2013-08-30 120 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)。 –