PDA

View Full Version : glColor()...



se7en
12-31-2009, 11:26 PM
I'm making a game that draws in 3D, and for the menu system does 2D via ortho mode. For now I'm drawing lines around selected menu options to show which one is currently selected. When I do it, I do something like..

glColor3f(1.0f, 0.0f, 0.0f);
glBegin(GL_LINES);
glVertex2f()
..
..
glEnd();

The first problem is the color doesn't come out right. If I use the color above, instead of being bright red it come out dark. Same with every other color - white shows up gray, etc. I'm not sure why. The project itself is way too big to post, but I can post whatever parts you want. I'm not sure what else to add because I don't know where this would happen.

And one other issue is that after I call the glColor function, everything is red. It's like a filter was put over the whole screen. Right now I just call glColor4f(1, 1, 1, 0) after I'm done drawing the lines to prevent that from happening, but when I go into 3D it ends up almost completely white. Is there a way to get rid of the color after calling glColor3f(1, 0, 0) ?

I can take some screenshots if need as well. I am not using lighting.

overlay
01-01-2010, 04:32 AM
Make sure lighting is disabled with:

glDisable(GL_LIGHTING);

remdul
01-01-2010, 01:33 PM
As overlay said, check if lighting is enabled, you probably want to disable before drawing 2d elements, and enable it before drawing a 3d scene.

Don't forget; OpenGL is a state machine. glColor sets the state of the current color used by the rasterizer. Most elements you draw afterwards will use that color (under the right conditions, see link below).

You can do this for example:

// draw line that fades from red to green
glBegin(GL_LINES);
glColor3f(1,0,0);
glVertex2f(0,0);
glColor3f(0,1,0);
glVertex2f(1,1);
glEnd();So yes, calling glColor3f(1, 1, 1) is a completely valid solution.

There's a few things that can affect the final rasterized pixel colors though (such as material parameters, lighting parameters, vertex normals, texture environment parameters). I recommend reading the following: http://www.sjbaker.org/steve/omniv/opengl_lighting.html

se7en
01-05-2010, 08:22 PM
<div class="ubbcode-block"><div class="ubbcode-header">Click to reveal.. <input type="button" class="form-button" value="Show me!" onclick="toggle_spoiler(this, 'Yikes, my eyes!', 'Show me!')" />]<div style="display: none;">I think the problem is because I'm drawing the lines on top of textures? I've disabled lighting, and that's the only other thing I've noticed. From the site posted above:


If it's disabled then all polygons, lines and points will be coloured according to the setting of the various forms of the glColor command. Those colours will be carried forward without any change other than is imparted by texture or fog if those are also enabled.

I disabled fog and nothing changes.[/QUOTE]</div>

Edit - I got it working. Just did..

glDisable(GL_TEXTURE_2D);

// draw primitives

glEnable(GL_TEXTURE_2D);