Hi.
My OpenGL texture display properly on my G1 and Motorola Milestone. (I
only have these 2 devices to test)
But on many other devices(reported by users), there's only a "white
box" displaying instead of the texture.
This bug also appear on Android 2.3 Emulator.
My texture size is 128x256 in pixel.
Below is the code I use to display the texture:
gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
gl.glEnable(GL10.GL_TEXTURE_2D);
gl.glColor4f(0.0f, 0.0f, 0.0f, 0.0f);
gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
gl.glEnable(GL10.GL_BLEND); // Turn Blending On
gl.glDisable(GL10.GL_DEPTH_TEST);
gl.glDisable(GL10.GL_LIGHT0);
gl.glDisable(GL10.GL_LIGHTING);
gl.glTexEnvf(GL10.GL_TEXTURE_ENV, GL10.GL_TEXTURE_ENV_MODE,
GL10.GL_REPLACE);
gl.glBindTexture(GL10.GL_TEXTURE_2D, myTextureID);
gl.glPushMatrix();
gl.glTranslatef(0, 0, -9.0f);
gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, texBuff);
gl.glVertexPointer(3, GL10.GL_FLOAT, 0, bgBuff);
gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, 4);
gl.glPopMatrix();
And here's the code I used to load the texture:
private int loadTextureById(GL10 gl, int resId) {
int[] textures = new int[1];
gl.glGenTextures(1, textures, 0);
int generatedTextureId = textures[0];
gl.glBindTexture(GL10.GL_TEXTURE_2D, generatedTextureId);
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);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S,
GL10.GL_CLAMP_TO_EDGE);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T,
GL10.GL_CLAMP_TO_EDGE);
gl.glTexEnvf(GL10.GL_TEXTURE_ENV, GL10.GL_TEXTURE_ENV_MODE,
GL10.GL_MODULATE);
InputStream is =
mGameActivity.getResources().openRawResource(resId);
Bitmap bitmap;
try {
bitmap = BitmapFactory.decodeStream(is);
} finally {
try {
is.close();
} catch (IOException e) {
// Ignore.
}
}
GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);
bitmap.recycle();
return generatedTextureId;
}
Anyone know how to solve this problem?
Thank you in advance!
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en