2013-08-30 208 views
0

我做了一个小函数,它遍历一个字符串,并根据每个字符在256x256字体纹理中的坐标将新的纹理坐标放入缓冲区,所以我可以渲染文本OpenGL顶点数组。Android OpenGL-ES纹理显示为乱码

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

一些Android设备只是有错误的OpenGL ES驱动程序。 HTC可能已经更新了驱动程序。哪种GPU类型?如果它在AVD模拟上正常工作,那么你的代码可能没问题。

如果你正在使用背面剔除,我也会尝试颠倒被剔除的卷绕方向。

+0

除文字以外的所有图像均正确显示。即使是那些有自定义纹理坐标(不是标准的0f和1f)。 –