fixed func GL_LIGHTING problem (solved)

Started by
1 comment, last by Herr_O 17 years, 6 months ago
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]
_____________________________
www.OddGames.comwww.OddGames.com/daniel
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.
Thanks for explaining, i've read it in the OGL reference too, but it didn't sink in like it does now.
_____________________________
www.OddGames.comwww.OddGames.com/daniel

This topic is closed to new replies.

Advertisement