Color Lights

So far I have a code that displays a white light, and I would like to change the color of the lights.

GLfloat specular[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat shininess[] = { 50.0 };
GLfloat position[] = { 1.0, 1.0, 1.0, 0.0 };

glPushMatrix();
glMaterialfv ( GL_FRONT, GL_SPECULAR, specular );
glMaterialfv ( GL_FRONT, GL_SHININESS, shininess );
glLightfv ( GL_LIGHT0, GL_POSITION, position );

glTranslated( 0.0, 0.0, 5.0 );
glDisable( GL_LIGHTING );
glColor3f( 0.0, 1.0, 0.0 );
glutWireCube( 0.1 );
glEnable( GL_LIGHTING );
glPopMatrix(); 

How do I change the Light color?

  • VC6-OGL

GLfloat lightDiffuse[] = {1, 0, 0, 1};

glLightfv(GL_LIGHT0, GL_DIFFUSE, lightDiffuse);

That’s from the very top of my head. This creates a diffuse light with a red color. GL_DIFFUSE can be replaced with other lights too like GL_AMBIENT.

Thank you, now I understand what I was missing.

  • VC6-OGL