我制作了一个小函数,它迭代字符串并根据 256x256 字体纹理中每个字符的坐标将新的纹理坐标放入缓冲区中,这样我就可以使用 OpenGL 顶点数组渲染文本。
private void updateTexCoords()
{
float unit = 0.0625f;
byte[] arr = string.getBytes();
for(int i = 0; i < string.length()*8; i += 8)
{
float x = (float)(((int)arr[i/8] & 0xff)%16)*unit;
float y = (float)(((int)arr[i/8] & 0xff)/16)*unit;
//axis center is at (0,1) pointing right, down
texture[0+i] = x; texture[1+i] = y+unit; //bottom left
texture[2+i] = x; texture[3+i] = y; //top left
texture[4+i] = x+unit; texture[5+i] = y+unit; //bottom right
texture[6+i] = x+unit; texture[7+i] = y; //top right
}
ByteBuffer byteBuffer = ByteBuffer.allocateDirect(texture.length * 4);
byteBuffer.order(ByteOrder.nativeOrder());
textureBuffer = byteBuffer.asFloatBuffer();
textureBuffer.put(texture);
textureBuffer.position(0);
}
它在所有测试的设备上都表现出色,除了一部旧手机,HTC Nexus 1, 尽管有一个图案,但它显示困惑的符号,并且您会发现基本上赋予它的纹理坐标在某种程度上是错误的。 什么可能会在一台特定设备上导致这样的问题,尤其是在使用 Java 工作并且不干扰 native 硬件相关的事情时?
最佳答案
某些 Android 设备只是存在有缺陷的 OpenGL ES 驱动程序。 HTC 可能有可用的更新驱动程序。它是哪种 GPU 类型?如果它在 AVD 仿真上正常工作,那么您的代码可能没问题。
如果您使用背面剔除,我也会尝试反转被剔除的缠绕方向。
关于java - Android OpenGL-ES 纹理显示困惑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18539015/