Corrupción de la textura de Android opengl

I am having problems with texture corruption on Android emulator (it runs fine on most android devices).

Android 4.1 reference rendering

The picture above is a reference rendering produced by emulator running Android 4.1 Jelly Bean, everything looks as it should.

Android 1.6

The second picture is captured in emulator running Android 1.6. Note the corruption of some of the disabled toolbar buttons (they are rendered with color 1f,1f,1f,0.5f)

Android 1.6

The third picture is captured in the same emulator. The difference is that now score is rendered in the upper-right corner. Score is a bitmap font, it's texture is an alpha mask. Everything rendered after the score looses it's texture. Note that the previous screenshot also contained bitmap font rendered the same way (but using different texture).

A similar problem was present on one of the Samsung devices (I don't remember the model). When the floor texture was rendered, everything rendered after that lost texture. The problem did not manifest itself when I either a) did not bind the texture b) did bind the texture, but drew no triangles using it c) recreated the png asset from scratch.

Opengl settings:


How textures are loaded:

public void doGLLoading(Engine renderer) {
        GL10 gl=renderer.getGl();
        int[] ids=new int[1];
        gl.glGenTextures(1, ids,0);
        gl.glBindTexture(GL10.GL_TEXTURE_2D, id);
        Log.d("SpriteDraw", String.format("Texture %s has format %s",getPath(),bitmap.getConfig().toString()));
        buildMipmap(gl, bitmap);
        gl.glTexParameterf(GL10.GL_TEXTURE_2D,GL10.GL_TEXTURE_MIN_FILTER, minFilter);
        gl.glTexParameterf(GL10.GL_TEXTURE_2D,GL10.GL_TEXTURE_MAG_FILTER, magFilter);
        gl.glTexParameterf(GL10.GL_TEXTURE_2D,GL10.GL_TEXTURE_WRAP_S, textureWrapS);
        gl.glTexParameterf(GL10.GL_TEXTURE_2D,GL10.GL_TEXTURE_WRAP_T, textureWrapT);
private void buildMipmap(GL10 gl, Bitmap bitmap) {
    int level = 0;
    int height = bitmap.getHeight();
    int width = bitmap.getWidth();

    while (height >= 1 || width >= 1) {
        // First of all, generate the texture from our bitmap and set it to
        // the according level
                    //TextureUtils.texImage2D(gl, GL10.GL_TEXTURE_2D, level, -1, bitmap, -1, 0);
        GLUtils.texImage2D(GL10.GL_TEXTURE_2D, level, bitmap, 0);
        if (height == 1 || width == 1) {
        // Increase the mipmap level
        height /= 2;
        width /= 2;
        Bitmap bitmap2 = Bitmap.createScaledBitmap(bitmap, width, height,

        // Clean up
        bitmap = bitmap2;

Notes: the font is rendered using gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA); y GL10.glDrawArrays. The corruption affects not only the 1.6 emulator, but also the 2.x series of android, althought it is not as prominent (the alpha masks are still rendered incorrectly). All assets are correctly loaded as power of two bitmaps.

preguntado el 25 de agosto de 12 a las 22:08

Are the textures dimention Power of Two? and do you use superPng or Png? normal png files don't reserve alpha correctly as mask. but superPng can reserve it. A plugin for photoshop exist to export as superPng -

Yes, they are all Power of Two (mentioned at the end of the post). Bitmaps are stored as greyscale bitmaps, loaded as ARGB_8888 by android, and converted to alpha mask by my code. -

1 Respuestas

  1. I suggest using 32bit textures, not grayscale, not "alphamasks" (what's that?)
  2. Check the size of your texture, it should not exceed maximum size ( glGetInteger( GL_MAX_TEXTURE_SIZE ). Also make shure your textures are power of 2. Yes, you mentioned before they are, but if they are in scalable assets (drawable_x_dpi folders), they will be scaled by android. To avoid scaling, put them to "raw" folder.
  3. Just for test, try to disable all filtering, including mipmaps - set GL_TEXTURE_WRAP_S, and GL_TEXTURE_WRAP_T to GL_NEAREST

Respondido el 04 de Septiembre de 12 a las 12:09

Alpha mask is a texture with only alpha channel. They should work ok. All textures are really loaded as power of two bitmaps (they are loaded using InputStream, not resource id, so they are not scaled). As to the filtering, I suppose you meant GL_TEXTURE_MIN_FILTER. Poniéndolo en GL_NEAREST no soluciona el problema. - rkapl

Yes, i meant GL_TEXTURE_MIN_FILTER. The next thing you can try is to replace texture files that glitch with textures that work normal. So you will know if the problem is in loading texture or in the way you use them. - David

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.