Game Development Reference
In-Depth Information
Figure 8-24. Beautifying the cannon example with a texture atlas
There are a few more things you need to know about texture atlases:
GL_LINEAR as the minification and/or magnification filter, there
might be artifacts when two images within the atlas are touching each other.
This is due to the texture mapper actually fetching the four nearest texels
from a texture for a pixel on the screen. When it does that for the border
of an image, it also fetches texels from the neighboring image in the atlas.
You can eliminate this problem by introducing an empty border of 2 pixels
between your images. Even better, you can duplicate the border pixel of
each image. The first solution is easier—just make sure your texture stays a
power of two.
ï?®
When you use
ï?®
There's no need to lay out all the images in the atlas in a fixed grid. You
could put arbitrarily sized images in the atlas as tightly as possible. All you
need to know is where an image starts and ends in the atlas, so that you can
calculate proper texture coordinates for it. Packing arbitrarily sized images
is a nontrivial problem, however. There are a couple of tools on the Web that
can help you with creating a texture atlas; just do a search and you'll be hit
with a plethora of options.
ï?®
Often you cannot group all the images of your game into a single texture.
Remember that there's a maximum texture size that varies from device to
device. You can safely assume that all devices support a texture size of
512×512 pixels (or even 1024×1024). So, you can just have multiple texture
atlases. You should try to group into one atlas objects that will be seen on
the screen together, though—say, all the objects of level 1 in one atlas, all
the objects of level 2 in another, all the UI elements in another, and so on.
Think about the logical grouping before finalizing your art assets.
ï?®
Remember how we drew numbers dynamically in Mr. Nom? We used a
texture atlas for that. In fact, e can perform all dynamic text rendering via a
texture atlas. Just put all the characters you need for your game into an atlas
and render them on demand, via mapping a rectangles to the appropriate
characters in the atlas. There are tools you can find on the Web that will
generate a bitmap font for you. For purposes of the upcoming chapters, we
 
Search WWH ::




Custom Search