Game Development Reference
In-Depth Information
Figure 7-26. A hundred Bobs scaled, rotated, and translated (in that order) to their positions in world space
It's easy to mix up the order of these matrix operations when you first start out with OpenGL on
the desktop. To remember how to do it correctly, use the mnemonic device called the LASFIA
principle: last specified, first applied. (Yeah, this mnemonic isn't all that great, huh?)
The easiest way to get comfortable with model-view transformations is to use them heavily. We
suggest you take the BobTest.java source file, modify the inner loop for some time, and observe
the effects. Note that you can specify as many transformations as you want for rendering each
model. Add more rotations, translations, and scaling. Go crazy.
With this last example, we basically know everything we need to know about OpenGL ES to
write 2D games . . . or do we?
Optimizing for Performance
When we run this example on a beefy second-generation device like a Droid or a Nexus One,
everything will run as smooth as silk. If we run it on a Hero, everything will start to stutter and
look pretty unpleasant. But hey, didn't we say that OpenGL ES was the silver bullet for fast
graphics rendering? Well, it is, but only if we do things the way OpenGL ES wants us to do them.
Measuring Frame Rate
BobTest provides a perfect example to start with some optimizations. Before we can do that,
though, we need a way to assess performance. Manual visual inspection (“doh, it looks like it
stutters a little�) is not precise enough. A better way to measure how fast our program performs
is to count the number of frames we render per second. In Chapter 3 we talked about something
called the vertical synchronization, or vsync for short. This is enabled on all Android devices that
 
Search WWH ::




Custom Search