Why does this ordering matter? uniformMatrix4fv update issue?

Started by
-1 comments, last by hatfarm 10 years, 12 months ago

So, I've got a couple of scenes I'm drawing (a custom mouse cursor and my map). I've got a separate camera object that can be moved around to change what part of the map I'm looking at, I want to keep the camera separate because once I start putting objects on my map, I want them to use the same camera but a (slightly) different GLSL program. Anyway, the way I'm doing it now is the camera is linked to the scene via a function that sends the MVP matrix from the camera to the scene. Here's that function:


void MapScene::updateMVP(const glm::mat4 &mvp){
    m_sProg.useProgram();
    glBindVertexArray(m_vao);
    m_sProg.getUniformLocation("mvp", m_worldUniform);
    glUniformMatrix4fv(m_worldUniform, 1, GL_FALSE, glm::value_ptr(mvp));
    if(GL_NO_ERROR != glGetError())
        std::cerr << "Could not write MVP!\n";
}

This code works, for the most part. I initialize my scenes and my camera, but if I don't do it in a specific order, I don't get the right results. I initially didn't have the "useProgram();" call at the beginning of the updateMVP() function, but now that I do, I don't know why this won't work. Here's what I write to get the desired results:


m_mapScene->initScene();
initCamera();
m_mouseScene->initScene();

If I put initCamera() at the bottom of this, I get just a tiny amount of the map to show (about the size of the mouse). initCamera() just sets projection, model and view matrices as you normally would and then sends an updateMVP() call to my mapScene. The crazy thing is, I call the updateMVP function during the render loop too, before I render any of my scenes. Any ideas? I can only think it's because of the 2d scene for the mouse, or just that it's a different program, but I don't understand why that would be a problem since the mapScene's shader program is set to be used before I try to do anything (I also don't get any of those cerr messages from a bad MVP write).

Any help would be appreciated.

This topic is closed to new replies.

Advertisement