Lighting seems relative to camera orientation?

Started by
2 comments, last by snak_attack 16 years, 5 months ago
I have what is I suspect a really noob question. I set up a global light, and use glLookAt to position & orient my camera. For the most part all is well. However, I notice that as I rotate the camera (changing not the location of the camera, just the look-at-target), polygons get lighter and darker. I thought maybe I was picking up some specular lighting, but I think I've disabled that. Here is the code (JOGL): gl.glEnable(GL.GL_LIGHTING); gl.glEnable(GL.GL_LIGHT1); gl.glLightfv(GL.GL_LIGHT1, GL.GL_AMBIENT, new float[] { .1f, .1f, .1f, 1f}, 0); gl.glLightfv(GL.GL_LIGHT1, GL.GL_DIFFUSE, new float[] { 1, 1, 1, 1}, 0); gl.glLightfv(GL.GL_LIGHT1, GL.GL_SPECULAR, new float[] { 0, 0, 0, 0}, 0); float[] pos = new float[] { .866, .5, 0, 0 }; gl.glLightfv(GL.GL_LIGHT1, GL.GL_POSITION, pos, 0); Any idea what I am doing wrong? thanks snak
Advertisement
Everytime you set the light position it is transformed by the current modelview matrix. To place it statically in the world set the light position every frame after you set the modelview matrix to the camera transformation.
If I was helpful, feel free to rate me up ;)If I wasn't and you feel to rate me down, please let me know why!
After the definition if the w part of a position of a light is 0 it is a directional light. If you want it to be a point light you have to specify the w with 1.

---> float[] pos = new float[] { .866, .5, 0, 1 }; <---

Everytime you move the camera you should also update the light position to get correct results.
http://3d.benjamin-thaut.de
Thanks, that helped. It turned out that I was making my lighting calls every frame, but before the call to glLookAt. Once I changed the order it looks much better. Thanks again

This topic is closed to new replies.

Advertisement