Hi, having a problem with getting the lighting to work correctly on a hierachical model. The model is made up of a static base, with different parts above being rotated.
The problem is that whilst the base is being lit correctly, the rest of the model seems to be being treated as if it’s a single object and shading applied to the whole thing rather than to individual faces. The result of this is that the moving part fades in and out as a whole as it rotates.
I’m assuming it’s something to do with how I’ve set up the matrix transformations, I’m a complete newbie so I may be doing something pretty stupid.
The executable is here if you want to see it in action: http://www.barwell.plus.com/misc/gl.exe
Here’s the code that I reckon is relevent, I can post more if needed:
GLfloat light_0_dir[]={1.0,0.5,0.5,0.0};
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glShadeModel(GL_SMOOTH);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glLightfv(GL_LIGHT0, GL_POSITION, light_0_dir);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glPushMatrix();
drawcube0(); //draw base
glRotatef(theta,0.0,1.0,0.0);
drawcube1(); //draw pole
glTranslatef(0,horsebob,0);
drawcube2(); //draw horses1+2
glRotatef(headspin,-0.1,0.0,0.0);
drawcube4(); //draw head1
glPopMatrix();
glPushMatrix();
glRotatef(theta,0.0,1.0,0.0);
glTranslatef(0,horsebob,0);
glRotatef(headspin,0.1,0.0,0.0);
drawcube5(); //draw head2
glPopMatrix();
glFlush();
glutSwapBuffers();
}
Thanks very much for any help.
Edit: I have tried setting up the lights properly within the modelview matrix as well (after glPushMatrix()) and the same problem occurs so I don’t believe it’s that.