Lighting help

Hello all,

I am currently working on a small dungeon crawling game using OpenGL and written in C.

I have run into a bit of a speed bump in that I cannot seem to get my lighting effects working with the correct normals.

When I define the normals I have calculated with each surface, the lighting effects behave unpredictably (sometimes remaining dark even with light sources nearby, sometimes not reacting to ambient lighting at all, etc…). However, when I use the coordinates (0, 0, 1) for each normal vector, the lighting seems to behave naturally regardless of whether or not (0, 0, 1) are theoretically the correct coordinates. I know that the normals that I have calculated myself are correct in theory as I have double checked them with a vector calculator. Would anyone happen to know what might be causing this?

This is my draw function-

GLvoid DungeonConstruction(GLvoid)
GLfloat x_m, y_m, z_m, u_m, v_m;
GLfloat xtrans, ztrans, ytrans;
GLfloat sceneroty;
int totalWalls;
//camera variables
xtrans = -xpos;
ztrans = -zpos;
ytrans = -mov1-0.5;
sceneroty = 360.0 - yrot;


glRotatef(lookupdown, 1.0, 0, 0);
glRotatef(sceneroty, 0, 1.0, 0);

glTranslatef(xtrans, ytrans, ztrans);    

//here are function calls to shapes (normals are defined in each polygon’s respective function.)


This my initGL function-

GLvoid GLStuff(GLsizei Width, GLsizei Height)

glClearColor(0.0, 0.0, 0.0, 0.0);	




glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbient);
glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse);
glLightfv(GL_LIGHT1, GL_POSITION, LightPosition);


I can provide more specific bits of code on request.

Thanks in advance!

How coarse is the geometry? Vertex lighting works best with smooth surfaces tessellated into many small faces. It doesn’t work so well if the distance between a point light source and a face isn’t significantly larger than the face (because you’re under-sampling the intensity function), or if you’re using per-vertex lighting (smooth shading) and the angle between adjacent faces is large (so adjacent normals point in substantially different directions).

Also, if you’re calculating normals from the geometry, make sure that they all point the same way (typically outward for a closed surface). If the direction is inconsistent, the results will be garbage. In practice, this means that your faces must have consistent orientation (i.e. either always clockwise or always anti-clockwise, when facing perpendicular to the face from a given side).