I have created a simple shader for drawing my scene in OpenGL. When another shader was introduced, a problem appeared.
I use the first shader and draw few objects in the scene. Then I use the second shader and draw something else. Every draw call has it's glUseProgram()
before the drawing starts. Problem is that all my objects drawn with the first shader disappear, but if I call glUseProgram(firstShader)
right after the second drawing is finished everything is fine. I can't figure out why this is happening even if I'm calling glUseProgram(firstShader)
right before the drawing starts.
Is there something I'm missing about OpenGL drawing process? Is it possible that OpenGL actually draws everything using the second shader?
Most simplified version of my program looks something like this:
glClear(...);
glUseProgam(simpleStandardShader); // just transforming vertices and doing some directional lighting and texturing
foreach (GameObject)
glDrawArray(...); // draw all 3D objects
glUseProgram(spriteShader); // transforming quads in screen space and texturing
foreach(Sprite)
glDrawArray(...); // draw all quads
glSwapBuffers(); // i hope i wrote it right, don't remember exact name
glUseShader
your custom function, or did you actually meanglUseProgram
? – glampert Jul 8 '14 at 1:59