Three blisteringly fast classes for rendering sky textures in 3D games: sphere, cube and dome
A very large percentage of games use textures to fake 'stuff' on or over the horizon. Distant mountains, buildings, clouds, hills, stars, nebula, sun, moon, etc, can all be painted into textures rather than rendered with actual geometry.
However, there are several geometries and mapping methods that can be used, each with their own advantages and disadvantages. This application showcases 3 types of environment geometry: sphere, cube and dome. Which one you choose depends on your requirements and how it will be used:
They all use vertex buffer objects and triangle strips for greatest speed. The code is clear, concise and optimized.
TIP: It is SOMETIMES a good idea to render your sky last. This is because the other geometry will have written to the depth buffer, and a large portion of the sky pixels will fail the z test and never be drawn. If you render the sky first, they will be drawn unnecessarily. Of course, this only works if you have no transparency in the scene.
Note: The example program uses freeglut for window creation but the Sky Geometry components themselves do not, so they are very portable.
How to use in your own application:
Create one of the objects:
SkySphere* _skysphere; _skysphere = new SkySphere( SCALE, SLICES, STACKS, TEXTURE_HANDLE);
SCALE is the radius of the sky sphere SLICES and STACKS are the number of horizontal and vertical tesslation divisions TEXTURE_HANDLE is an opengl handle to a texture. Included is a function for reading TGA images but you'll probably want something better
Every frame simply use:
And finally, at the end, remember to clean up after yourself: