Lighting + Shading..

i have a light source diffuse set up but it seems that the light rotates with my object when it should not. i would like to see my lighting regardless of how i rotate my object… what am i doing wrong??

I think you have placed the code that positions the light source at the wrong place, it is affected by the transformations, could you post the code maybe for your lighting and modelview matrix setup ?


sure here you go…

//variables, includes etc etc…

GLvoid ReSizeGLScene(GLsizei width, GLsizei height) // Resize And Initialize The GL Window
if (height==0) // Prevent A Divide By Zero By
height=1; // Making Height Equal One

glViewport(0,0,width,height);						// Reset The Current Viewport

glMatrixMode(GL_PROJECTION);						// Select The Projection Matrix
glLoadIdentity();									// Reset The Projection Matrix

// Calculate The Aspect Ratio Of The Window

glMatrixMode(GL_MODELVIEW);							// Select The Modelview Matrix
glLoadIdentity();									// Reset The Modelview Matrix


//some functions called later…

int InitGL(GLvoid) // All Setup For OpenGL Goes Here
glShadeModel(GL_SMOOTH); // Enable Smooth Shading
glClearColor(0.0f, 0.0f, 0.0f, 0.5f); // Black Background
glClearDepth(1.0f); // Depth Buffer Setup
glEnable(GL_DEPTH_TEST); // Enables Depth Testing
glEnable(GL_NORMALIZE); // unit normal is always set to 1, dont need to call normalize(normal)

glInitNames();   //intilialize the NAME STACK -- for stacking names for picking

//glDepthFunc(GL_LEQUAL);								// The Type Of Depth Testing To Do

glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);	// Really Nice Perspective Calculations

float ambientLight[] = {0.5, 0.5, 0.5, 1.0};
float diffuseLight[] = {1.0, 1.0, 1.0, 1.0};

float lightPosition[] = {0.0, 0.0, 1.0, 1.0}; //0.0 makes it a directional light coming from the positive z axis
glLightfv(GL_LIGHT1, GL_AMBIENT, ambientLight);
glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuseLight);
glLightfv(GL_LIGHT1, GL_POSITION, lightPosition);


i hope this will come out looking right…

the other problem i have having with my heightmap is that it is hard for me to figure out which way to point the normal b4 each vertex3f call b/c each vertex might be pointing somewhere else , so how would i do this? should i post also my calculate normals code just to make sure i am doing this right? thanks a bunch, i am just bewildered right now.