Android OpenGL-ES纹理显示乱糟糟

时间:2013-08-30 18:08:40

标签: java android opengl-es textures

我创建了一个小函数,它迭代一个字符串,并根据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 one外,它对所有测试的设备都非常适用 虽然有一个模式你会看到基本上给它的纹理坐标在某种程度上是错误的。 什么可能在一个特定的设备上导致这样的问题,特别是在使用Java工作而不是搞乱本机硬件相关的东西时?

1 个答案:

答案 0 :(得分:1)

有些Android设备只是有错误的OpenGL ES驱动程序。 HTC可能已更新可用的驱动程序。它是哪种GPU类型的?如果它在AVD仿真上正常工作,那么你的代码可能就好了。

如果您正在使用背面剔除,我也会尝试反转剔除的缠绕方向。

相关问题