PDA

View Full Version : Normals kill already unworking lights



CyberSlag5k
02-03-2005, 10:20 AM
I'm reading a 3D model (right now just a sphere) in from an STL file. For those that don't know, all an STL file is composed of are the vertices for a set of triangles and the surface normals for those triangles. I can get the shape to draw, but I can't get it to light properly. Without making a call to glNormal3f, the object is completely unlit. Well, somewhat in that it will light up gradually as it is rotated and then fade back to unlit. The odd thing is that if I just move the camera to the other side of the sphere, it remains unlit. It only lights if I rotate only the sphere.

This screamed to me "hey, give me surface normals!" So I did and now the sphere doesn't light at all under any conditions. I tried inverting some (and all) of the normals, but that didn't work. I'm quite certain they are all of unit length, as they are read that way from the file (I checked it by hand).

My lights work properly with just a basic sphere (ala glutSolidSphere()). I'm presently using a single, white light with diffuse and specular properties. The sphere lights up if I switch to ambient, but that's about it.

Here's all my lighting stuff:

GLfloat mat_specular[] = {1.0f, 1.0f, 1.0f, 1.0f};
GLfloat mat_shininess[] = {50.0f};

glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);

GLfloat light_position[] = {1.0f, 3.0f, 1.0f, 0.0f};
GLfloat white_light[] = {1.0f, 1.0f, 1.0f, 0.0f};
GLfloat white_light2[] = {0.5f, 0.0f, 1.0f, 0.0f};


glLightfv(GL_LIGHT0, GL_POSITION, light_position);
glLightfv(GL_LIGHT0, GL_DIFFUSE, white_light);
glLightfv(GL_LIGHT0, GL_AMBIENT, white_light2);
glEnable(GL_LIGHT0);

//draw stuffI'm not sure what else to do, as the normals seem to be of little use...

CyberSlag5k
02-03-2005, 12:23 PM
I solved the problem. I forgot to reset my normalVector linked list before I used it.