gpt4 book ai didi

java - OpenGL ES : Drawing using a Texture Atlas

转载 作者:行者123 更新时间:2023-11-30 04:32:29 25 4
gpt4 key购买 nike

我正在尝试使用 OpenGL ES 开发一款使用分块贴图的 Android 2D 游戏,我听说出于性能原因,最好将分块存储在纹理图集(一个包含多个分块的大位图)中。

有没有人有一些示例代码来演示如何在 Android OpenGL ES 中从纹理图集绘制图 block ?

onDrawFrame(GL10 gl) {
...
}

最佳答案

好吧,我想出了办法。

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);

...
}

关于java - OpenGL ES : Drawing using a Texture Atlas,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7459053/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com