Sign in to follow this  
hatfarm

Why does this ordering matter? uniformMatrix4fv update issue?

Recommended Posts

hatfarm    224

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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this