Only one light working

Hi,
Any ideas why I can only get one light to work in my scene. Here is my globals:

//LIGHT 0 Properties
GLfloat light0Pos[] = {10.0f, 12.0f, -30.0f,1.0f};
GLfloat light0Colour[] = {1.0f, 1.0f, 1.0f};

//LIGHT 1 Properties
GLfloat light1Pos[] = {-10.0f,12.0f,-30.0f,0.0f};
GLfloat light1Colour[] = {1.0f, 1.0f, 1.0f};

And here is my Initialise function:


float AmbientColour0[] = {1.0f, 1.0f, 1.0f, 1.0f};
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, AmbientColour0); 
	
//Now Setup LIGHT 0
//glEnable(GL_LIGHT0);	
glLightfv(GL_LIGHT0, GL_POSITION, light0Pos);		
glLightfv(GL_LIGHT0,GL_AMBIENT_AND_DIFFUSE,light0Colour);

//Now Setup LIGHT 1
glEnable(GL_LIGHT1);	
glLightfv(GL_LIGHT1, GL_POSITION, light1Pos);	glLightfv(GL_LIGHT1, GL_AMBIENT_AND_DIFFUSE,
light1Colour);

So they are basically using the same properties but light 1 is moved to x-10. When I disable Light 0, there is no light so that is the only one working. Hope you can help, again hehe
thanks

There’s nothing obviously wrong with the code you have posted but there’s not enough context to be able to answer your question. Is light1 behind the object? If so you won’t see it unless you move your camera.

Hi

GLfloat light1Pos[] = {-10.0f,12.0f,-30.0f,0.0f};
If I’m not mistaking w = 0.0f gives a directional
light.

Its initial position is (0, 0, 1, 0) and the orientation is parallel to and in the
direction of the -z axis.Then you move it further away in the direction of the -z axis.I suppose
that’s not what you want.

Hope it helps.
Claude

Hi thanks for the replies. The light is not behind the object, and the camera is free moving with the keyboard. I disabled the object and it has no effect. I also tried playing with the directional and positional light property. Still only ligt 0 will work. :frowning: please help

light positions get transformed by the mv matrix as any other vertex you submit:
have you tried to specify them once per frame and not only at init time ?

something like:

//	every frame

glMatrixMode( GL_MODELVIEW );
glLoadIdentity();

handle_camera_and_set_mv_matrix();

glLightfv( GL_LIGHT0, GL_POSITION, light0Pos );
glLightfv( GL_LIGHT1, GL_POSITION, light1Pos );

draw_scene();

Light colors should be four-component vectors, just as material colors.

glLightfv does not accept GL_AMBIENT_AND_DIFFUSE as second parameter. Thus you are not setting any light color for GL_LIGHT1, where all values default to 0.0.