Note that there are some explanatory texts on larger screens.

plurals
  1. POOpenglES 2.0 PNG alpha texture overlap
    primarykey
    data
    text
    <p>I'm trying to draw multiple hexagons on the screen that have an alpha channel. the image is this:</p> <p><img src="https://i.stack.imgur.com/iPO7X.png" alt="http://img834.imageshack.us/img834/571/hexagon.png"></p> <p>So, I load the texture into the program and that's ok. When it runs, the alpha channel is blended with the background color and that's ok but, when two hexagons overlap themselves, the overlapped part becomes the color of the background! Below the picture:</p> <p><img src="https://i.stack.imgur.com/eqjYd.png" alt="http://img259.imageshack.us/img259/213/20120731163847.png"></p> <p>Of course, this is not the effect that I expected.. I want them to overlap without this background being drawn over the other texture. Here is my code for drawing:</p> <pre><code> GLES20.glUseProgram(Program); hVertex = GLES20.glGetAttribLocation(Program,"vPosition"); hColor = GLES20.glGetUniformLocation(Program, "vColor"); uTexture = GLES20.glGetUniformLocation(Program, "u_Texture"); hTexture = GLES20.glGetAttribLocation(Program, "a_TexCoordinate"); hMatrix = GLES20.glGetUniformLocation(Program, "uMVPMatrix"); GLES20.glVertexAttribPointer(hVertex, 3, GLES20.GL_FLOAT, false, 0, bVertex); GLES20.glEnableVertexAttribArray(hVertex); GLES20.glUniform4fv(hColor, 1, Color, 0); GLES20.glActiveTexture(GLES20.GL_TEXTURE0); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, hTexture); GLES20.glUniform1i(uTexture, 0); GLES20.glVertexAttribPointer(hTexture, 2, GLES20.GL_FLOAT, false, 0, bTexture); GLES20.glEnableVertexAttribArray(hTexture); GLES20.glBlendFunc(GLES20.GL_ONE, GLES20.GL_ONE_MINUS_SRC_ALPHA); GLES20.glEnable(GLES20.GL_BLEND); x=-1;y=0;z=0; for (int i=0;i&lt;10;i++) { Matrix.setIdentityM(ModelMatrix, 0); Matrix.translateM(ModelMatrix, 0, x, y, z); x+=0.6f; Matrix.multiplyMM(ModelMatrix, 0, ModelMatrix, 0, ProjectionMatrix, 0); GLES20.glUniformMatrix4fv(hMatrix, 1, false, ModelMatrix, 0); GLES20.glDrawElements(GLES20.GL_TRIANGLES, DrawOrder.length, GLES20.GL_UNSIGNED_SHORT, bDrawOrder); } GLES20.glDisable(GLES20.GL_BLEND); GLES20.glDisableVertexAttribArray(hVertex); } </code></pre> <p>And My fragment shader:</p> <pre><code>public final String fragmentShaderCode = "precision mediump float;" + "uniform vec4 vColor;" + "uniform sampler2D u_Texture;" + "varying vec2 v_TexCoordinate;" + "void main() {" + " gl_FragColor = vColor * texture2D(u_Texture, v_TexCoordinate);" + "}"; </code></pre> <p>and my renderer code:</p> <pre><code> super(context); setEGLContextClientVersion(2); getHolder().setFormat(PixelFormat.TRANSLUCENT); setEGLConfigChooser(8, 8, 8, 8, 8, 8); renderer = new GLRenderer(context); setRenderer(renderer); </code></pre> <p>I already tried to use diferent functions on glBlendFunc but nothing seems to work.. Does Anyone knows what the problem is? I'm really lost.. If needs anymore code just ask!</p> <p>Thank you!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload