0
\$\begingroup\$

I have a problem with the alpha of my game, maybe it is solved in another post but as I am new in OpenGl and Game developemnt I dont understand most of the vocabulary and cant find a solution.

The problem is I have enemies with alpha and coins with alpha that works great, but when an enemy pass through the coin it take seem the background instead of the coin(same with shoots)

there is a image explaining it

enter image description here

There is the code to draw enemys and coins

public void drawEnemy(GL10 gl)
{
    gl.glFrontFace(GL10.GL_CCW); // Front face in counter-clockwise
                                    // orientation
    gl.glEnable(GL10.GL_CULL_FACE); // Enable cull face
    gl.glCullFace(GL10.GL_BACK); // Cull the back face (don't display)

    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer);
    gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY); // Enable
                                                            // texture-coords-array
                                                            // (NEW)
    gl.glTexCoordPointer(3, GL10.GL_FLOAT, 0, texBuffer); // Define
                                                            // texture-coords
                                                            // buffer (NEW)

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

    // front
    switch (type)
    {
        case 0:
            gl.glBindTexture(GL10.GL_TEXTURE_2D, TextureLoader.textureIDs[0]);
            break;
        case 1:
            gl.glBindTexture(GL10.GL_TEXTURE_2D, TextureLoader.naveEnemigaIDs[0]);
            break;
        case 2:
            gl.glBindTexture(GL10.GL_TEXTURE_2D, TextureLoader.naveEnemigaIDs2[0]);
            break;
    }

    gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, 4);

    gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY); // Disable
                                                            // texture-coords-array
                                                            // (NEW)
    gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glDisable(GL10.GL_CULL_FACE);
    gl.glDisable(GL10.GL_BLEND);
}


public void drawCoin(GL10 gl)
{
    gl.glFrontFace(GL10.GL_CCW); // Front face in counter-clockwise
                                    // orientation
    gl.glEnable(GL10.GL_CULL_FACE); // Enable cull face
    gl.glCullFace(GL10.GL_BACK); // Cull the back face (don't display)

    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer);
    gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY); // Enable
                                                            // texture-coords-array
                                                            // (NEW)
    gl.glTexCoordPointer(3, GL10.GL_FLOAT, 0, texBuffer); // Define
                                                            // texture-coords
                                                            // buffer (NEW)

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

    // front
    gl.glBindTexture(GL10.GL_TEXTURE_2D, TextureLoader.CointextureIDs[0]);
    gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, 4);

    gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY); // Disable
                                                            // texture-coords-array
                                                            // (NEW)
    gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glDisable(GL10.GL_CULL_FACE);
    gl.glDisable(GL10.GL_BLEND);
}
\$\endgroup\$
3
  • 2
    \$\begingroup\$ disable depth testing, or depth write \$\endgroup\$
    – Raxvan
    Nov 13, 2014 at 11:40
  • 4
    \$\begingroup\$ or sort your object from back to front \$\endgroup\$ Nov 13, 2014 at 12:22
  • \$\begingroup\$ Thanks for your reply, how I can do that? and why it happen? \$\endgroup\$
    – D4rWiNS
    Nov 13, 2014 at 12:44

1 Answer 1

1
\$\begingroup\$

The issue was the drawing order. If I draw the money and then the ship it respect the alpha.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .