0
我想在Android上傳pkm紋理。我能夠讀取圖像並獲得其寬度,高度&數據正確,但紋理顯示爲黑色。PKM紋理與ETC2壓縮給黑屏
紋理加載函數:
public static int loadCompressedTexture(final Context context, final int resourceId){
final int[] textures = new int[1];
GLES30.glGenTextures(1, textures, 0);
Log.w(TAG, "ETC1 texture support: " + ETC1Util.isETC1Supported());
if (textures[0] != 0)
{
// Read in the resource
InputStream in = context.getResources().openRawResource(R.raw.bodyf1pkm);
ETC2Utils.ETC2Texture tex = null;
try {
tex = ETC2Utils.createTexture(in);
} catch (IOException e) {
Log.e(TAG,e.toString());
}
Log.d(TAG,"tex width: "+tex.getWidth());
Log.d(TAG,"tex height: "+tex.getHeight());
// Bind to the texture in OpenGL
GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, textures[0]);
// Set filtering
GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_MIN_FILTER, GLES30.GL_NEAREST);
GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_MAG_FILTER, GLES30.GL_LINEAR);
GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_WRAP_S, GLES30.GL_REPEAT);
GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_WRAP_T, GLES30.GL_REPEAT);
// Load texture.
GLES30.glCompressedTexImage2D(GLES30.GL_TEXTURE_2D,0,tex.getCompressionFormat(),tex.getWidth(),tex.getHeight(),0,tex.getDataSize(),tex.getData());
}
return textures[0];
}
我使用的是同級拉賈瓦利的ETC2Util類(https://github.com/Rajawali/Rajawali/blob/master/rajawali/src/main/java/org/rajawali3d/materials/textures/utils/ETC2Util.java)的加載數據。 數據正在正確加載,但紋理變黑。誰能幫忙?