[英]OpenGL ES: Drawing using a Texture Atlas
I'm trying to develop an Android 2D game using OpenGL ES that uses a tiled map, and I heard that it's best to store the tiles in a texture atlas (one large bitmap with multiple tiles) for performance reasons. 我正在尝试使用使用平铺地图的OpenGL ES开发Android 2D游戏,并且听说出于性能方面的考虑,最好将平铺存储在纹理地图集中(一个带有多个平铺的大位图)。
Does anyone have some sample code that demonstrates how to draw a tile from a texture atlas in Android OpenGL ES? 是否有人提供示例代码来演示如何在Android OpenGL ES中从纹理图集绘制图块?
onDrawFrame(GL10 gl) {
...
}
Well I figured out how to do it. 好吧,我想出了怎么做。
onDrawFrame(GL10 gl) {
...
int[] crop = new int[4];
crop[0] = tileWidth * tileIndex; // tileIndex represents the nth tile in the texture atlas
crop[1] = tileHeight;
crop[2] = tileWidth;
crop[3] = -tileHeight;
// specify the source rectangle
((GL11) gl).glTexParameteriv(GL10.GL_TEXTURE_2D, GL11Ext.GL_TEXTURE_CROP_RECT_OES, crop, 0);
// draw the texture
((GL11Ext)gl).glDrawTexiOES(x, y, 0, tileWidth, tileHeight);
...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.