Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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
share|improve this question
4  
Can you show us your code? –  concept3d Jul 8 '14 at 0:41
2  
Is this glUseShader your custom function, or did you actually mean glUseProgram? –  glampert Jul 8 '14 at 1:59
    
@concept3d It's very object oriented so it will be hard to actually upload relevant parts without uploading bunch of code. –  instancedName Jul 8 '14 at 12:51
1  
Are you setting any uniforms before calling glUseProgram? –  GuyRT Jul 8 '14 at 14:02
1  
I asked because you say "...if I call glUseProgram(firstShader) right after the second drawing is finished everything is fine". That lead me to think that (without that call) on the subsequent frame uniforms are being set on the second program before the first one is selected again. –  GuyRT Jul 8 '14 at 14:56

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.