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;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glEnable(GL_NORMALIZE);
glRotatef(lookupdown, 1.0, 0, 0);
glRotatef(sceneroty, 0, 1.0, 0);
glTranslatef(xtrans, ytrans, ztrans);
glBindTexture(GL_TEXTURE_2D,texture[0]);
//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)
{
LoadGLTextures();
glEnable(GL_TEXTURE_2D);
glClearColor(0.0, 0.0, 0.0, 0.0);
glClearDepth(1.0);
glDepthFunc(GL_LESS);
glEnable(GL_DEPTH_TEST);
glShadeModel(GL_SMOOTH);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f,(GLfloat)Width/(GLfloat)Height,0.1f,100.0f);
glMatrixMode(GL_MODELVIEW);
glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbient);
glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse);
glLightfv(GL_LIGHT1, GL_POSITION, LightPosition);
glEnable(GL_LIGHT1);
}
I can provide more specific bits of code on request.
Thanks in advance!