James Bowman


OpenGL lets you specify arbitrary colors for lights. So it's perfectly possible to give lights a negative color, so they make the subject darker.

This example uses a single positive point light, and several dark spot lights to give the effect of shadows. The cube is highly tesselated so that the edges of the spotlights show up nicely.

The spheres also shadow each other: you'll see mini-eclipses happen from time to time. The example does this by drawing the spheres in order from nearest to furthest, and switching on each sphere's darklights after the sphere has been drawn.

What the example doesn't do is attempt to vary the size of the shadow according to the distance of the sphere from the light. It should be an easy matter to do this by tweaking the spotlight parameters.

The motion of the lights and sphere is the same the flies, and the cube's motion is the same as stars.

Pressing 'c' toggles motion of the cube; 's' toggles motion of the spheres, and 'l' toggles motion of the light.

darkspot.c source (distributed under the terms of the GNU General Public License).

(If you want to compile it, you'll also need GLUT).