DannyG
12-06-2010, 09:40 AM
Hi,
for an Android OpenGL app I have some quads which are textured based on a user configuration. If the configuration changes, the textures need to change accordingly. I wrote a function to load these:
private void loadTextures(Bitmap[] resources) {
mGL.glDeleteTextures(mTextures.length, mTextures, 0);
mTextures = new int[resources.length];
mGL.glGenTextures(resources.length, mTextures, 0);
Matrix flip = new Matrix();
flip.postScale(1f, -1f);
for(int i = 0; i<resources.length; i++){
Bitmap bmp = Bitmap.createBitmap(resources[i], 0, 0, resources[i].getWidth(), resources[i].getHeight(), flip, true);
resources[i].recycle();
mGL.glBindTexture(GL10.GL_TEXTURE_2D, mTextures[i]);
mGL.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR);
mGL.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);
mGL.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_REPEAT);
mGL.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_REPEAT);
GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bmp, 0);
bmp.recycle();
}
}
The first time, the textures load fine, but a second call to it turns the screen white.
Am I overlooking something?
for an Android OpenGL app I have some quads which are textured based on a user configuration. If the configuration changes, the textures need to change accordingly. I wrote a function to load these:
private void loadTextures(Bitmap[] resources) {
mGL.glDeleteTextures(mTextures.length, mTextures, 0);
mTextures = new int[resources.length];
mGL.glGenTextures(resources.length, mTextures, 0);
Matrix flip = new Matrix();
flip.postScale(1f, -1f);
for(int i = 0; i<resources.length; i++){
Bitmap bmp = Bitmap.createBitmap(resources[i], 0, 0, resources[i].getWidth(), resources[i].getHeight(), flip, true);
resources[i].recycle();
mGL.glBindTexture(GL10.GL_TEXTURE_2D, mTextures[i]);
mGL.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR);
mGL.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);
mGL.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_REPEAT);
mGL.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_REPEAT);
GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bmp, 0);
bmp.recycle();
}
}
The first time, the textures load fine, but a second call to it turns the screen white.
Am I overlooking something?