1

Guys, how can this be. But in my previous projects, it wasn't. And I don't know how I attempt this effect. Tell me the truth, please.

1
  • I'm sorry I have no idea what your problem is, or what you are asking about. Please try to make a more detailed description of your issue (code samples, diagram, something)
    – Mat
    Apr 6, 2011 at 19:01

1 Answer 1

4

Section 18.050, How can I make my light move or not move and control the light position?:

First, you must understand how the light position is transformed by OpenGL.

The light position is transformed by the contents of the current top of the ModelView matrix stack when you specify the light position with a call to glLightfv( GL_LIGHTn, GL_POSITION, ... ). If you later change the ModelView matrix, such as when the view changes for the next frame, the light position isn't automatically retransformed by the new contents of the ModelView matrix. If you want to update the light’s position, you must again specify the light position with a call to glLightfv( GL_LIGHTn, GL_POSITION, ... ).

...

  • How can I make my light position stay fixed relative to my eye position? How do I make a headlight?

You need to specify your light in eye coordinate space. To do so, set the ModelView matrix to the identity, then specify your light position. To make a headlight (a light that appears to be positioned at or near the eye and shining along the line of sight), set the ModelView to the identity, set the light position at (or near) the origin, and set the direction to the negative Z axis.

When a light’s position is fixed relative to the eye, you don't need to respecify the light position for every frame. Typically, you specify it once when your program initializes.

2
  • 1
    Umm, The FAQ's code example is incorrect. There's no token GL_LIGHT_POSITION that was ever accepted by OpenGL. Positioning a light should be set by calling glLightfv( GL_LIGHT<n>, GL_POSITION, ... );, where <n> represents the light number. This answer has been edited to show the correct syntax.
    – radical7
    Mar 25, 2013 at 5:03
  • @drewster: Fixed.
    – genpfault
    Nov 28, 2019 at 23:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.