Skybox demo program

hplus dash gl at mindcontrol dot org
2003-01-21

Download (1 MB): skybox-030121.zip

Yet another OpenGL.org FAQ that I finally decided to answer with some sample code on the web.

To start the demo, run the "skybox.exe" program from the command line, inside this directory. Pass the "-w" option if you want to run it in a window. Use arrow keys to scroll, and escape (or 'q') to quit.

This program shows how to draw a sky box with no seaming in the textures, using GL_CLAMP_TO_EDGE. The textures are generated with just over 90 degree field of view (I'm using the Persistence of Vision ray tracer) and drawn on a cube that's centered around the camera. You can use Bryce, or 3ds Max, or whatever you want to generate these textures, as long as you can set up a camera that generates a square texture that's a hairs-edge wider than 90 degrees FOV (to compensate for the fact that we clamp to the center of the outermost pixels).

If your graphics card supports border texels (which the GeForce 2 does not) you can load the neighboring texture edges into the borders of each texture, and get away with an exact 90 degree FOV when rendering the textures, and also use CLAMP or CLAMP_TO_BORDER to get rid of the final (very small) artifact.

Please pay no attention to the gross over-engineering of the GL state wrapping that happens in this sample; it's cut down from another test program I had going at the time. All the good stuff happens in main.cpp, and the Skybox class is at the head of the file to make it easy to find. Put a break- point in Skybox::draw() and trace through what it's doing, and you should be going in no time.

This code builds on Windows XP using MSVC version 7; you may be able to get it to build on Linux or other platforms with relative ease, because it's using GLUT (DLL for Windows is included) but I haven't done so, so it probably won't compile out of the box.

sky box screen shot
Screen shot. Can you spot the seams?