PDA

View Full Version : Heightmap flattens if model is rendered



cappah78
05-02-2015, 03:15 AM
I have a 3D OpenGL project that renders a simple heightmap from a texture. When the program runs, the heightmap displays a
mountainous range as expected. The problem comes when I try to render a model along with it. When both heightmap and model
are rendered, the model displays fine, but the heightmap flickers once with the correct calculations, then flattens itself.

In my Game.cpp:


void Game::init()
{
window = createWindow("Project", WIDTH, HEIGHT);

shader = new ModelShader();
model = new Model(shader, "models/model.obj");
model->setModelPlacement(glm::vec3(0.0f, 0.0f, 3.0f), 0.2f, 45.0f);

terrainShader = ModelShader();
terrain = new Terrain(terrainShader, "heightmaps/heightmap01.png");

projectionMatrix = glm::perspective(45.0f, (float)WIDTH / (float)HEIGHT, 0.1f, 1000.0f);
viewMatrix = glm::lookAt(
glm::vec3(0.f, 0.f, -5.f), // Camera position
glm::vec3(0, 0, 0), // Camera target
glm::vec3(0, 1, 0)); // Camera orientation (up)

model->init(projectionMatrix, viewMatrix);
terrain->init(projectionMatrix, viewMatrix);
}

void Game::render()
{
model->draw();
terrain->draw();
}

Within both init() functions for the model and terrain, I'm using the shader program, setting the values then disabling the program.
Same goes for both draw() functions. But for some reason, when I render the model with the heightmap, the heightmap
calculation stops and renders a flat plane.

Yandersen
05-02-2015, 10:35 AM
There is not enough info provided to figure out the problem. If the elevation of terrain height values is controlled by some uniform scaling factor, that uniform may have changed somehow to a zero. Check which program object is bound while the uniform at that location is assigned a new value.