Game Development Reference
In-Depth Information
Of course, our new bindable Vertices class has a few restrictions now:
We can only set the vertex and index data when the
Vertices instance is not
bound, as the upload of that information is performed in Vertices.bind() .
We can't bind two
ï?®
Vertices instances at once. This means that we can only
render with a single Vertices instance at any point in time. That's usually not
a big problem though, and given the impressive increase in performance, we
will live with it.
ï?®
In Closing
There's one more optimization we can apply that is suited for 2D graphics programming with
flat geometry, such as with rectangles. We'll look into that in the next chapter. The keyword to
search for is batching , which means reducing the number of glDrawElements() / glDrawArrays()
calls. An equivalent for 3D graphics exists as well, called instancing , but that's not possible with
OpenGL ES 1.x.
We want to mention two more things before we close this chapter. First of all, when you
run either BobTest or OptimizedBobTest (which contains the super-optimized code we just
developed), notice that the Bobs wobble around the screen somewhat. This is due to the fact
that their positions are passed to glTranslatef() as floats. The problem with pixel-perfect
rendering is that OpenGL ES is really sensitive to vertex positions with fractional parts in their
coordinates. We can't really work around this problem; the effect will be less pronounced or even
nonexistent in a real game, as we'll see when we implement our next game. We can hide the
effect to some extent by using a more diverse background, among other things.
The second thing we want to point out is how we interpret the FPS measurements. As you can
see from the preceding output, the FPS fluctuates a little. This can be attributed to background
processes that run alongside our application. We will never have all of the system resources for
our game, so we have to learn to live with this issue. When you are optimizing your program,
don't fake the environment by killing all background processes. Run the application on a phone
that is in a normal state, as you'd use it yourself. This will reflect the same experience that a user
will have.
Our nice achievement concludes this chapter. As a word of warning, only start optimizing your
rendering code after you have it working, and only then after you actually have a performance
problem. Premature optimization is often a cause for having to rewrite your entire rendering
code, as it may become unmaintainable.
Summary
OpenGL ES is a huge beast. We managed to boil all that down to a size that makes it easily
usable for our game programming needs. We discussed what OpenGL ES is (a lean, mean
triangle-rendering machine) and how it works. We then explored how to make use of OpenGL
ES functionality by specifying vertices, creating textures, and using states (such as blending)
for some nice effects. We also looked a little bit into projections and how they are connected
to matrices. While we didn't discuss what a matrix does internally, we explored how to use
 
Search WWH ::




Custom Search