tried to call the load functions, no success this far
This commit is contained in:
parent
454a004c8f
commit
acf537e026
6
level.cc
6
level.cc
@ -2,7 +2,7 @@
|
||||
|
||||
Level::Level(std::string filePath){
|
||||
this->filePath = filePath;
|
||||
terrain = Terrain(filePath + "/terrain");
|
||||
this->terrain = Terrain(filePath + "/terrain");
|
||||
}
|
||||
|
||||
Level::Level() {
|
||||
@ -12,7 +12,7 @@ Level::~Level() {
|
||||
}
|
||||
|
||||
void Level::load(Shader shader) {
|
||||
terrain.load();
|
||||
//this->terrain.load();
|
||||
|
||||
|
||||
|
||||
@ -38,7 +38,7 @@ void Level::render() {
|
||||
for(int i = 0; i<objects.size(); i++) {
|
||||
objects[i].render();
|
||||
}
|
||||
terrain.render();
|
||||
//this->terrain.render();
|
||||
}
|
||||
|
||||
glm::vec3 Level::getAmbientLight() {
|
||||
|
26
terrain.cc
26
terrain.cc
@ -12,18 +12,25 @@ Terrain::~Terrain() {
|
||||
|
||||
|
||||
void Terrain::load() {
|
||||
std::ifstream terrain_png(this->filePath + "/heightmap.png"); //TODO: filepath organization
|
||||
std::ifstream terrain_png(this->filePath + "/heightmap.png"); //TODO: filepath organization
|
||||
unsigned int rowNum, columnNum, heightmapValue;
|
||||
|
||||
terrain_png.seekg(16); //skip part of the header
|
||||
char temp[2];
|
||||
terrain_png.read(temp, 4); //read width
|
||||
this->heightmapWidth = (temp[1]<<0) | (temp[0]<<8); //convert from network to host byte order
|
||||
terrain_png.read(temp, 4); //read height
|
||||
this->heightmapHeight = (temp[1]<<0) | (temp[0]<<8); //convert from network to host byte order
|
||||
terrain_png.seekg(16); //skip part of the header
|
||||
|
||||
heightmap = new float*[this->heightmapHeight]; //initialize the heightmap
|
||||
for(rowNum = 0; rowNum < this->heightmapHeight; rowNum++){ //read in the heightmap
|
||||
terrain_png.read((char *)&this->heightmapWidth, 4); //read width
|
||||
terrain_png.read((char *)&this->heightmapHeight, 4); //read height
|
||||
this->heightmapWidth = ntohl(this->heightmapWidth); //convert from network to host byte order
|
||||
this->heightmapHeight = ntohl(this->heightmapHeight);
|
||||
/* //alternate implementation that does NOT work at all
|
||||
char temp[2];4???
|
||||
terrain_png.read(temp, 4); //read width
|
||||
this->heightmapWidth = (temp[1]<<0) | (temp[0]<<8); //convert from network to host byte order
|
||||
terrain_png.read(temp, 4); //read height
|
||||
this->heightmapHeight = (temp[1]<<0) | (temp[0]<<8); //convert from network to host byte order
|
||||
*/
|
||||
|
||||
heightmap = new float*[this->heightmapHeight]; //initialize the heightmap
|
||||
for(rowNum = 0; rowNum < this->heightmapHeight; rowNum++){ //read in the heightmap
|
||||
heightmap[rowNum] = new float[this->heightmapWidth];
|
||||
for(columnNum = 0; columnNum < this->heightmapWidth; columnNum++){
|
||||
terrain_png.read((char *)&heightmapValue, 1);
|
||||
@ -81,6 +88,7 @@ void Terrain::makeTriangleMesh(){
|
||||
this->triangleMesh->bind();
|
||||
this->triangleMesh->setMode(GL_TRIANGLE_STRIP);
|
||||
this->triangleMesh->attachAllAttributes(arrayBuffer);
|
||||
//TODO unbind?
|
||||
}
|
||||
|
||||
void Terrain::render() {
|
||||
|
@ -4,6 +4,8 @@
|
||||
#include <string>
|
||||
#include "texture.hh"
|
||||
#include <fstream>
|
||||
#include <netinet/in.h>
|
||||
#include <ACGL/OpenGL/Objects/VertexArrayObject.hh>
|
||||
|
||||
class Terrain {
|
||||
public:
|
||||
|
Loading…
Reference in New Issue
Block a user