Game Development Reference
In-Depth Information
setFilters(GL10. GL_NEAREST , GL10. GL_NEAREST );
gl.glBindTexture(GL10. GL_TEXTURE_2D , 0);
width = bitmap.getWidth();
height = bitmap.getHeight();
bitmap.recycle();
}
} catch (IOException e) {
throw new RuntimeException("Couldn't load texture '" + fileName
+ "'", e);
} finally {
if (in != null )
try {
in.close();
} catch (IOException e) {
}
}
}
The load() method stays essentially the same as well. The only addition is the call to
createMipmaps() in case the texture should be mipmapped. Non-mipmapped Texture instances
are created as before.
private void createMipmaps(GL10 gl, Bitmap bitmap) {
gl.glBindTexture(GL10. GL_TEXTURE_2D , textureId);
width = bitmap.getWidth();
height = bitmap.getHeight();
setFilters(GL10. GL_LINEAR_MIPMAP_NEAREST , GL10. GL_LINEAR );
int level = 0;
int newWidth = width;
int newHeight = height;
while ( true ) {
GLUtils. texImage2D (GL10. GL_TEXTURE_2D , level, bitmap, 0);
newWidth = newWidth / 2;
newHeight = newHeight / 2;
if (newWidth <= 0)
break ;
Bitmap newBitmap = Bitmap. createBitmap (newWidth, newHeight,
bitmap.getConfig());
Canvas canvas = new Canvas(newBitmap);
canvas.drawBitmap(bitmap,
new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()),
new Rect(0, 0, newWidth, newHeight), null );
bitmap.recycle();
bitmap = newBitmap;
level++;
}
Search WWH ::




Custom Search