I'm having trouble getting lighting to work in program that rotates a cube. All I see is the solid color of my cube, and no shading of any kind. I've read and re-read what to do, and I can't figure out where I'm going wrong...
here are the relevant code segments:
void initLighting(void) {
GLfloat mat_properties[] = {1, 1, 0, 1.0};
GLfloat white_light[] = {1.0, 1.0, 1.0, 1.0};
GLfloat light_position[] = {5.0, 5.0, -5.0, 1.0 };
glShadeModel(GL_SMOOTH);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
glLightfv(GL_LIGHT0, GL_DIFFUSE, white_light);
glLightfv(GL_LIGHT0, GL_AMBIENT, white_light);
/* object color determined here */
glMaterialfv(GL_FRONT, GL_AMBIENT, mat_properties);
glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_properties);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
}
and in the display callback func:
glBegin(GL_QUADS);
for(int i = 0; i < 6; i++)
{
GLfloat d1[3], d2[3], norm[3];
for(int j = 0; j < 3; j++)
{
d1[j] = vdata[qindices[0]-1][j] - vdata[qindices[1]-1][j];
d2[j] = vdata[qindices[2]-1][j] - vdata[qindices[1]-1][j];
}
normcrossprod(d1,d2,norm);
glNormal3fv(norm);
glVertex3fv(&vdata[qindices[0]-1][0]);
glVertex3fv(&vdata[qindices[1]-1][0]);
glVertex3fv(&vdata[qindices[2]-1][0]);
glVertex3fv(&vdata[qindices[3]-1][0]);
}
glEnd();
</pre>
Thanks </i>
edit: there should be an after the first qindices, but I don't know how to turn off the codes
Edited by - Chupa on March 22, 2002 6:04:47 PM