Archived

This topic is now archived and is closed to further replies.

Lighting

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

hey, I was having a few problems with my lighting, i have included a light into my little scene. Although the problem is the light moves as the camera does even with a glPushMatrix/glPopMatrix. How can i stop this ?

Share this post


Link to post
Share on other sites
If you set the light location in your init code and does not change it later should it be fix. Treat the light position like a normal vertex position.

Share this post


Link to post
Share on other sites
You have to set your Light-Position every Frame !

Pseudo-Code:

DrawScene()
{
glRotatef(Cam.CamRotX,1.0f,0,0);
glRotatef(360.0f - Cam.CamRotY,0,1.0f,0);

glTranslatef(-Cam.CamXPos, -Cam.CamYPos, -Cam.CamZPos);

glLightfv(GL_LIGHT1, GL_POSITION, LightPosition); // Position The Light
}

In this Code the Light is Rotated and Tranlated too, and so
it has a "fix" position in the world.

Share this post


Link to post
Share on other sites
quote:
Original post by Crash_Kid
You have to set your Light-Position every Frame !


No, take a look at the faq.

quote:

Pseudo-Code:

DrawScene()
{
glRotatef(Cam.CamRotX,1.0f,0,0);
glRotatef(360.0f - Cam.CamRotY,0,1.0f,0);

glTranslatef(-Cam.CamXPos, -Cam.CamYPos, -Cam.CamZPos);

glLightfv(GL_LIGHT1, GL_POSITION, LightPosition); // Position The Light
}

In this Code the Light is Rotated and Tranlated too, and so
it has a "fix" position in the world.

Yes, but he did not want it to move with (be fix to) the camera. The desired result is a light that is fix relative to the absolute (global) coordinate system.

Share this post


Link to post
Share on other sites