Game Development Reference
In-Depth Information
We won't go into the details of why aliasing happens; all you need to know is how to make
objects look better. That's where mipmapping comes in.
The key to fixing aliasing problems is to use lower-resolution images for parts of an object
that are smaller on screen or further away from the view point. This is usually called a mipmap
pyramid or chain . Given an image in its default resolution, say 256×256 pixels, we create smaller
versions of it, dividing the sides by two for each level of the mipmap pyramid. Figure 11-9 shows
the crate texture with various mipmap levels.
Figure 11-9. A mipmap chain
To make a texture mipmapped in OpenGL ES, we have to do two things:
Set the minification filter to one of the
GL_XXX_MIPMAP_XXX constants, usually
ï?®
GL_LINEAR_MIPMAP_NEAREST .
Create the images for each mipmap chain level by resizing the original
ï?®
image and upload them to OpenGL ES. The mipmap chain is attached to a
single texture, not multiple textures.
To resize the base image for the mipmap chain, we can simply use the Bitmap and Canvas
classes that the Android API provides. Let's modify the Texture class a little. Listing 11-8 shows
the code.
Listing 11-8. Texture.java, Our Final Version of the Texture Class
package com.badlogic.androidgames.framework.gl;
import java.io.IOException;
import java.io.InputStream;
import javax.microedition.khronos.opengles.GL10;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
 
Search WWH ::




Custom Search