PDA

View Full Version : Unable to set a headlight (flashlight)



Azdo
09-27-2002, 11:05 PM
Hello, I'm having trouble when trying to set a light from the camera's point of view. I set the light only once at the initialization of the window, after the OpenGL rendering context is set with these parameters:





float ambient[]={ 0.1, 0.1, 0.1, 1.0};
float difusse[]={ 1.0, 1.0, 1.0, 1.0};
float shininess[]={ 1.0, 1.0, 1.0, 1.0};
float position[]={ 0.0, 0.0, 1.0, 0.0}; /*w==0 direction*/

glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);

glLightfv(GL_LIGHT0,GL_AMBIENT,ambient);
glLightfv(GL_LIGHT0,GL_DIFFUSE,difusse);
glLightfv(GL_LIGHT0,GL_SHININESS,shininess);

glLightfv(GL_LIGHT0,GL_POSITION,position);



After that, I change the point of view with





gluLookAt(1000,1000,-1000,0,0,0,0,1,0);



Then I draw an horizontal plane and, after, an starship. The final render is:

http://galeon.com/azdo/lightOZ.jpg

Note that all the polygons are shaded with the same color, although they have different normal vectors. Changing the direction to





float position[]={ 0.0, 0.0, -1.0, 0.0};



leads to a weird representation where only exists a color:

http://galeon.com/azdo/lightOZ2.jpg

If I set instead the light direction to





float position[]={ 1.0, 0.0, 0.0, 0.0};



the scene is correctly rendered, with the light coming from the right (positive X axis):

http://galeon.com/azdo/lightOX.jpg

It also works correctly with the Y axis. I don't know why it just doesn't work with the Z axis, can anynone tell me?

Thanks in advance for your replies.


[This message has been edited by Azdo (edited 09-29-2002).]

Azdo
09-30-2002, 10:35 AM
Well, I updated the image links so they work now.

nexusone
09-30-2002, 10:43 AM
How have you setup your normals?

Also your matrial settings?


Originally posted by Azdo:
Well, I updated the image links so they work now.

Azdo
10-02-2002, 12:45 AM
Originally posted by nexusone:
How have you setup your normals?

Also your matrial settings?



I think he normals and the materials are fine as shown in the last picture, when the light comes from the right. It's the light direction what matters.

Anyway, I'm setting the normals per-polygon (using the normal vector to the polygon). When I get home, I'll post the material initialization code.

Azdo



[This message has been edited by Azdo (edited 10-02-2002).]