added testData to terrain for debugging
This commit is contained in:
parent
834d3758d6
commit
5cee3e7dd2
@ -4,8 +4,8 @@ uniform mat4 modelMatrix;
|
||||
uniform mat4 viewMatrix;
|
||||
uniform mat4 projectionMatrix;
|
||||
|
||||
in vec3 aNormal;
|
||||
in vec3 aPosition;
|
||||
in vec3 aNormal;
|
||||
in vec2 aTexCoord;
|
||||
|
||||
out vec3 vNormal;
|
||||
|
2
level.cc
2
level.cc
@ -36,7 +36,7 @@ void Level::load(ACGL::OpenGL::SharedShaderProgram shader) {
|
||||
this->terrain.load();
|
||||
Model terrainModel = this->terrain.getModel();
|
||||
// load a texture:
|
||||
Material terrainMaterial = Material("clownfishBunny.png", 0.1f, 0.7f, 0.3f, 1.0f);
|
||||
Material terrainMaterial = Material("clownfishBunny.png", 0.7f, 0.7f, 0.3f, 1.0f);
|
||||
//Create object
|
||||
Object terrainObject = Object(terrainModel, terrainMaterial,
|
||||
glm::vec3(-0.5f*(float)this->terrain.getHeightmapHeight(), 0.0f, -0.5f*(float)this->terrain.getHeightmapWidth()),
|
||||
|
47
terrain.cc
47
terrain.cc
@ -14,7 +14,7 @@ Terrain::~Terrain() {
|
||||
void Terrain::load() {
|
||||
this->filePath = "../Levels/LevelTest/terrain"; //TODO remove this, its only for testing
|
||||
|
||||
std::ifstream terrain_png(this->filePath + "/heightmap.png");
|
||||
std::ifstream terrain_png(this->filePath + "/heightmap2.png");
|
||||
unsigned int rowNum, columnNum, heightmapValue;
|
||||
|
||||
terrain_png.seekg(16); //skip part of the header
|
||||
@ -42,27 +42,27 @@ void Terrain::load() {
|
||||
void Terrain::makeTriangleMesh(){
|
||||
|
||||
ACGL::OpenGL::SharedArrayBuffer ab = std::make_shared<ACGL::OpenGL::ArrayBuffer>();
|
||||
ab->defineAttribute("aPosition", GL_FLOAT, 3); //TODO: ArrayBuffer for the texture coordinates
|
||||
ab->defineAttribute("aNormal", GL_FLOAT, 3);
|
||||
ab->defineAttribute("aTexCoord", GL_FLOAT, 2);
|
||||
ab->defineAttributeWithOffset("aPosition", GL_FLOAT, 3, 0);
|
||||
ab->defineAttributeWithOffset("aNormal", GL_FLOAT, 3, 3);
|
||||
ab->defineAttributeWithOffset("aTexCoord", GL_FLOAT, 2, 6);
|
||||
|
||||
unsigned int rowNum=0, columnNum=0, dataCount=0, abNumFloats=8; //initializing:
|
||||
unsigned int rowNum=0, columnNum=0, dataCount=0, floatsPerVertex=8; //initializing:
|
||||
bool movingRight = true, isUp = true;
|
||||
int numVertices = (this->heightmapHeight - 1) * (this->heightmapWidth * 2 + 1) + 1;
|
||||
float* abData = new float[numVertices * abNumFloats];
|
||||
float* abData = new float[numVertices * floatsPerVertex];
|
||||
|
||||
while(rowNum < this->heightmapHeight){ //traversing the Triangle Strip!
|
||||
set_abData(abData, dataCount, rowNum, columnNum);
|
||||
dataCount += abNumFloats;
|
||||
dataCount += floatsPerVertex;
|
||||
if (isUp){
|
||||
rowNum = rowNum + 1;
|
||||
isUp = false;
|
||||
}else if (movingRight){
|
||||
if (columnNum == this->heightmapWidth - 1){
|
||||
set_abData(abData, dataCount, rowNum, columnNum);
|
||||
dataCount += abNumFloats;
|
||||
dataCount += floatsPerVertex;
|
||||
set_abData(abData, dataCount, rowNum, columnNum);
|
||||
dataCount += abNumFloats;
|
||||
dataCount += floatsPerVertex;
|
||||
movingRight = false;
|
||||
rowNum = rowNum + 1;
|
||||
} else{
|
||||
@ -73,9 +73,9 @@ void Terrain::makeTriangleMesh(){
|
||||
}else{
|
||||
if (columnNum == 0){
|
||||
set_abData(abData, dataCount, rowNum, columnNum);
|
||||
dataCount += abNumFloats;
|
||||
dataCount += floatsPerVertex;
|
||||
set_abData(abData, dataCount, rowNum, columnNum);
|
||||
dataCount += abNumFloats;
|
||||
dataCount += floatsPerVertex;
|
||||
movingRight = true;
|
||||
rowNum = rowNum + 1;
|
||||
}else{
|
||||
@ -86,7 +86,24 @@ void Terrain::makeTriangleMesh(){
|
||||
}
|
||||
}
|
||||
|
||||
ab->setDataElements(numVertices, abData);
|
||||
//ab->setDataElements(numVertices, abData);
|
||||
float* testData = new float[32];
|
||||
testData[0]=0.0f;testData[1]=0.0f;testData[2]=0.0f;
|
||||
testData[3]=0.0f;testData[4]=1.0f;testData[5]=0.0f;
|
||||
testData[6]=0.0f;testData[7]=0.0f;
|
||||
|
||||
testData[8]=1.0f;testData[9]=0.2f;testData[10]=0.0f;
|
||||
testData[11]=0.0f;testData[12]=1.0f;testData[13]=0.0f;
|
||||
testData[14]=1024.0f;testData[15]=.0f;
|
||||
|
||||
testData[16]=0.0f;testData[17]=0.2f;testData[18]=1.0f;
|
||||
testData[19]=0.0f;testData[20]=1.0f;testData[21]=0.0f;
|
||||
testData[22]=0.0f;testData[23]=1024.0f;
|
||||
|
||||
testData[24]=1.0f;testData[25]=0.0f;testData[26]=1.0f;
|
||||
testData[27]=0.0f;testData[28]=1.0f;testData[29]=0.0f;
|
||||
testData[30]=1024.0f;testData[31]=1024.0f;
|
||||
ab->setDataElements(numVertices, testData);
|
||||
this->triangleMesh = std::make_shared<ACGL::OpenGL::VertexArrayObject>();
|
||||
this->triangleMesh->bind();
|
||||
this->triangleMesh->setMode(GL_TRIANGLE_STRIP);
|
||||
@ -139,11 +156,13 @@ float** Terrain::getHeightmap(){
|
||||
}
|
||||
|
||||
unsigned int Terrain::getHeightmapHeight(){
|
||||
return this->heightmapHeight;
|
||||
//return this->heightmapHeight;
|
||||
return 2;
|
||||
}
|
||||
|
||||
unsigned int Terrain::getHeightmapWidth(){
|
||||
return this->heightmapWidth;
|
||||
//return this->heightmapWidth;
|
||||
return 2;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user