Mark Buikema
Mark Buikema

Reputation: 2540

Bad quality textures in OpenGL ES

I managed to show an image on the screen. But when I put multiple images on top of each other, the semitransparent edges are black and it doesn't really achieve the result I was hoping for. I am using a Galaxy Note 2.

This is how it looks: enter image description here

I want the tiles to be close to each other, without any black edges. I have not yet programmed any correct coordinates for the tiles so please don't mind that. The problem is the black edges which should be semi-transparent.

This is the code in the drawing method:

public void draw(GL10 gl) {
    gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[0]);

    gl.glFrontFace(GL10.GL_CW);
    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);

    gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertBuffer);
    gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, textureBuffer);


    gl.glDrawElements(GL10.GL_TRIANGLE_STRIP, pIndex.length, GL10.GL_UNSIGNED_SHORT, pBuff);
    gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
}

And to load the texture:

public void loadGLTexture(GL10 gl, Context context) {
    Bitmap bitmap = null;

    if (Math.random() > .3) {
        bitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.tile_grass);
    } else {
        bitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.tile_sand);
    }

    gl.glGenTextures(1, textures, 0);
    gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[0]);
    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);

    GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);

    bitmap.recycle();
}

Upvotes: 1

Views: 652

Answers (1)

Mark Buikema
Mark Buikema

Reputation: 2540

Solved it, I had to add this:

gl.glEnable(GL10.GL_BLEND);
gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);

Upvotes: 1

Related Questions