PDA

View Full Version : Color Lights



Stack Overflow
01-04-2003, 09:23 AM
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

Structural
01-04-2003, 09:55 AM
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.

Stack Overflow
01-04-2003, 10:00 AM
Thank you, now I understand what I was missing.

- VC6-OGL