-
OpenGL graphics
Hi,
I'm having trouble getting around what everything means in the lighting and section of OpenGL. I have managed to get lighting working, but whatever i try for shading doesn't work. I've been working of tutorials but can't make much sense of it. If anybody could help me understand whats going on and how to get shading working would be great. Ive got comments on my code which is as far as i understand.
Code:
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);
glShadeModel(GL_SMOOTH);
glEnable(GL_DEPTH_TEST); // Enabling depth test
glEnable(GL_COLOR_MATERIAL); // Allows colored materials to be affected by the light
glEnable(GL_LIGHTING); // Enable lighting
glEnable(GL_LIGHT0); // Enable 1st light, possible 8 - max
glLightfv(GL_LIGHT0, GL_POSITION, LightPos); // set light position
glLightfv(GL_LIGHT0, GL_DIFFUSE, LightColor); // setting diffuse colour
glLightfv(GL_LIGHT0, GL_SPECULAR, LightColor); // setting specular colour
// At this point, control is relinquished to the GLUT event handler.
glutMainLoop(); // Control is returned as events occur, via the callback functions.
}
thanks
-
What exactly do you mean by "shading"? Shadows? Or just the dark parts that face away from the light?
If the latter, you might want to try setting the ambient lighting term, like this:
Code:
float lightAmbient[4] = {0.1f, 0.1f, 0.1f, 1.0f};
glLightfv(GL_LIGHT0, GL_AMBIENT, lightAmbient);
-
You need to specify a normal at each vertex, if I understand what you are asking for. I believe you mean Goraud shading. Note that this only produces reasonably good results for densely tesselated models (each polygon is small), because it interpolates the value of the normal across the face (meaning as you get towards the center of a large polygon you will notice the effects of the averaged normals).
If you simply meant for coloring, you need to enable smooth shading and supply a different color per vertex.
EDIT:
Also, what the hell is a 'draught?'
-
lol, checkers?? we call it draughts... well 'they'..... i just want simple shadows so you can tell its 3D, from far, atm sometimes it looks 2.
-
I tried what psychopath suggested, but no luck. I didnt make up my shapes of polygons, i'm not on that level, i simply stuck together 2D shapes to make 3D shapes. I just want simple shadows now, so it adds to the realism. My light is shining from the top, and when you move the camera through it to the bottom side, it is dark. Maybe my positionbing of my light is incorrent??
Code:
const GLfloat LightPos[] = { 0.0, 0.0, 1.0, 0.0 };
const GLfloat LightColor[] = { 1.0f, 1.0f,1.0f, 1.0f };
-
There is no integrated support for shadows in OpenGL. You need to do the calculations yourself.
For something simple like checkers, you could just render a simple dark circle under each piece offset by a constant factor.
-
i see, what about shading on the peices ??