PDA

View Full Version : Lighting problem



jobson
04-26-2012, 06:33 PM
Hi,

I drew two yellow polygons parallel to the axis Z. Both are looking toward the positive X axis. The problem is: when the light is close to the polygon A, it becomes dark yellow. Otherwise, when the light is close to the polygon B, it becomes light yellow, as I expected. I tried to change the normal vector of the polygon A to (-1, 0, 0) and it seems to work,i.e., hen the light is close it, it becomes light yellow. I cannot figure out why the behavior is completely different for polygon A and B. What am I missing ?

I attached a small program to show what I am talking about: the "r" key rotates the light and the arrows move the camera.

Thanks

kowal
04-27-2012, 10:14 AM
Hello,


You called:



glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);


in your code. Last argument should be {0,0,0,1}, because light position is transformed by Modelview matrix.
(set by glTranslate and glRotate before call to glLightfv)

jobson
04-27-2012, 02:23 PM
Thatīs it !

Thanks a lot.

Jobson