Pro OpenGL ES for iOS

(singke) #1

152 CHAPTER 5: Textures^


has no native font support, it’s up to us, the long-suffering engineers of the world, to add
it ourselves. Sigh. This could be done by placing the characters of the desired font onto
a single mosaic texture, called a ‘‘font atlas,’’ and then selecting them by carefully using
texture coordinates.

Mipmaps


Mipmaps are a means of specifying multiple levels of detail for a given texture. That can
help in two ways: it can smooth out the appearance of a textured object as its distance
to the viewpoint varies, and it can save resource usage when textured objects are far
away.
For example, in Distant Suns, I may use a texture for Jupiter that is 1024 ̄512. But that
would be a waste of both memory and CPU if Jupiter was so far away that it was only a
few pixels across. Here is where mipmapping can come into play. So, what is a
mipmap?
From the Latin phrase ‘‘multum in parvo’’ (literally: ‘‘much in little’’), a mipmap is a family
of textures of varying levels of detail. Your root image might be 128 on a side, but when
a part of a mipmap, it would have textures that were also 64, 32, 16, 8, 4, 2, and 1 pixel
on a side, as shown in Figure 5-18.

Figure 5-18. Hedly the head, the mipmapped edition

In iOS5, switching on mipmapping is done by adding only one additional parameter to
the GLKTextureLoader:textureWithContentsOfFile() call. So swap in the options
dictionary in place of the previous one, as follows:

NSDictionary *options=[NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber
numberWithBool:YES],GLKTextureLoaderOriginBottomLeft,
[NSNumber
numberWithBool:TRUE],GLKTextureLoaderGenerateMipmaps,nil];
Free download pdf