I’ve just encountered a bit of strangeness setting the position of a light, and I’m curious as to the reason.
Here’s the code:
GLfloat lightPos = { 0.0f, 0.0f, 75.0f, 1.0f };
GLfloat spotDir = { 0.0f, 0.0f, -1.0f };glLoadIdentity();
// translate scene into view
glTranslatef( 0.0f, 0.0f, -250.0f );glLightfv( GL_LIGHT0, GL_POSITION, lightPos ); // <------- This is the bad line
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glColor3f( 0.0f, 1.0f, 0.0f );
auxSolidSphere( 30.0f );glPushMatrix();
glRotatef( yRot, 0.0f, 1.0f, 0.0f );
glRotatef( xRot, 1.0f, 0.0f, 0.0f );glLightfv( GL_LIGHT0, GL_POSITION, lightPos );
glLightfv( GL_LIGHT0, GL_SPOT_DIRECTION, spotDir );
glPopMatrix();glFlush();
As the code is the spotlight appears to come from the wrong direction or just “doesn’t look right”, though I can’t tell just why. If I remove the first glLightCall() (the bad one) then the surface of my sphere gets lit exactly the way I expect.
The thing I don’t understand is, why doesn’t the second call to glLight() simply overwrite the position set by the first call? Since I have called glLight() to set the positon before doing a coordinate rotation is the light somehow locked to it’s previous coordinate system, or what?
My code works when I remove the first line (which didn’t really have a good reason to be there anyway…), but I’m still quite curious about what’s actually going on. I couldn’t find anything in the blue book that indicated what this might be, so I thought I’d run it by you guys…