PDA

View Full Version : 'unsetting' the color



exar
07-10-2004, 09:49 PM
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.

mikael_aronsson
07-10-2004, 10:33 PM
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.

exar
07-10-2004, 11:33 PM
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?

mikael_aronsson
07-11-2004, 12:17 AM
Are you using lighting or not when you render the cube ? ( glEnable( GL_LIGHTING); glEnable( GL_LIGHT0); ).

Mikael

ZbuffeR
07-11-2004, 11:05 AM
Try to put the color to full white instead.

07-11-2004, 02:40 PM
Try this:


glPushAttrib(GL_CURRENT_BIT);
glColor3f(0.0f, 1.0f, 0.0f);
DrawMyFancyLines();
glPopAttrib(GL_CURRENT_BIT);
DrawMyFancyCube();If that still dosent work check out the documentation about glPushAttrib()/glPopAttrib() to see what states you can also save/restore.

exar
07-14-2004, 07:59 AM
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?

jcabeleira
07-14-2004, 01:20 PM
disable the lighting with glDisable(GL_LIGHTING)before you draw the lines

07-18-2004, 05:53 PM
Exar

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:

glColor3f(1,1,1)

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.

Wisdrum

07-18-2004, 05:57 PM
Exar

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

Sorry

Wisdrum

exar
07-22-2004, 05:51 PM
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.