Jump to content
  • Advertisement
Sign in to follow this  
Herr_O

OpenGL fixed func GL_LIGHTING problem (solved)

This topic is 4374 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've heard about this problem before, and I think it is common. I've created a directional light but the direction must be inversed before it is used, otherways it lights where it shouldn't. This vector should point down... {-0.5f, -0.5f, 0.5f, 0.0f}, but my opengl code wants it to point upward. I have to "correct" it with this in order to have it light as I want it to: tmpdirection=-lightDir; glLightfv( GL_LIGHT0, GL_POSITION, tempLight); Thank you! [Edited by - Herr_O on October 2, 2006 2:39:22 AM]

Share this post


Link to post
Share on other sites
Advertisement
Remember that GL_POSITION is simply the position of the light. OpenGL itself has no notion of a positional or directional light, it merely has a position for the light that is used in the lighting calculations. Since the position is specified in homogeneous coordinates, if w is set to 0.0 it is equivalent to a position at infinity in the direction given by x, y, and z.

Now when you think about a light bulb, you can picture it having a position in 3d space and its light rays emanate outward from that position. You probably visualize a "positional" light in OpenGL the same way... you specify its position and its "light rays" shoot out away from that point in space. You have to think of a "directional" light in the same sense, only you specify its position at infinity, so its "light rays" shoot out from that point at infinity, thus in the opposite direction of the position you specify.

So for example, if you specify the light's position as (0,0,1,0), which is the default light position, that is like saying the light is positioned at infinity on the +z axis. So that means when the light comes from (0,0,+inf) it is shining down the -z axis.

Share this post


Link to post
Share on other sites
Thanks for explaining, i've read it in the OGL reference too, but it didn't sink in like it does now.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!