Jump to content
  • Advertisement
Sign in to follow this  
someone2

Where exactly to set the position of light?

This topic is 4625 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

Hi, I am experimenting with lights and I really am stuck on this one... where exactly in the code should I set the position of the light? There are 2 approaches... 1. Right at the beginning of drawing a scene.. glMatrixMode(GL_MODELVIEW); glLoadIdentity(); //Followed immediately by.. glLightfv(GL_LIGHT1, GL_POSITION, lightPosition2); 2. Right before drawing the shape... For example... gluLookAt(0, 1, 3, 0, 0, 0, 0, 1, 0); glRotatef(rotation*3+pi*i/numCubes, 0, 1, 0); glScalef(0.12,0.12,0.12); glTranslatef(translation,0,0); glRotatef(rotation*5,0,1,0); Now, followed by... glLightfv(GL_LIGHT1, GL_POSITION, lightPosition2); And then drawing. What are the differences? Which is the more logical one? Thank you very much in advance

Share this post


Link to post
Share on other sites
Advertisement
The two cases are different, and both are correct, because you use them to achieve different things. So which one is correct for you obviously depends on what you want to do with the light.

The light position, when set, is transformed by the modelview matrix, and since the viewpoint is, to OpenGL, always fixed at the origin, the result of this is:

In case 1: The light position is relative the viewpoint. The light will appear to follow the viewpoint as you move around the world.

In case 2: The light position is relative the object being drawn. the light will appear to follow the object.

In case 3: You didn't mention this case, but it's more common than the two you mentioned actually. Here you set the light position between the viewpoint transforms and the object transforms (between gluLookAt and glScale in case 2). The light position is in worldspace coordinates and will appear in a fixed position in the world.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!