Another light question

Started by
3 comments, last by xycsoscyx 17 years, 5 months ago
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???
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
-----"Master! Apprentice! Heartborne, 7th Seeker Warrior! Disciple! In me the Wishmaster..." Wishmaster - Nightwish
OpenGL Light FAQ
.
Try to put that code after move your camera, after glTranslate and glRotate.
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).

This topic is closed to new replies.

Advertisement