PDA

View Full Version : light and modelview transformation



almok
06-30-2001, 05:36 AM
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.

zed
06-30-2001, 12:28 PM
Originally posted by almok:
Why in Opengl Red Book I read that to keep
stationary light
But it's strange this code:
I see a rotating sphere and a stationary light.


isnt that what you want??

almok
07-01-2001, 12:29 AM
Originally posted by zed:
isnt that what you want??

I don't know because Opengl Red Book tell
that to keep a stationary light I need to set this after modeling and viewing transformation when in my code I have set
the light code first of modeling trasformation.
what I mistake?

Hi.