/* This is a function which initializes lighting in an OpenGL program. I can be called from an init function which also sets up projection, depth buffering, etc. For lighting to work properly there should be a normal vector supplied for every vertex. */ void initLighting(void) { GLfloat mat_properties[] = {0.5, 0.5, 0.5, 1.0}; GLfloat white_light[] = {1.0, 1.0, 1.0, 1.0}; GLfloat light_position[] = {1.0, 1.0, 2.0, 0.0 }; glShadeModel(GL_SMOOTH); glLightfv(GL_LIGHT0, GL_POSITION, light_position); glLightfv(GL_LIGHT0, GL_DIFFUSE, white_light); glLightfv(GL_LIGHT0, GL_AMBIENT, white_light); /* object color determined here */ glMaterialfv(GL_FRONT, GL_AMBIENT, mat_properties); glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_properties); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); }