Jump to content
  • Advertisement
Sign in to follow this  
jmcheng

Another light question

This topic is 4251 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
Advertisement
Sorry, can't find atm another thread on this problem(but there are plenty here, the search function is a little bit messy). But this might help you: link

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!