PDA

View Full Version : glColor


me_here_me
02-21-2008, 03:10 AM
Hi
I want to draw two discs in red color using openGL. I am able to draw the discs but no matter what color I specify for the discs, one turns out to be blue and the other black.

I tried retrieving the color through "glGetFloatv(GL_CURRENT_COLOR, gf);" and the color is correctly specified, but still the drawing is always in blue and black.

below is the code snippet. My application is based in clockwise drawing


OpenGL setup

glEnable( GL_LIGHTING );
glEnable( GL_LIGHT0 );

glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glFrontFace(GL_CW);

glEnable( GL_DEPTH );
glShadeModel( GL_SMOOTH );


code to draw discs

GLUquadricObj* quadraticObject = gluNewQuadric( );
glTranslatef(0.0,0.0,-250.0);
glColor4f(1.0,0.0,0.0,1.0);

GLfloat gf[4];
glGetFloatv(GL_CURRENT_COLOR, gf);

gluDisk(quadraticObject, 0.0, 50.0, 100, 100);
glTranslatef(0.0,0.0,500.0);
gluDisk(quadraticObject, 0.0, 50.0, 100, 100);



first disc blue and the second one is black :(

any clues

regards

me_here_me
02-21-2008, 05:01 AM
it works now

I have to disable light for the colors to show up. But I do not understand why I have to disable lights?

regards

Reedbeta
02-21-2008, 08:26 AM
By default in OpenGL, the color of things when lighting is turned on is not controlled by glColor, but rather by glMaterial. You can use glMaterial to set the emissivity, the ambient, diffuse, and specular reflectivities, and the specular highlight 'tightness' (specular power) as well. However if you glEnable(GL_COLOR_MATERIAL), you can then use glColor to set the ambient and diffuse reflectivities, which is often convenient.

mmakrzem
02-24-2008, 06:31 AM
I've read in the OpenGL doc that it is better (faster) to use glColor rather than glMaterial even when both function calls are supposed to do the samething thing. Does anyone know why that is?

kusma
02-24-2008, 10:38 AM
I've read in the OpenGL doc
What do you mean by "the OpenGL doc"?

mmakrzem
02-24-2008, 10:40 AM
msdn: http://msdn2.microsoft.com/en-us/library/ms537236(VS.85).aspx

my bad, it talks about glColorMaterial vs glMaterial

Reedbeta
02-24-2008, 05:05 PM
And it only says glColorMaterial is "preferred" over glMaterial. That could mean anything; it doesn't imply that it's faster. It probably just means it's more convenient for the programmer.