2011-10-07 44 views
0

我正在做OpenGL-ES的第一步。 Atm我可以在方形多邊形上加載兩個POT紋理,我可以在屏幕上旋轉和縮放。如果我嘗試加載非POT PNG,那麼紋理顯示爲白色。如何將POT圖像轉換爲POT位圖以在紋理上使用OpenGL?

我需要做一些技巧來將非POT紋理轉換爲POT位圖來填充我的方形多邊形的紋理。我怎樣才能將它們轉換成POT位圖?

這是實際的代碼我必須加載紋理:

從資產DIR:

String imagePath = "radiocd5.png"; 
    AssetManager mngr = context.getAssets(); 
    // Create an input stream to read from the asset folder 
    InputStream is=null; 
    try { 
     is = mngr.open(imagePath); 
    } catch (IOException e1) { e1.printStackTrace(); } 

    //Get the texture from the Android resource directory 
    InputStream is = context.getResources().openRawResource(R.drawable.radiocd5); 
    Bitmap bitmap = BitmapFactory.decodeStream(is); 
    //Use the Android GLUtils to specify a two-dimensional texture image from our bitmap 
    GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0); 

FROM RES /繪製對象:

//Get the texture from the Android resource directory 
    InputStream is = context.getResources().openRawResource(R.drawable.radiocd5); 
    Bitmap bitmap = BitmapFactory.decodeStream(is); 
    //Use the Android GLUtils to specify a two-dimensional texture image from our bitmap 
    GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0); 
+0

關於白色的問題,你是否記得明確禁用使用非鍋紋理時的mip映射? – Tommy

回答

0

最好的辦法是重新採樣的圖像,將其設定爲2的冪(POT)。谷歌'圖像重採樣',並準備好面對一些沉重的數學;)Lanzcos重採樣http://en.wikipedia.org/wiki/Lanczos_resampling是你可能考慮的幾種方法之一。雙線性插值也很好。