implemented loading of the heightmap from a png to unsigned int**

This commit is contained in:
Steffen Fündgens 2014-11-03 17:19:22 +01:00
parent 911c8ebfcc
commit 925eb62831
2 changed files with 34 additions and 1 deletions

View File

@ -1,7 +1,34 @@
#include "terrain.hh"
Terrain::Terrain() {
Terrain::Terrain(){
}
Terrain::~Terrain() {
}
void Terrain::load() {
std::ifstream terrain_png(this->filePath);
unsigned int width, height, rowNum, columnNum;
terrain_png.seekg(16);
terrain_png.read((char *)&width, 4);
terrain_png.read((char *)&height, 4);
width = ntohl(width);
height = ntohl(height);
heightmap = new unsigned int*[height];
for(rowNum=0; rowNum<height; rowNum++){
heightmap[columnNum] = new unsigned int[width];
for(columnNum=0; columnNum<width; columnNum++){
terrain_png.read((char *)&heightmap[columnNum][rowNum], 1);
}
}
}
void Terrain::render() {
}

View File

@ -3,6 +3,11 @@
#include <string>
#include "texture.hh"
#include <fstream>
#include <iostream>
#include "png.h"
//#include <winsock.h> //on windows
#include <netinet/in.h> //on Unix
class Terrain {
public:
@ -14,6 +19,7 @@ class Terrain {
float friction;
Texture texture;
std::string filePath;
unsigned int** heightmap;
};
#endif