PDA

View Full Version : I know the official answer on lights that move with the camera, but...



halo
12-18-2003, 12:09 AM
Setting the light position right after glloadidentity() should give you lights that just stay where they are supposed to be, right?

My render routine first does some rotation and translation for the camera, then does rotation and translation for each mesh, then renders the mesh.

No matter what I do, my lights move with the position AND orientation of the camera! What am I doing wrong?

Thanks.




glViewport 0,0,w,h
glClear GL_COLOR_BUFFER_BIT Or GL_DEPTH_BUFFER_BIT
glLoadIdentity
gluPerspective 45.0,w/h,nearrange,farrange

setuplight

glPushMatrix

glRotatef -EntityRoll(camera),0,0,1
glRotatef EntityPitch(camera),1,0,0
glRotatef -EntityYaw(camera),0,1,0
glTranslatef -EntityX(camera),-EntityY(camera),EntityZ(camera)

glScalef 1,1,-1

render a bunch of stuff here

glPopMatrix
End Function

Function setuplight()
glEnable GL_LIGHT0
bank=CreateBank(16)
PokeFloat bank,0,1.0
PokeFloat bank,4,1.0
PokeFloat bank,8,1.0
PokeFloat bank,12,0.0
glLightfv GL_LIGHT0,GL_DIFFUSE,bank
FreeBank bank
bank=CreateBank(16)
PokeFloat bank,0,0
PokeFloat bank,4,0
PokeFloat bank,8,0
PokeFloat bank,12,1.0
glLightfv GL_LIGHT0,GL_POSITION,bank
FreeBank bank
glLightf GL_LIGHT0, GL_CONSTANT_ATTENUATION, 2.0)
glLightf GL_LIGHT0, GL_LINEAR_ATTENUATION, 1.0
glLightf GL_LIGHT0, GL_QUADRATIC_ATTENUATION, 0.1
End Function

12-18-2003, 12:26 AM
Have you tried messing with glMatrixMode(GL_PROJECTION) and glMatrixMode(GL_MODELVIEW) ?

I believe the answer is there.

halo
12-18-2003, 12:38 AM
I added a call to glMatrixMode GL_PROJECTION before the setuplight command, and it works perfectly now. Thanks dude.