PDA

View Full Version : Display lists and moving light



christus
11-11-2004, 12:25 PM
Hi to all, sorry for my English and silly questions, simply Iím new in business. OK, hereís my problem. Iím drawing few objects using display lists and rotating them using mouse. The trouble is that I want light to remain in one point and not to rotate or move with drawn objects. Tell me what Iím doing wrong. I initialize GL, set viewport, set lights, load objects from file, calculate vertex normals, and prepare display lists (each object to a different list, no light calls during creating lists). Finally while drawing a frame I do not call glLightfv( GL_LIGHT0, GL_POSITIONÖ at all, or call it before rotating and translating anything, but light moves anyway. Code looks like this:

{
glMatrixMode( GL_MODELVIEW);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glLoadIdentity();

glRotatef(XRotation+XDelta,0,1,0);
glRotatef(YRotation+YDelta,1,0,0);

glColor3f(0.6,0.6,0.6);
for (unsigned int i = 1; i <= Scene->ObjectCount; i++)
{
glCallList(i);
}
glPopMatrix();
glFlush();
SwapBuffers(hdc);
}Iím using C++Builder 6. As you see it couldnít be simpler. This is light preparation code:

{
glEnable(GL_DEPTH_TEST);
glFrontFace(GL_CCW);
glEnable(GL_NORMALIZE);
glEnable( GL_LIGHTING);

glLightfv( GL_LIGHT0, GL_AMBIENT, swiatlo_ambient);
glLightfv( GL_LIGHT0, GL_DIFFUSE, swiatlo_diffuse);
glLightfv( GL_LIGHT0, GL_POSITION, swiatlo_position);
glLightfv( GL_LIGHT0, GL_SPECULAR, swiatlo_specular);
glEnable( GL_LIGHT0);

glEnable(GL_COLOR_MATERIAL);
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
glMaterialfv(GL_FRONT,GL_SPECULAR,swiatlo_specular );
glMateriali(GL_FRONT,GL_SHININESS,128);
glClearColor( 0.0, 0.0, 0.0, 0.0);
}Did I forgot something? Or am I just stupid? I just donít want the light to move. When I draw a sphere using auxSolidSphere every thing is perfect, and when I draw a same sphere by display the light just cant stay in one point. :confused: Help.

iznogoud
11-11-2004, 12:51 PM
First of all you have a mistake! When you call
glColorMatarial(); you need to give two (2)
arguments, not three! The fucntion simply takes the
current (active) colour and applies it to the
material you specify with your call. So, you will
need a glMaterial(,,); call first with your colour
values. (I cannot believe I caught this one!)
just get rid of this call and use many glMaterial
calls (my opinion).

I doubt this is going to solve your problem, but I
had to say it.

And put these two calls in the lighting preparation
code too:
glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE);