stratgame

diff level/src/level.cc @ 3:8d95187cb3ee

foo
author John Tsiombikas <nuclear@member.fsf.org>
date Wed, 23 May 2012 17:10:46 +0300
parents 369b51c9e4a8
children 2e38715de41b
line diff
     1.1 --- a/level/src/level.cc	Wed May 23 07:25:43 2012 +0300
     1.2 +++ b/level/src/level.cc	Wed May 23 17:10:46 2012 +0300
     1.3 @@ -2,6 +2,7 @@
     1.4  #include <string.h>
     1.5  #include "level.h"
     1.6  #include "datapath.h"
     1.7 +#include "opengl.h"
     1.8  
     1.9  using namespace tinyxml2;
    1.10  
    1.11 @@ -53,6 +54,32 @@
    1.12  	return true;
    1.13  }
    1.14  
    1.15 +void Level::draw() const
    1.16 +{
    1.17 +	auto iter = levelmaps.find("height");
    1.18 +	if(iter == levelmaps.end()) {
    1.19 +		return;
    1.20 +	}
    1.21 +
    1.22 +	img_pixmap *hmap = (img_pixmap*)iter->second.get_pixmap();
    1.23 +
    1.24 +	glBegin(GL_POINTS);
    1.25 +	for(int i=0; i<hmap->height; i++) {
    1.26 +		for(int j=0; j<hmap->width; j++) {
    1.27 +			int height;
    1.28 +			img_getpixel1i(hmap, j, i, &height);
    1.29 +
    1.30 +			float x = (float)j / (float)hmap->width - 0.5;
    1.31 +			float y = height / 255.0;
    1.32 +			float z = (float)i / (float)hmap->height - 0.5;
    1.33 +
    1.34 +			glColor3f(y, 0.0, 1.0 - y);
    1.35 +			glVertex3f(x, y, z);
    1.36 +		}
    1.37 +	}
    1.38 +	glEnd();
    1.39 +}
    1.40 +
    1.41  
    1.42  LevelMap::LevelMap()
    1.43  {