Mode 7 and You
Sin & Cos: The Programmer’s Pals! is probably the most straight forward example of Mode 7 implemented in a C like language available. You may be wondering what Mode 7 is.
F-Zero and Mario Kart for the SNES made use of Mode 7 and it has been used in quite a few games since. Mode 7 is a term to describe the ability to scale and rotate a texture. It simply translates the height of a texture into the depth.
Not so surprisingly you will find that the equations used to render Mode 7 are essentially identical to the equations used to render the ceilings and floors in Bunnies. Mode 7 is Bunnies without the walls.
The above link provides the basic rendering function but gets the key part of the equation wrong. Fortunately, Bunnies gets it right so I just used the equation from Bunnies.
WRONG:
distance = camera.z * scale_y / (screen_y + horizon);
CORRECT:
distance = camera.z * scale_y / (2.0 * screen_y - horizon);
I’ve started translating the old SoftGel C++ code to C# and this Mode 7 stuff is going to be the first to make use of the new library. I’m going to try to find time to start writing more tutorials. Bunnies is pretty advanced at this point and so I think I’ll begin developing a simple racing game and writing tutorials to explain how it all works. Eventually I may work the tutorials back to Bunnies.
You may be wondering what the point is with OpenGL and DirectX available. There are a number of reasons. The main one is that I’ve been there and done that with OpenGL and DirectX. I want to learn the math behind the rendering. The second reason is that most of the work that goes into making a game has nothing to do with rendering graphics. And also, you’ll find many of the same concepts that are used to render graphics are also used to implement game mechanics.
And finally, software rendering works on any platform that can plot a pixel. Not all gaming systems have 3D capabilities. If you can figure out the 3D stuff in software you’ll have no trouble doing it in DirectX or OpenGL.

Leave a comment
You must be logged in to post a comment.