Drawing a vbo without using an enabled shader ?


1- I would like to know how it works…

I am drawing a 3D model in a perspective view with a background. (no problem)

To do that I first draw the background :

disable my shader

// draw the background : a simple rectangle with colors in a vbo
glDrawArrays(GL_QUADS,0,8) GLSL=6 

enable my shader

Then I draw the 3D scene :
I have opengl 1.1 code with glvertex(…) functions.
In my shader version 110 (vertex + fragment) :

  • I retrieve the vertex with the built-in variable gl_Vertex.
  • I do not use attribute variables. I only use uniform variables.
  • I use one uniform variable “myObjectColor” to set the color : gl_FragColor = myObjectColor;

Question :
Must I disable my shader before drawing my background ?
In other words : does my shader “see” my vbo ? Is it doing something ? Are the built-in variable gl_Vertex and gl_Color well defined ?

If the shader does something I think that I have to disable it because my uniform variable to set the color is not set during the background drawing.

2- This second question is only valid if the shader can be keeped enabled during the background drawing :
I tested without disabling the shader. It seems to work well except for the first frame : the background is black. After the first refresh it is ok.
I tried to see what is missing with glintercept but i haven’t seen anything… But something is wrong…
What can cause that ?

Thanks for your advices.

Your shader will be used for all draw calls as long as it’s enabled. So you will need a different (very simple) shader to draw your background, or disable the shader completely if you’re ok with using the fixed pipeline.

You confirm what I thought.
So I searched why my views are not coherent with that.
I found that my shader is disabled after the first frame, which explains the background is well drawn after the first frame.

Now it is coherent and it helped me to understand other things.
Thanks for your answer.