2 Chapter 1 Introduction
years it has been ported to run on PCs with Direct3D, on PCs with Linux, on Macin-
toshes with OS X, and on Unix workstations that have OpenGL support. The engine
has evolved to include many more features, namely, high-level rendering effects and
shaders. I have received innumerable emails asking how to use the engine, how to ex-
tend the engine, and how to write tools for the engine. Naturally, to understand the
answers to these questions you must understand how the engine is architected. This
book is about the Wild Magic architecture, a case study for understanding the issues
of constructing an engine that you would see in a commercial environment.
The issues are many, each relatively easy to understand in isolation from the
others. However, putting all the pieces together is a formidable task to get right. But
what does “right” mean? An engine is a large library and is subject to the software
engineering principles that govern how such a large package evolves. Certainly you
(or your customers) will want to customize the engine to support new features.
But unfortunately, simplicity of maintenance does not come trivially. The various
abstract subsystems of the library must be architected so that they integrate easily
among themselves, and, as many customers of middleware have found out, they
must integrate easily with packages provided by others. Talk to any game company
that has had to combine a graphics engine, a physics engine, a networking engine,
and an AI engine together into a single game—you will hear the war stories about
the difficulties of making that happen. The promise of this book is not that you will
architect a system that will just simply plug into everyone else’s system, but rather that
you will learn how to minimize the pain of doing so. You need to ask a lot of questions
about your architecture and many times decide on various trade-offs. Sometimes you
will make a decision and go with it, only to find out later that you have to redesign
and rebuild. This is a natural part of the process for any large library construction,
but your goal is to anticipate where the problems will occur and design to facilitate
solving those problems without having to rewrite from scratch.
The next three sections present a couple of complete applications that compile
and run. The idea is to show you what systems come into play to get a working ap-
plication. The last section is a discussion of encapsulation of abstract systems whose
implementations depend on the platform (operating system, windowing system, ren-
derer creation, and use). More complicated applications show that you also need to
identify systems that allow you to factor code for reusability. Although some games
are written as throwaway code, from a company’s perspective it is better to write li-
braries that can be reused in other similar games. The last section also provides brief
descriptions of the remaining chapters in the book.
1.1 Drawing a Triangle
In this section I discuss the graphics equivalent of the “Hello, world” introductory
programming assignment—drawing a single triangle on the screen. The triangle ver-
tices are assigned colors, and the graphics system will interpolate these to create colors