Skip navigation

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.

“If the last value, w, is zero, the corresponding light source is a directional one, and the (x, y, z) values describe its direction.”

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:

And 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 );

type call.

So, be sure to put your glLightfv() calls INSIDE YOUR RENDER LOOP!




  1. Thx for the tip! Ligthing works now as it should.

  2. I bet you’d get some argument about that if you encountered one of the people who wrote the redboook. The reason I say that is, if a directional light is considered to be an infinite distance away, how could you then specify a position in space?

    • Kim Etzerodt
    • Posted November 15, 2008 at 9:00 pm
    • Permalink

    How can x, y and z describe the position of a direcitonal light, when a directional light has no position?

  3. Actually, the phrase should read:

    “If the last value, w, is zero, the corresponding light source is a POSITIONAL one, and the (x, y, z) values describe its position in space.”

  4. Whoops. No, you’re right. Zero does indeed indicate a Directional light. My bad.

  5. If the w value is zero, then the point lies on the plane at infinity, and the x,y,z effectively becomes a direction vector.

    Learn more about homogenous coordinates to understand this – it’s the whole reason there’s a w to begin with!

    • BlindSide
    • Posted April 21, 2009 at 5:17 am
    • Permalink

    And going by that statement, setting the X, Y, Z would give you the exact opposite direction of the intended direction, hence it’s like setting it’s position in infinity.

    • Anonymous
    • Posted June 17, 2011 at 1:50 am
    • Permalink

    Great thing. Thanks bobobo.

    • Jiwon
    • Posted February 24, 2012 at 8:08 am
    • Permalink

    Thanks! I had been banging my head against the wall with this for a while as well, and your solution fixed it :D

    • Me
    • Posted September 12, 2012 at 8:22 pm
    • Permalink

    I am siding with Kimani here. The book is correct. I think the explanation here regarding the homogenous coordinate is really helpful:

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: