macdevcenter.com
oreilly.comSafari Books Online.Conferences.

advertisement

AddThis Social Bookmark Button

Build a Simple 3D Pipeline in Tcl

by Michael J. Norton
08/12/2005

As a kid, did you ever take something apart just to see how it worked? I still remember taking apart my old Apple ][ just to see if I could get it back together. The integrated circuits sat on sockets, so you could easily pry them off with a small screw driver. It was an interesting exercise in seeing how computer hardware functions.

It's been several decades since I last dismantled an Apple ][, but I still find myself taking things apart just to satisfy my curiosity. I don't take apart computers that much anymore. I mean, where's the fun in taking apart a laptop? Eeek!

My interest has shifted to old game software autopsies. Old popular video game source code can be found everywhere on the net. Not only that, but game console development environments are becoming available to the hobbyist. Development environments exist on Linux for the GameCube (see also Linux on the GameCube, the Sony PlayStation 2, and the old Sega Dreamcast console). These game console platforms have some interesting homebrewed 3D demos for them on the internet. These incredible hobbyist efforts sparked my interest in reverse engineering 3D graphics for the game console environment. In some cases, excluding the PlayStation 2, the Linux environments don't support the OpenGL API. Which means coding 3D from scratch is necessary.

Related Reading

Game Design Complete
By Patrick O'Luanaigh

Do you need any of these development environments to experiment with game console 3D programming? Certainly not. I am surrounded by computers at work and at home; Macintosh, PC, Sun, and SGI. Despite the differences in hardware and software on all of these systems, they all have a nice little scripting language, Tcl, which is more than capable of stepping up to the task. Using Tcl, you can literally prototype algorithms in the interpreter much in the same way you would prototype an electronics circuit on an experimenter's breadboard. In our case, we're going to assemble a game console to experiment with using Tcl. Pretty cool, huh?

Simple 3D Pipeline

Sometimes the internet can be overwhelming in information. My initial Googling for 3D game and programming graphics yielded a lot of pages that were, in a nutshell, a re-hash of college students' lectures in linear algebra and vectors, typically followed with an object-oriented coding example of a spinning cube with light sources. Have fun dissecting that code!

Relying on my ancient knowledge of 3D computer graphics, which is in an eroding data buffer in my mind, I recollected the basics of the 3D graphics pipeline. Why is this information important? Understanding the linear algebra involved is one thing; the order of implementation of the matrices is the other half of the equation. Most website tutorials make you dig this out of the complex source code that accompanies the lengthy discourse on linear algebra. As the physicist Richard Feynman used to say, Q.E.D., right? In my earlier years of college I would have prided myself in deriving the solution. Fast forward 20 years later, and my attitude has shifted to "just show me the solution." Let's take a look at a solution to a simple 3D graphics pipeline.

World Coordinates

The object we're going to render exists in a fictitious 3D world. Objects in our world are mapped to x, y, and z coordinates. For simplicity, we're going to render a polygon to our Tcl game console. The three vertices of the polygon are defined in world coordinates as follows:

set vertex_list { \ 
    {0.57735026919 0.57735026919 0.57735026919} \ 
    {0.57735026919 -0.57735026919 -0.57735026919} \ 
    {-0.57735026919 -0.57735026919 0.57735026919} }  
 

Our polygon is a triangle, which is one face of a tetrahedron, a three-sided pyramid. We're only going to render one face, as shown in Figure 1, to keep it simple.

figure 1
Figure 1. Wish output display of polygon

Pages: 1, 2, 3

Next Pagearrow