PDA

View Full Version : Rendering function not rendering terrain



Arko4576
06-14-2014, 04:57 PM
I have been following this tutorial on multi- layered terrain (http://www.mbsoftworks.sk/index.php?page=tutorials&series=1&tutorial=24)but have not been able to get it to render. From my observations I believe the terrain is rendering due to my app having a fps drop when I set it to render. I believe the problems is with the textures, mainly the shaders and how I bind them.

The fragment and vertex shaders are in his tutorial if you need to see them.

Below is the rendering function that I am currently trying to use:


shaders->setUniform("vColor", glm::vec4(1, 1, 1, 1));
shaders->setUniform("HeightmapScaleMatrix", glm::scale(glm::mat4(1.0), glm::vec3(terrain.vRenderScale)));


glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, fungus->object());

glBindSampler(0, fungus->sampler());
shaders->setUniform("gSampler[0]", 0);

glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, sandGrass->object());

glBindSampler(1, sandGrass->sampler());
shaders->setUniform("gSampler[1]", 1);
glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, rock->object());

glBindSampler(2, rock->sampler());
shaders->setUniform("gSampler[2]", 2);

glActiveTexture(GL_TEXTURE3);
glBindTexture(GL_TEXTURE_2D, sand->object());

glBindSampler(3, sand->sampler());
shaders->setUniform("gSampler[3]", 3);

glActiveTexture(GL_TEXTURE4);
glBindTexture(GL_TEXTURE_2D, path->object());

glBindSampler(4, path->sampler());
shaders->setUniform("gSampler[4]", 4);

glBindVertexArray(asset->vao);
glEnable(GL_PRIMITIVE_RESTART);
glPrimitiveRestartIndex(terrain.width*terrain.heig ht);

int iNumIndices = (terrain.width - 1)*terrain.height * 2 + terrain.width - 1;
glDrawElements(GL_TRIANGLE_STRIP, iNumIndices, GL_UNSIGNED_INT, 0);

glBindVertexArray(0);
glBindSampler(0, 0);
glBindTexture(GL_TEXTURE_2D, 0);


shaders->stopUsing();