Why in Opengl Red Book I read that to keep
stationary light I need to set the light
position after whatever viewing and modeling transformation.
But it’s strange this code:
I see a rotating sphere and a stationary light.
void display(void)
{
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
GLfloat position[] = { 0.0, 0.0, 2, 1.0 };
GLfloat direction[] ={0,0,-1};
glLightfv(GL_LIGHT0,GL_POSITION,position);
glLightfv(GL_LIGHT,GL_SPOT_DIRECTION,direction);
glLightf(GL_LIGHT0,GL_SPOT_CUTOFF,20);
glTranslatef(0,0,-4);
glRotatef(spin,0,1,0);
glutSolidSphere(1.0,20,20);
glutSwapBuffers();
glutPostRedisplay();
glFlush ();
spin =(spin +1) % 360;
}
but if I think in local coordinate system
I put the light first of modelview transformation.
Hi.