PDA

View Full Version : Problems with setting current color



daviem01
09-12-2001, 11:09 AM
Hello all,

I'm getting some strange color errors in my program.

The purpose of this program is to draw rectangles in different colors. Each rectangle is defined in a struct that contains the corner coordinates along with an int "key" (from 0 to about 7) that indicates which color the rectangle is to be drawn in. Each color is defined with a static const GLdouble[3] and is given an appropriate name such as "lavender".

At draw time, the program loops through the list of structs, retrieves the key, sets the current drawing color (with a switch statement that calls glColor3dv with the appropriate color array for the key), and draws the rectangle.

The correct color is being passed to glColor3dv; I have confirmed this with the debugger. The problem is that what is actually DRAWN is incorrect. For example, if rectangles with key 0 (lavender) and 1 (yellow) are both in the array to be drawn, only lavender shows up on screen. If only rectangles with key 0 are drawn, they all show up in grey (which isn't even defined as a color!) It's as if the current color is somehow getting reset to something else.

The flow is as follows (this is part of a larger program):

//Disable GL_DEPTH_TEST
//Enable GL_LINE_STIPPLE and set its value
glPushMatrix();

//Loop through the array of structs
{
//Set color (as described above)
glBegin(GL_LINE_LOOP);
//Rectangle is drawn here
glEnd();
}
glPopMatrix();
//Reenable everything necessary

GL_LIGHTING is on throughout this process, but turning it off didn't make a difference.

Any suggestions would be greatly appreciated!

zed
09-12-2001, 02:45 PM
colour doesnt work when lighting is turned on unless u use colourmaterials.
do u have texturing turned off, other than that i cant see what could be wrong

glColor4f(red)
draw something // this will be red
glColor4f(green)
draw something // this should be green, if its staying red then???

daviem01
09-12-2001, 03:14 PM
Thanks, zed. I'll double check, but I think GL_TEXTURE_2D is turned off.