Jump to content


glColor


6 replies to this topic

#1 me_here_me

    New Member

  • Members
  • PipPip
  • 24 posts

Posted 21 February 2008 - 11: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

#2 me_here_me

    New Member

  • Members
  • PipPip
  • 24 posts

Posted 21 February 2008 - 01:01 PM

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

#3 Reedbeta

    DevMaster Staff

  • Administrators
  • 5305 posts
  • LocationBellevue, WA

Posted 21 February 2008 - 04:26 PM

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.
reedbeta.com - developer blog, OpenGL demos, and other projects

#4 MarekKnows.com

    Valued Member

  • Members
  • PipPipPip
  • 190 posts
  • LocationOntario, Canada

Posted 24 February 2008 - 02:31 PM

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?
C++, 3D OpenGL and Game Programming video tutorials:
www.MarekKnows.com
Play my free games: Ghost Toast, Zing

#5 kusma

    Valued Member

  • Members
  • PipPipPip
  • 163 posts

Posted 24 February 2008 - 06:38 PM

mmakrzem said:

I've read in the OpenGL doc
What do you mean by "the OpenGL doc"?

#6 MarekKnows.com

    Valued Member

  • Members
  • PipPipPip
  • 190 posts
  • LocationOntario, Canada

Posted 24 February 2008 - 06:40 PM

msdn: http://msdn2.microso...236(VS.85).aspx

my bad, it talks about glColorMaterial vs glMaterial
C++, 3D OpenGL and Game Programming video tutorials:
www.MarekKnows.com
Play my free games: Ghost Toast, Zing

#7 Reedbeta

    DevMaster Staff

  • Administrators
  • 5305 posts
  • LocationBellevue, WA

Posted 25 February 2008 - 01:05 AM

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.
reedbeta.com - developer blog, OpenGL demos, and other projects





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users