-
OpenGL lighting
Hey peeps,
I have tried to make my game have simple lighting which i have seen on many tutorials on the web. However, i cant get mine to have the same effect, and i cant work out why. All i want is shininess to be in effect, which i have seen on many screen shots, and also makes the other half of the shape to be darker (shading?), i will show my environment setup:
Code:
const GLfloat shininess [] = { 100.0 };
const GLfloat specular [] = { 1.0, 1.0, 1.0, 1.0 };
const GLfloat LightPos[] = { 1.0, 1.0, 1.0, 0.0 };
void glutInit(int argc, char ** argv)
{
// Setup the basic GLUT stuff
glutInit(&argc, argv); // initialises environment
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); // uses a double buffer - colour mode -
// Create the window
glutInitWindowSize(200, 200); // creates the window size
glutInitWindowPosition(100, 150); // position of the window on the screen
glutCreateWindow("3D Draughts");
// Register the event callback functions
glutDisplayFunc(Display); // called everytime it needs to refresh the display
glutIdleFunc(idle); // called when it isnt doing anything
glutKeyboardFunc(KeyboardHandler); // picks up keyboard strokes
glutSpecialFunc(SpecKeyHandler);
glutMouseFunc(processMouse); // mouse movement and clicks
glutMotionFunc(processMouseActiveMotion);
glutReshapeFunc(Reshape); // called everytime it needs to reshape something
orientMe();
glClearDepth(1.0f);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glClearColor(0.0, 0.0, 0.0, 0.0);
glShadeModel(GL_SMOOTH);
glEnable(GL_DEPTH_TEST); // Enabling depth test
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specular);
glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, shininess);
glLightfv(GL_LIGHT0, GL_POSITION, LightPos);
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
glEnable(GL_COLOR_MATERIAL);
glLightfv(GL_LIGHT0, GL_POSITION, LightPos);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0); // Enable lighting
// At this point, control is relinquished to the GLUT event handler.
glutMainLoop(); // Control is returned as events occur, via the callback functions.
}
If anybody could help, it would be a GREAT help, thank you very much.
-
You didn't draw an object. glColorMaterial sets the lighting attributes for an object drawn thereafter.
Though I'm not sure, but you should enable before using them. Enable light0 then set its attributes, same with colormaterial. I think it makes it easier to keep track of.
-
Hey,
Ive created a game, and call draw() in my game.cpp, but i added draw() to my environment setup as well, it doesn't do anything?? maybe i should delete the draw() from my game.cpp??
Thanks.
-
glutDisplayFunc() looks like it calls Display() in your code, but you say your draw function is draw() ? The display function should be the one calling your rendering code. And why would you call the rendering function on the environment setup?
-
sorry, ignore what i said before, you are right, it is the way you said it. I just don't understand why the shininess is not affecting the board and draughts on my game. Is their anything wrong with the setup??
-
Try calling this:
Code:
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specular);
glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, shininess);
In the rendering code, and not the setup code. Not sure if it'll matter in your case though. You also may want to try setting the specular componant of the light, like this:
Code:
glLightfv(GL_LIGHT0, GL_SPECULAR, youSpecularColour);
Can't remember for sure if that's required for the specular of the material to take effect or not. It's been a while since I've used standard OpenGL lighting.
-
no luck :-( it just stays the same....