Sign in to follow this  

lighting question

This topic is 3342 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Basically I have made a game and loaded in md2 models (with normals) that i can move about in the scene however ive noticed the lighting effect on them does not change all the shading stays the same regardless to the direction i turn the models to. Could this be to do with the fact all my lighting is contained in the init function and is only called once so is sets up all the shading on the model once? how would i do it so that the lighting updates when i move my model? is it common to call the init from the display to update the lighting?

Share this post


Link to post
Share on other sites


void init()
{
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
glEnable(GL_NORMALIZE);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

//Light 0 Properties/Position
GLfloat ambientLight[]={0.9,0.9,0.9,1.0};
GLfloat diffuseLight[]={0.3,0.3,0.3,1.0};
GLfloat specularLight[]={0.2,0.2,0.2,1.0};


glLightfv(GL_LIGHT0, GL_AMBIENT, ambientLight);
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseLight);
glLightfv(GL_LIGHT0, GL_SPECULAR, specularLight);
glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);

glEnable(GL_LIGHT0);

loadTexture();
}


void display (void)
{
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadMatrixf(cameraMatrix);
glEnable(GL_TEXTURE_2D);

//Draw everything

glEnd();
glFlush();
glutSwapBuffers();
}



thats my code. If i call the init in the display it updates the lighting on all the stuff drawn in the display but this isnt common?

Share this post


Link to post
Share on other sites

This topic is 3342 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this