I've made a game where all objects use one sprite sheet, which works fine so far. Now I've made an object that has its own texture, but (at least on my phone, an Evo) it just shows a white plane. This works fine on the emulator, however. This is my code for loading textures:
public void LoadTexture(GL10 gl, Context context) throws IOException {
InputStream is = context.getAssets().open("Image.png");
Bitmap bitmap = null;
try{
bitmap = BitmapFactory.decodeStream(is);
}finally{
try{
is.close();
is = null;
gl.glGenTextures(1, texture,0);
gl.glBindTexture(GL10.GL_TEXTURE_2D, texture[0]);
//Create Nearest Filtered Texture
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_NEAREST);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);
//Different possible texture parameters, e.g. GL10.GL_CLAMP_TO_EDGE
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_REPEAT);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_REPEAT);
//Use the Android GLUtils to specify a two-dimensional texture image from our bitmap
GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);
gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
//Clean up
bitmap.recycle();
}catch(IOException e){
}
}
}
And, in a different class:
public void LoadTexture(GL10 gl, Context context) throws IOException{
InputStream is = context.getAssets().open("end.png");
Bitmap bitmap = null;
try{
bitmap = BitmapFactory.decodeStream(is);
}finally{
try{
is.close();
is = null;
gl.glGenTextures(1, texture,0);
gl.glBindTexture(GL10.GL_TEXTURE_2D, texture[0]);
//Create Nearest Filtered Texture
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_NEAREST);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);
//Different possible texture parameters, e.g. GL10.GL_CLAMP_TO_EDGE
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_REPEAT);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_REPEAT);
//Use the Android GLUtils to specify a two-dimensional texture image from our bitmap
GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);
gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
//Clean up
bitmap.recycle();
}catch(IOException e){
}
}
}
Both classes have a draw frame routine that enables/disables the texture, and a private member (int[] texture = new int[1]
). I try changing the variable, but the same thing happens anyway. Both textures are loaded in onSurfaceCreated(GL10 gl, EGLConfig config);