2
我知道有CompressedTextureActivity的例子,我基於我的代碼,但我無法做到這一點。 孤男寡女我們有所幫助:在Android中加載壓縮紋理ETC1
public static int loadCompressedTexture(final Context context, final int resourceId){
final int[] textureHandle = new int[1];
GLES20.glGenTextures(1, textureHandle, 0);
if (textureHandle[0] != 0){
InputStream input = context.getResources().openRawResource(resourceId);
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureHandle[0]);
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST);
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
try{
ETC1Util.loadTexture(GLES20.GL_TEXTURE_2D, 0, 0,GLES20.GL_RGB, GLES20.GL_UNSIGNED_SHORT_5_6_5, input);
}
catch(IOException e){
System.out.println("DEBUG! IOException"+e.getMessage());
}
finally{
try {
input.close();
} catch (IOException e) {
// ignore exception thrown from close.
}
}
//GLES20.glGenerateMipmap(GLES20.GL_TEXTURE_2D);
checkGlError("");
}
else
throw new RuntimeException("Error loading texture.");
return textureHandle[0];
}
loadTexture拋出IOException異常,其結果是黑...
更新:我有沒有頭PKM文件。出於某種原因,我認爲它們應該以這種方式進行編碼,但是現在我使用標頭對它們進行了編碼,並且不再發生IOException錯誤。順便說一下,我使用etc1tool,並且源png文件是2048x2048。
不過,我不斷收到黑暗......
順便說一句,這是我用來加載紋理正常,這顯示就好代碼:
public static int loadTexture(final Context context, final int resourceId)
{
final int[] textureHandle = new int[1];
GLES20.glGenTextures(1, textureHandle, 0);
if (textureHandle[0] != 0)
{
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inScaled = false; // No pre-scaling
final Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), resourceId, options);
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureHandle[0]);
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR_MIPMAP_NEAREST);
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0);
GLES20.glGenerateMipmap(GLES20.GL_TEXTURE_2D);
logHeap();
bitmap.recycle();
}
if (textureHandle[0] == 0)
{
throw new RuntimeException("Error loading texture.");
}
return textureHandle[0];
}
而不是隻是在出現異常時打印「錯誤」,爲什麼不嘗試打印'e.getMessage()'?它可能有更多的信息。 – Tim
當然,杜......將更新與更多信息的問題。 – jmacedo
您的代碼目前是否適用於非ETC紋理? – Tim