Multiple Lights & Colors

I’m sure I’m missing something obvious, but what I want is simple. I looked for any example code or related questions but can’t seem to find anything. I’m just trying to get the typical red green and blue lights illuminating an object. I can get a single light & color to work, but adding any other lights they all end up being the same color apparently.

The display function:

void Display() {

gluPerspective(45, (GLfloat) ww/(GLfloat) wh, 1, 700);



GLfloat LightAmbient[]= { 0.5f, 0.5f, 0.5f, 1.0f };
GLfloat LightDiffuse[]= { 1.0f, 1.0f, 1.0f, 1.0f };
GLfloat LightPosition[]= { 0.0f, 0.0f, 3.0f, 1.0f };

glColor4f(1, 0, 0, 1);
glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbient);
glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse);	
glLightfv(GL_LIGHT1, GL_POSITION,LightPosition);

LightPosition[2] = 0;
LightPosition[1] = 3;
glColor4f(0, 1, 0, 1);
glLightfv(GL_LIGHT2, GL_AMBIENT, LightAmbient);
glLightfv(GL_LIGHT2, GL_DIFFUSE, LightDiffuse);	
glLightfv(GL_LIGHT2, GL_POSITION,LightPosition);

LightPosition[1] = 0;
LightPosition[0] = 3;
glColor4f(0, 0, 1, 1);
glLightfv(GL_LIGHT3, GL_AMBIENT, LightAmbient);
glLightfv(GL_LIGHT3, GL_DIFFUSE, LightDiffuse);	
glLightfv(GL_LIGHT3, GL_POSITION,LightPosition);

glColor4f(1, 1, 1, 1);

// spin 'round some
rotate += 5;
glTranslatef(0, 0, -10);
glRotatef(rotate, 3, 1, 2);

sph.draw(); // draws the sphere


You don’t use glColor for specifying lighting colors, just material/vertex colors. The quads you set up in your lighting materials (your 4 float array) for specular, ambient and diffuse specify the color of the light in RGBA color.

Thus, get rid of glColor in the above code and replace it with new lighting definition arrays.

You’re defining a plain white light with your arrays. You need three seperate ones,
one with diffuse and ambient beging 1,0,0,1; the 2nd beging 0,1,0,1; and the last pair being 0,0,1,1 (or whatever combination you want)


[This message has been edited by Siwko (edited 06-14-2000).]