Drawing is done by VBOs only (my hardware doesn't support VAOs AFAIK), in the usual way as far as I can see.
Every frame, after drawing:int projectionMatrixLocation = glGetUniformLocation(programShaderID, "projectionMatrix"); // Get the location of our projection matrix in the shader int viewMatrixLocation = glGetUniformLocation(programShaderID, "viewMatrix"); // Get the location of our view matrix in the shader int modelMatrixLocation = glGetUniformLocation(programShaderID, "modelMatrix"); // Get the location of our model matrix in the shader glUniformMatrix4fv(projectionMatrixLocation, 1, GL_FALSE, &projectionMatrix); // Send our projection matrix to the shader glUniformMatrix4fv(viewMatrixLocation, 1, GL_FALSE, &viewMatrix); // Send our view matrix to the shader glUniformMatrix4fv(modelMatrixLocation, 1, GL_FALSE, &modelMatrix); // Send our model matrix to the shader
Here is one problem,
I guess you first do something like "glUseProgram(programShaderId)", and at the end of your drawing "glUseProgram(0)"? Or do you just use one shader? Then setting it once in the initialisation is ok.
When you set the uniforms after drawing, the shaders dont have the matrices when they draw/process everything.or if the shader is active all the time then you draw everything with the matrices from the last draw step.
And you dont need to use "glGetUniformLocation()" every frame because the locations are constant for one shader, just get the locations once after "loadShaders ("vertexShader.txt","fragmentShader.txt"); "
The right sequence would be:
- Load shaders
- set uniforms
- draw your vbo
The other stuff you are doing should be right, so this sequence only considers the uniform stuff.
A good resource for me is http://www.opengl-tutorial.org/
Feel free to ask if it is still not working or when there are other questions