Sign in to follow this  

Another light question

This topic is 4031 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 Does another encounter a problem where whenever you move your camera around, the light source seems to be moving with you (the camera is the light source position).

GLfloat lightPosition[] = {10.0f, 5.0f, 10.0f, 1.0f};
GLfloat lightDiffuse[] = {0.5,1,1,1};
GLfloat lightAmbient[] = {0.0f, 0.0f, 0.0f, 1.0f};

glEnable(GL_COLOR_MATERIAL);
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);

glLoadIdentity();
glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);
glLightfv(GL_LIGHT0, GL_DIFFUSE, lightDiffuse );
glLightfv(GL_LIGHT0, GL_AMBIENT, lightAmbient);

glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, 1.0f);
glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 0.0f);
glLightf(GL_LIGHT0, GL_QUADRATIC_ATTENUATION, 0.0f);


The above code is to set the light source. As you can see, there are no moving lightposition variable operation but somehow, the light moves on it's own???

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Try to put that code after move your camera, after glTranslate and glRotate.

Share this post


Link to post
Share on other sites
If I remember right (been a while since I used OpenGL) it transforms things differently depending on the current matrix stack. When you set your transformation matrices and light data are order dependant, when are you setting your lights currently (before or after you set your transformation matrices)? Have you tried flipping the order (like the previous poster stated), so if you're setting lights after you set your camera, try setting the lights first instead (and vice versa).

Share this post


Link to post
Share on other sites

This topic is 4031 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this