Lighting Issues (screenshots)

Started by
8 comments, last by Hexed 18 years, 9 months ago
Hi I'm beginning to write an OpenGL program and everything is going great except I notice the scene lighting is... strange. It seems like the lighting changes depending on the current camera position and angle. That's the only way I can really explain it, so I shall include screenshots. Notice how the lighting on the teapot model changes as the camera moves around the object. Also notice 31337 pr0gr4mm3r t3xtur3z.
Advertisement
how 'bout a snippet of code laddie?
Sure thing. I'll include anything that I believe to be relevant, if you need more just let me know. In order of execution...

From resource loading function:
glLightfv (GL_LIGHT1, GL_DIFFUSE, sector01.light.rgba);glLightfv (GL_LIGHT1, GL_POSITION, sector01.light.pos);glEnable (GL_LIGHT1);


From GL initialization function:
glShadeModel (GL_SMOOTH);glEnable (GL_LIGHTING);


And I believe that's all I have for lighting code. One light is in this scene, positioned at [0,0,0]. And I also call glNormal3f for each poly in order to ensure correct lighting.
If your camera code is calling glTranslatef() you're probably translating the light position.
That's what I thought at first too. I was using these calls in main GL drawing function:

glRotatef(-xrot, 1.0f, 0.0f, 0.0f);glRotatef(-yrot, 0.0f, 1.0f, 0.0f);glTranslatef(-xpos, -ypos, -zpos);


And I tried replacing that with gluLookAt(), but same results. wtf?
From the screenshots it looks like the light gets rotated the opposite direction with the scene before translating. You should handle the light position as if it was just another vertex in the scene.
Try putting the glLightfv (GL_LIGHT1, GL_POSITION, sector01.light.pos); after the translating and before the rendering code.
Erm this is not working. Wouldn't that translate the light with the camera anyway? It doesn't sound right to me, none of the tutorials I have read mention anything like that.
Show more rendering code / post a more detailed order of operations...
the rug - funpowered.com
tassu is correct, after u position the camera u must reposition the lights
check the redbook, the faq etc
Thanks for the replies. Tassu's suggestion solved my problems, I just wasn't understanding that the lights needed to be handled basically the same as a vertex in the scene. Now I am trying to fix another lighting problem, and I believe the issue is that I'm not rotating and supplying the correct glNormal3f. Kind of annoying. :) Thanks guys.

This topic is closed to new replies.

Advertisement