我剛剛開始使用openGL我需要爲動畫加載位圖的分配我可以讓它工作很好幾幀,但是當我嘗試加載所有幀時,內存不足我怎麼才能加載一次幾幀?這是我使用加載紋理加載多個紋理openGL
public void loadGLTexture(GL10 gl, Context context) {
Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(),R.drawable.r1);
Bitmap bitmap01 = Bitmap.createScaledBitmap(bitmap, 512, 512, false);
Bitmap bitmap2 = BitmapFactory.decodeResource(context.getResources(),R.drawable.r2);
Bitmap bitmap02 = Bitmap.createScaledBitmap(bitmap2, 512, 512, false);
Bitmap bitmap3 = BitmapFactory.decodeResource(context.getResources(),R.drawable.r3);
Bitmap bitmap03 = Bitmap.createScaledBitmap(bitmap3, 512, 512, false);
try {
bitmap = bitmap01;
bitmap2 = bitmap02;
bitmap3 = bitmap03;
} finally {
}
//Generate there texture pointer
gl.glGenTextures(3, textures, 0);
//Create Texture and bind it to texture 0
gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[0]);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR);
GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);
//Create Texture and bind it to texture 1
gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[1]);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR);
GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap2, 0);
//Create Texture and bind it to texture 2
gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[2]);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR);
GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap3, 0);
//Clean up
bitmap.recycle();
bitmap2.recycle();
bitmap3.recycle();
}
}