# Another light question

## 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);

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);


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 on other sites
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 on other sites
Try to put that code after move your camera, after glTranslate and glRotate.

##### 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).

## Create an account

Register a new account

• ## Partner Spotlight

• ### Forum Statistics

• Total Topics
627644
• Total Posts
2978367

• 10
• 12
• 22
• 13
• 33