Everyone loves the redbook.
It is an excellent book.
However, even excellent books contain some mistakes.
I’m highlighting one mistake that was particularly troublesome to me today.
This is wrong.
The statement should read:
“If the last value, w, is zero, the corresponding light source is a directional one, and the (x, y, z) values describe its POSITION IN SPACE.”
How annoying. The quotation remains this way in the 5th edition of the redbook, and I doubt it was changed in the 6th.
* Lighting looks off? = Troubleshooting OpenGL lights
Does your lighting look odd, even though you’re certain you’ve computed the normals correctly? I recently ran into this issue and overlooked something very simple. After checking my normal computations again and again and being CERTAIN they were right, I found that the problem was not my normal computations at all. It was my setting up of the glLight.
Here we have a simple model, with correctly computed normals, and lighted.
When we shift the view using the mouse . . . we see this.
That looks wrong.
AFTER I FIXED IT, I finally got this:
How’d I fix it?
After checking my normal computatations again and again and being certain there wasn’t anything wrong with them, I went to check out my glLightfv() function calls.
I had made sure to specify my glLightfv() calls in my Init() function . .
glLightfv() was being called ONLY once at the beginning of the program . . . AND THAT WAS THE PROBLEM.
EVERYTIME YOU DRAW THE SCENE, you must re-specify the position of the light using a
glLightfv( GL_LIGHT0, GL_POSITION, lightVector );
So, be sure to put your glLightfv() calls INSIDE YOUR RENDER LOOP!