PDA

View Full Version : why can't I get green?



ghollins
04-03-2001, 10:49 PM
I have the following code as part of my program. It seems to me that it should be drawing in green, not red, but it draws in red. To save space I have only included my display function.
Here it is:

void displayFunc(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);


glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

gluLookAt(0.0, 0.0, 19.0,
0.0, 0.0, 0.0,
0.0, 1.0, 0.);

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

glBegin(GL_QUADS);

glNormal3f( 0.0f, 0.0f, 1.0f);

glVertex3f( -3.0f, 0.0f, 0.5f);
glVertex3f( -3.0f, 1.0f, 0.5f);
glVertex3f( -2.0f, 1.0f, 0.5f);
glVertex3f( -2.0f, 0.0f, 0.5f);

glNormal3f( 0.0f, 0.0f, 1.0f);
glVertex3f( -2.0f, 1.0f, 0.5f);
glVertex3f( -2.0f, 0.0f, 0.5f);
glVertex3f( -1.0f, 0.0f, 0.5f);
glVertex3f( -1.0f, 1.0f, 0.5f);
glEnd();

glutSwapBuffers();

glutPostRedisplay();
}

Pip
04-03-2001, 11:20 PM
See the answers given to Sajjad (color differences) who has the same problem.
In your case, I would be agree with Zed.
(mode GRB)

BwB
04-04-2001, 04:39 AM
Ummm, color me stupid but... Shouldn't the glColor3f() call be inside of the glBegin()/glEnd() pair??? And whats this talk of grb??? I'll have to check out that thread.. but any OpenGL implementation that conformed to the OpenGL standard would properly convert values passed to glColor() to the device dependant format...

BwB
04-04-2001, 04:41 AM
Ok, I just checked that other thread and it has nothing to do with this issue. Sorry Pip http://www.opengl.org/discussion_boards/ubb/smile.gif That issue is dealing with textures being read in from a disk file and the file possibly storing the pixel data in the wrong format (well, not wrong, just different). This is obviously not the case here.

DFrey
04-04-2001, 04:59 AM
BwB: glColor can be called at any time, inside or outside a glBegin/glEnd pair.

Pip
04-04-2001, 05:01 AM
You have right about the talk BWB.

But no matter when glColor is called. (After or before a glBegin)
It is just important to call it before glVertex, in this example.
The color is a simple Status.
So,
There is something wrong, somewhere http://www.opengl.org/discussion_boards/ubb/frown.gif

Relic
04-04-2001, 08:00 AM
The display function alone is not sufficient to derive the OpenGL state from it.
If you have, for example, enabled lighting and disabled color material, then the glColor call is just obsolete.

Deiussum
04-04-2001, 09:15 AM
Are textures enabled/bound? That could cause it to be a different color as well.

zed
04-04-2001, 05:54 PM
i agree with relic + deiussum, in times of trouble disable everything eg lighting,textures,blending, alphatest etc.
then it should work. then enable them one at a time to find the culprit.