I’ve got a Problem with my specular highlights. My situation:
An object (like an egg), my camera(which I set with gluLookAt(…) and a positional light ( light-egg-camera angle is 45 degrees in xz-plane). I turn the camera around the egg (the light alway this 45 degrees next to the camera). The problem is, that the highlights are computed someway wrong. It appears not always on the lighten side of the egg. Sometimes it appears on the dark side. Here some code:
for the material of the egg.
plus in the egg-render-function
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, m_Ambient);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, m_Diffuse);
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, m_Specular);
glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, m_Shinyness);
Originally posted by qwert: I forgot: I do the gluLookAt(…) before the rendering.
Yeah, I never quite seemed to get the lighting work properly when using gluLookAt(). Instead,
before rendering objects call glTranslate and glRotate to move the objects (camera) and see if it works. Worked for me
Redbook has a nice piece of code in chapter 3 called ‘void polarView(…)’.
Using gluLookAt is perfectly fine and does not in itself mess up lighting. It is only doing the same matrix transformations that you are now trying to do explicitly.
The most common causes of lighting problems would be incorrect normals, and incorrect light position. For example you say you do a gluLookAt before rendering. Do you also set the light position after using gluLookAt? You need to every frame of course.
It’s kind of strange…
Now, my camera movement is completely messed up, but the specular highlights are shown correct.
If I use gluLookAt(…) instead of my own function, the ligthing is wrong again. I change only the gluLookAt(…) by OwnLookAt(…).
Ok DFrey, I found it, you were right . gluLookAt really don’t mess anything up. When I called glulookAt, I was actually in the prjection-matrix and not in rhe modelview-matrix as it should be. Maybe you made the same mistake, niko.
Thanks very much for your help, that was a lousy one.
Originally posted by qwert: When I called glulookAt, I was actually in the prjection-matrix and not in rhe modelview-matrix as it should be. Maybe you made the same mistake, niko.
Right, so I did [bangs head on the table]. But anyways, because of that mistake I now know the math to do my own ‘gluLookAt()’. Sweet.