作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 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/
我是一名优秀的程序员,十分优秀!