scaled heightmap height to [0,1] tried to give the heightmap a clor

This commit is contained in:
Steffen Fündgens 2014-11-11 13:27:11 +01:00
parent c68119d7d0
commit 9cb7278eb3

View File

@ -14,7 +14,7 @@ Terrain::~Terrain() {
void Terrain::load() { void Terrain::load() {
this->filePath = "../Levels/LevelTest/terrain"; //TODO remove this, its only for testing this->filePath = "../Levels/LevelTest/terrain"; //TODO remove this, its only for testing
std::ifstream terrain_png(this->filePath + "/heightmap.png"); //TODO: filepath organization std::ifstream terrain_png(this->filePath + "/heightmap.png");
unsigned int rowNum, columnNum, heightmapValue; unsigned int rowNum, columnNum, heightmapValue;
terrain_png.seekg(16); //skip part of the header terrain_png.seekg(16); //skip part of the header
@ -25,9 +25,6 @@ void Terrain::load() {
terrain_png.read(temp, 4); //read height terrain_png.read(temp, 4); //read height
this->heightmapHeight = (temp[3]<<0) | (temp[2]<<8) | (temp[1]<<16) | (temp[0]<<24); //convert from network to host byte order this->heightmapHeight = (temp[3]<<0) | (temp[2]<<8) | (temp[1]<<16) | (temp[0]<<24); //convert from network to host byte order
printf("Width: %d ", (int)this->heightmapWidth);
printf("Height: %d ", (int)this->heightmapHeight);
heightmap = new float*[this->heightmapHeight]; //initialize the heightmap heightmap = new float*[this->heightmapHeight]; //initialize the heightmap
for(rowNum = 0; rowNum < this->heightmapHeight; rowNum++){ //read in the heightmap for(rowNum = 0; rowNum < this->heightmapHeight; rowNum++){ //read in the heightmap
heightmap[rowNum] = new float[this->heightmapWidth]; heightmap[rowNum] = new float[this->heightmapWidth];
@ -50,7 +47,6 @@ void Terrain::makeTriangleMesh(){
unsigned int rowNum=0, columnNum=0, dataCount=0; //initializing: unsigned int rowNum=0, columnNum=0, dataCount=0; //initializing:
bool movingRight = true, isUp = true; bool movingRight = true, isUp = true;
int numVertices = (this->heightmapHeight - 1) * (this->heightmapWidth * 2 + 1) + 1; int numVertices = (this->heightmapHeight - 1) * (this->heightmapWidth * 2 + 1) + 1;
printf("NumberofVertices: %d ", numVertices);
float* abData = new float[numVertices * 3]; float* abData = new float[numVertices * 3];
while(rowNum < this->heightmapHeight){ //traversing the Triangle Strip! while(rowNum < this->heightmapHeight){ //traversing the Triangle Strip!
@ -104,6 +100,21 @@ void Terrain::makeTriangleMesh(){
this->triangleMesh->setMode(GL_TRIANGLE_STRIP); this->triangleMesh->setMode(GL_TRIANGLE_STRIP);
this->triangleMesh->attachAllAttributes(ab); this->triangleMesh->attachAllAttributes(ab);
//TODO unbind? //TODO unbind?
//TODO remove this TestCode (that doesnt even work yet...):
/* ACGL::OpenGL::SharedArrayBuffer tex = std::make_shared<ACGL::OpenGL::ArrayBuffer>();
tex->defineAttribute("color", GL_FLOAT, 3);
float* texData = new float[numVertices*3];
for (int i=0; i<numVertices*3; i++){
texData[i] = 1.0;
}
tex->setDataElements(numVertices, texData);
this->triangleMesh->attachAllAttributes(tex);
*/
} }
void Terrain::render() { void Terrain::render() {