Bonjour,

Je cherche à mettre en place une texture transparente derriere laquel je fais bouger un carré.Je travaile su OpenglES (android).
Quand je mets mon carré au dessus de ma texture, je vois la transparence du carré à travers duquel je vois la texture qui est transparente.
Quand je mets le carre derriere la texture, le vois la transparence de la texture et le fond par transparence mais je ne vois pas le carré a travers la texture.
Voici mes shaders:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// the texture
    private final String vertexShaderCode =
    "uniform mat4 uMVPMatrix;\n" +
            "attribute vec2 aPosition;\n" +
            "attribute vec2 aTexPos;\n" +
            "varying vec2 vTexPos;\n" +
            "void main() {\n" +
            "  vTexPos = aTexPos;\n" +
            "  gl_Position = uMVPMatrix * vec4(aPosition.xy, 0.0, 1.0);\n" +
            "}";
 
    private final String fragmentShaderCode =
            "precision mediump float;\n"+
                    "uniform sampler2D uTexture;\n" +
                    "varying vec2 vTexPos;\n" +
                    "void main(void)\n" +
                    "{\n" +
//                    "  gl_FragColor = texture2D(uTexture, vTexPos);\n" +
                    "  gl_FragColor = vec4( vTexPos.xy,0,(vTexPos.x+vTexPos.y)/4.0);\n" +
                        "}";
 
    //the square:
        private final String vertexShaderCode =
                // This matrix member variable provides a hook to manipulate
                // the coordinates of the objects that use this vertex shader
                "uniform mat4 uMVPMatrix;" +
                "attribute vec4 vPosition;" +
                "void main() {" +
                // The matrix must be included as a modifier of gl_Position.
                // Note that the uMVPMatrix factor *must be first* in order
                // for the matrix multiplication product to be correct.
                "  gl_Position = uMVPMatrix * vPosition;" +
                "}";
 
        private final String fragmentShaderCode =
                "precision mediump float;" +
                "uniform vec4 vColor;" +
                "void main() {" +
                "  gl_FragColor = vColor;" +
                "}";
Mes function d'affichage:
Pour le carré:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
public void draw(float[] mvpMatrix) {
        // Add program to OpenGL environment
        GLES20.glUseProgram(mProgram);
 
        GLES20.glEnable( GLES20.GL_DEPTH_TEST );
        GLES20.glDepthFunc( GLES20.GL_LEQUAL );
        GLES20.glDepthMask( true );
        GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA);
        GLES20.glEnable(GLES20.GL_BLEND);
 
        // get handle to vertex shader's vPosition member
        mPositionHandle = GLES20.glGetAttribLocation(mProgram, "vPosition");
 
        // Enable a handle to the triangle vertices
        GLES20.glEnableVertexAttribArray(mPositionHandle);
 
        // Prepare the triangle coordinate data
        GLES20.glVertexAttribPointer(
                mPositionHandle, COORDS_PER_VERTEX,
                GLES20.GL_FLOAT, false,
                vertexStride, vertexBuffer);
 
        // get handle to fragment shader's vColor member
        mColorHandle = GLES20.glGetUniformLocation(mProgram, "vColor");
 
        // Set color for drawing the triangle
        GLES20.glUniform4fv(mColorHandle, 1, color, 0);
 
        // get handle to shape's transformation matrix
        mMVPMatrixHandle = GLES20.glGetUniformLocation(mProgram, "uMVPMatrix");
        MyGLRenderer.checkGlError("glGetUniformLocation");
 
        // Apply the projection and view transformation
        GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mvpMatrix, 0);
        MyGLRenderer.checkGlError("glUniformMatrix4fv");
 
        // Draw the square
        GLES20.glDrawElements(
                GLES20.GL_TRIANGLES, drawOrder.length,
                GLES20.GL_UNSIGNED_SHORT, drawListBuffer);
 
        // Disable vertex array
        GLES20.glDisableVertexAttribArray(mPositionHandle);
        GLES20.glDisable(GLES20.GL_BLEND);
    }
