'unsetting' the color

I have a program that currently just displays a textured cube. To get an idea of what various translations did in 3d space, I started drawing a grid behind this cube, using a couple of nested loops and drawing using GL_LINES. Before the grid is drawn, I also called glColor3f(0.0f, 1.0f, 0.0f); to make the grid appear green.

Trouble is, everything after this also comes out green (including the cube, which previously was just the color of the texture). I can’t work out how to ‘unset’ the color so that things drawn after the grid aren’t affected. Any help much appreciated.

Hi !

You can’t “unset” any color, what you can do is to set it to black glColor3f( 0.0f, 0.0f, 0.0f); for example when you are done with the green stuff.

Right, that’s what occured to me first as well, but doing that makes everything after it come out black (eg: the textured cube was now just plain black - no sign of the texture anymore). Tried the same with white and got the same results.

Any ideas?

Are you using lighting or not when you render the cube ? ( glEnable( GL_LIGHTING); glEnable( GL_LIGHT0); ).


Try to put the color to full white instead.

Try this:

glColor3f(0.0f, 1.0f, 0.0f);

If that still dosent work check out the documentation about glPushAttrib()/glPopAttrib() to see what states you can also save/restore.

Thanks for all the suggestions.

Are you using lighting or not when you render the cube ? ( glEnable( GL_LIGHTING); glEnable( GL_LIGHT0); ).
I wasn’t at first. I’ve just tried it with both those things enabled, and now the cube looks textured again, which is great. The grid lines appear black though, and not green (I don’t know if this is because they’re strictly 2-dimensional, and hence the light doesn’t show up on them or something?)

Is it possible to do a combination of textured objects and coloured lines/other shapes without lighting enabled?

disable the lighting with glDisable(GL_LIGHTING)before you draw the lines


Before you draw the textured object:

 glEnable ($$GL_TEXTURE_2D)   	       
glBindTexture ($$GL_TEXTURE_2D, yourTexture[])

After you draw the textured object:

glDisable ($$GL_TEXTURE_2D)

also, after you draw the primitive reset the color to bright white:


The colors of one is affecting the other and vica versa.

I think there is a GL Material call or something similar to tint the textured objects with whatever color you wish also, but, i can´t remember exactly.



Also, take out those double $$ dollar signs. They´re not for C++.



Ahhh, thanks Wisdrum. It hadn’t occured to me to do glDisable(GLTEXTURE2D) at any point. It still seems slightly odd that setting the color back to full white is neccessary, as if it was some kind of ‘magic’ value.