SimpleLight is sample C code illustrating the use of OpenGL. It
is intended to accompany the book 3D Computer Graphics: A mathematical
approach with OpenGL, by Samuel R. Buss, Cambridge University Press, 2003.
However, it can be used independently as well.
SimpleLight illustrates the use Phong lighting in OpenGL. It
draws six spheres of different colors, and makes a white light revolve around the
spheres. It consists of two source files, SimpleLight.c and SimpleLight.h.
There are several options available for downloading this program:
Things to notice:
- Compile and run the program. Try out the keyboard controls. Pressing
"r" starts and stops the animation. Pressing "s" performs single
steps of the animation. The up and down arrows control the speed of the
rotation. Pressing "l" (for local) switches between a positional light and
a directional light.
- Note the specular hightlights.
- Note how the diffuse illumination is brightest facing the light, and dims quickly as the
surface normals move away from facing the light source.
- Note how the bright center of diffuse illumination is not at the same position as the
specular hightlight. What is this?
- Note that there is some ambient light (both global ambient light and anbient light from
light #0). For this reason, the sides of the spheres facing away the light source
are not completely dark.
- Note how the specular highlights change position when the light switches between
directional and positional. Note how the diffuse lighting changes when the light
switch is made. Explain qualitatively why you see the changes you do.
- The six spheres and the light are all in the same plane (the xy-plane). Why don't
the spheres cast shadows on each other?
- Note how the program used emissive properties to make the light glow white.
However the fact that the white sphere is visible is independent of the fact that the
light is active and shining.