Pour ma texture:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
public void draw(float[] mvpMatrix) {
 
        // Add program to OpenGL environment
        GLES20.glUseProgram(mProgram);
 
 
        GLES20.glEnable( GLES20.GL_DEPTH_TEST );
        GLES20.glDepthFunc( GLES20.GL_LEQUAL );
        GLES20.glDepthMask( true );
       GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA);
        GLES20.glEnable(GLES20.GL_BLEND);
 
        // get handle to vertex shader's vPosition member
        mPositionHandle     = GLES20.glGetAttribLocation(mProgram, "aPosition");
        MyGLRenderer.checkGlError("glGetUniformLocation");
        mTexturePosHandle   = GLES20.glGetAttribLocation(mProgram, "aTexPos");
        MyGLRenderer.checkGlError("glGetUniformLocation");
        // Enable a handle to the triangle vertices
 
        // Prepare the triangle coordinate data
        GLES20.glVertexAttribPointer(
                mPositionHandle, 2,
                GLES20.GL_FLOAT, false,
                8, vertexBuffer);
 
        GLES20.glEnableVertexAttribArray(mPositionHandle);
        MyGLRenderer.checkGlError("glGetUniformLocation");
 
 
        GLES20.glVertexAttribPointer(
                mTexturePosHandle, 2,
                GLES20.GL_FLOAT, false,
                8, vertexTextureBuffer);
 
        GLES20.glEnableVertexAttribArray(mTexturePosHandle);
        MyGLRenderer.checkGlError("glGetUniformLocation");
 
        // get handle to shape's transformation matrix
        mMVPMatrixHandle = GLES20.glGetUniformLocation(mProgram, "uMVPMatrix");
        MyGLRenderer.checkGlError("glGetUniformLocation");
 
        // Apply the projection and view transformation
        GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mvpMatrix, 0);
        MyGLRenderer.checkGlError("glUniformMatrix4fv");
 
 
            int uTexture = GLES20.glGetUniformLocation(mProgram, "uTexture");
            GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
            GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureHandle[0]);
            MyGLRenderer.checkGlError("glGetUniformLocation");
            GLES20.glUniform1i(uTexture, 0);
            MyGLRenderer.checkGlError("glGetUniformLocation");
 
           // GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
            // Draw the square
 
 
        GLES20.glDrawElements(
                GLES20.GL_TRIANGLES, drawOrder.length,
                GLES20.GL_UNSIGNED_SHORT, drawListBuffer);
//        GLES20.glDrawElements(
//                GLES20.GL_TRIANGLES, 0,
//                GLES20.GL_UNSIGNED_SHORT, 4);
 
        // Disable vertex array
        GLES20.glDisableVertexAttribArray(mPositionHandle);
 
        GLES20.glDisable(GLES20.GL_BLEND);
    }

Et le code du render:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
 // Draw background color
        GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
 
 
 
 
 
        // Set the camera position (View matrix)
        Matrix.setLookAtM(mViewMatrix, 0, 0, 0, -10, 0f, 0f, 0f, 0f, 1.0f, 0.0f);
 
//        Matrix.setRotateM(mRotationMatrix0, 0, angleX, 0, 1.0f, 0);
        Matrix.setRotateM(mRotationMatrixX, 0, angleX, 0, 1,0);
        Matrix.setRotateM(mRotationMatrixY, 0, angleY, 0, 0,1);
        Matrix.setRotateM(mRotationMatrixZ, 0, angleZ, 1, 0,0);
 
//        for(int j=0;j<4;j++)
//        {
//        	for(int i=0;i<4;i++)
//            {
//        		Log.d("tt"," "+(mRotationMatrix0[j*4+i]));
//            }
//        }
        Matrix.multiplyMM(mRotationMatrix0, 0,mRotationMatrixY , 0,  mRotationMatrixZ, 0);
        Matrix.multiplyMM(mRotationMatrix0, 0,mRotationMatrix0 , 0,  mRotationMatrixX, 0);
        Matrix.multiplyMM(mRotationMatrix, 0,mRotationMatrix0  , 0, mViewMatrix , 0);
 
        // Calculate the projection and view transformation
        Matrix.multiplyMM(mMVPMatrix, 0, mProjectionMatrix, 0, mRotationMatrix, 0);
 
        // Draw square
        mTexturedSquare.draw(mMVPMatrix);
 
        mSquare.draw(mMVPMatrix);
Je suis completement bloqué et je dois pas comprendre quelquechose.
Si quelqu'un pouvait me donner un coup de pouce?