code to calculate a cross product... float *cross( vertex c0, vertex c1, vertex c2, float *targvect ) { float v1[3]; float v2[3]; v1[X] = c0.x - c1.x; v1[Y] = c0.y - c1.y; v1[Z] = c0.z - c1.z; v2[X] = c1.x - c2.x; v2[Y] = c1.y - c2.y; v2[Z] = c1.z - c2.z; targvect[X] = v1[Y] * v2[Z] - v1[Z] * v2[Y] ; targvect[Y] = - v1[X] * v2[Z] + v1[Z] * v2[X] ; targvect[Z] = v1[X] * v2[Y] - v1[Y] * v2[X] ; return targvect; } /* end function cross */ code to compute polygon normals... for (i = 0; i < m->num_polygons; i++) { cross( m->the_vertices[m->the_polygons[i].points[X]], m->the_vertices[m->the_polygons[i].points[Y]], m->the_vertices[m->the_polygons[i].points[Z]], m->the_polygons[i].p_normal ); } code to compute vertex normals.... vertex *v; polygon *p; for ( each polygon ) { p = &( m->the_polygons[ i ] ); for ( each vertex in polygon ) { v = &( m->the_vertices[ p->points[j] ] ); v->v_normal[X] += p->p_normal[X]; v->v_normal[Y] += p->p_normal[Y]; v->v_normal[Z] += p->p_normal[Z]; } } to initialize the lighting.... GLfloat mat_amb[] = { 0.1, 0.0, 0.1, 1.0 }; GLfloat mat_dif[] = { 0.6, 0.3, 0.6, 1.0 }; GLfloat mat_specular[] = { 1.0, 0.0, 1.0, 1.0 }; GLfloat mat_shininess[] = { 2.0 }; the_light.pos[X] = 0.0; /* x */ the_light.pos[Y] = 5.0; /* y */ the_light.pos[Z] = 0.0; /* z */ the_light.pos[W] = 1.0; /* homogeneous */ glMaterialfv(GL_FRONT, GL_AMBIENT, mat_amb); glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_dif); glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular); glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); the_light.ambient[X] = 0.2; the_light.ambient[Y] = 0.2; the_light.ambient[Z] = 0.2; the_light.ambient[W] = 1.0; the_light.diffuse[X] = 1.0; the_light.diffuse[Y] = 1.0; the_light.diffuse[Z] = 1.0; the_light.diffuse[W] = 1.0; the_light.specular[X] = 1.0; the_light.specular[Y] = 1.0; the_light.specular[Z] = 1.0; the_light.specular[W] = 1.0; glLightfv ( GL_LIGHT0, GL_POSITION, the_light.pos ); glLightfv ( GL_LIGHT0, GL_AMBIENT, the_light.ambient ); glLightfv ( GL_LIGHT0, GL_SPECULAR, the_light.specular ); glLightfv ( GL_LIGHT0, GL_DIFFUSE, the_light.diffuse ); to enable the zbuffer... glDepthFunc(GL_LESS); glEnable(GL_DEPTH_TEST);