Hey
Was wondering if anyone could give me some pointers or tips on lighting. I have done several samples, and have had lighting working without any issues. However, once I translate this lighting code into my application, nothing seems to work.
Essentially, I use the following to setup my rendering area:
width = 1024.0f
height = 600.0f
zDist = (height / 2.0) / tanf(DEGREE_TO_RAD(45.0f/2.0f);
gluPerspective(45.0f, width/height, 500, 2000)
gluLookAt(width/2.0f, height/2.0f, zDist, width/2.0f, height/2.0f, 0.0, 0.0, 1.0f, 0.0f);
The above sets up my code so that I have a rendering area of 1024x600 where z=0.
I can draw a 100x100x100 cube at 0x0x0 and have it appear in the bottom left hand corner of the screen perfectly. The issue I have is that after using the above transformations lighting no longer works.
I setup lighting as follows:
const GLfloat gLightAmbient[] = { 0.7f, 0.7f, 0.7f, 1.0f };
const GLfloat l0LightDiffuse[] = { 0.5f, 0.5f, 0.5f, 1.0f };
const GLfloat l0LightPosition[] = { 512.0f, 300.0f, 4.0f, 1.0f };
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, gLightAmbient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, l0LightDiffuse);
The global ambient lighting works. The diffuse lighting can work when I use the gluLookAt with my eye being at 0,0,4 and the center being at 0,0,0. when I try and break out of that I cannot figure out where I should position my light to get proper diffuse lighting. Any help or pointers would be appreciated. I have tried playing around with both directional and positional lighting to get something to work with little success.
Thanks