【发布时间】:2012-03-28 13:39:14
【问题描述】:
我在使用纹理图集在 OpenGL 中对对象进行纹理处理时遇到问题,我正在创建一个 2d 游戏,并且我知道如何将 POT 位图纹理化为对象,但我似乎找不到转换教程出于性能原因,我的代码使用纹理图集,这是我当前工作对象创建和纹理实现的代码。
public void createTexture(Bitmap bmp, GL10 gls, int texturename)
{
this.gl = (GL11) gls;
this.TextureName = texturename;
bombBmp = bmp;
VertexBuffer = null;
TextureBuffer = null;
IndexBuffer = null;
ByteBuffer byteBuffer = ByteBuffer.allocateDirect(12 * 4);
byteBuffer.order(ByteOrder.nativeOrder());
VertexBuffer = byteBuffer.asFloatBuffer();
VertexBuffer.put(new float[] { 0, 0, 0.0f, 0, -h, 0.0f, w, 0, 0.0f, w, -h, 0.0f });
VertexBuffer.position(0);
byteBuffer = ByteBuffer.allocateDirect(8 * 4);
byteBuffer.order(ByteOrder.nativeOrder());
TextureBuffer = byteBuffer.asFloatBuffer();
TextureBuffer.put(new float[] { 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f });
TextureBuffer.position(0);
byteBuffer = ByteBuffer.allocateDirect(6 * 2);
byteBuffer.order(ByteOrder.nativeOrder());
IndexBuffer = byteBuffer.asShortBuffer();
IndexBuffer.put(new short[] { 0, 1, 2, 1, 3, 2 });
IndexBuffer.position(0);
gl.glBindTexture(GL10.GL_TEXTURE_2D, this.TextureName);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_CLAMP_TO_EDGE);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_CLAMP_TO_EDGE);
GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bombBmp, 0);
bombBmp.recycle();
bombBmp = null;
}
我从 genTexture 生成我的 Texturename 并将 POT 位图传递给这个函数
gl.glGenTextures(1, textures, 0);
bomb.createTexture(bombBmp, gl, textures[0]);
这是我假设的纹理位图
【问题讨论】:
-
纹理图集具体有什么不明白的地方?你知道纹理坐标是如何工作的吗?我认为没有人会为您重写您的代码,但如果有一些您不理解的特定概念,您可能会找到一些帮助。
-
我不知道如何从纹理图集中绑定子图像,我只知道如何将图像作为一个整体进行绑定,例如,我必须先使用texImage2d然后使用texSubImage吗?还是我必须立即使用 texSubImage?谢谢
-
你是如何解决这个问题的?
标签: android opengl-es textures