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而不干擾與本機硬件相關的事情時?
除文字以外的所有圖像均正確顯示。即使是那些有自定義紋理座標(不是標準的0f和1f)。 –