View Full Version : Rendering 2D over 3D

Alexandru Matei
02-13-2010, 03:02 PM

I'm having an issue rendering 2D on top of 3D: the vertex colour I'm setting for 2D content is getting used for 3D content as well.

What I'm doing, per frame:
- setup 3D
- draw a mesh with no vertex colours using glDrawArrays
- setup 2D
- draw a quad with vertex colour

The 3D content is being rendered correctly as far as the geometry is concerned, but all vertices use the colour I'm setting in 2D (i.e. if I draw a blue filled rectangle in 2D, the 3D teapot is also blue). 2D content appears normal.

When rendering the 3D mesh, I'm disabling colour arrays:

Am I doing something wrong?

Thanks a lot,

Alfonse Reinheart
02-13-2010, 03:40 PM
When you did the 2D rendering, you must have set some state (perhaps texture environment state) that causes the color to be used for something. All glDisbleCliientState will do is turn off the color array. The state will still be set to use colors to compute the final pixel output.

You must find whatever state you set and undo this once you're done with 2D rendering.

Alexandru Matei
02-13-2010, 04:48 PM

Thank you for your answer, I believe I found out what was happening. I wasn't setting glTexEnvi anywhere in the code and apparently it's defaulted to GL_TEXTURE_ENV_MODE = GL_MODULATE.

For the 3D part, I wasn't setting any vertex color, so I'm guessing the last color set in 2D was also being used for blending with the texture.

Finally, I set GL_TEXTURE_ENV_MODE to GL_REPLACE at the end of the 2D part. When I introduce vtx color for the 3D part I'll set it back to GL_MODULATE.

Is my understanding correct?

Thank you,

02-14-2010, 10:34 PM
That's correct. glTexEnv is for all textures you use, so will need to be set and reset between states, which is different from glTexParam* that is for a specific textures.

Alexandru Matei
02-15-2010, 02:58 AM
Cool, thanks a lot :)