IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

OpenGL Discussion :

Mettre en place une texture transparente


Sujet :

OpenGL

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éclairé
    Profil pro
    Inscrit en
    Décembre 2007
    Messages
    560
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2007
    Messages : 560
    Par défaut Mettre en place une texture transparente
    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?

  2. #2
    Expert confirmé

    Avatar de dragonjoker59
    Homme Profil pro
    Software Developer
    Inscrit en
    Juin 2005
    Messages
    2 035
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Bas Rhin (Alsace)

    Informations professionnelles :
    Activité : Software Developer
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2005
    Messages : 2 035
    Billets dans le blog
    12
    Par défaut
    Salut!

    Le problème que tu rencontres vient très certainement de l'ordre de dessin de tes objets.
    Il est commun de découper le rendu en plusieurs étapes:
    • Dessin des objets opaques, Depth Write activé
    • Tri des objets transparents par rapport à la caméra, du plus éloigné au plus proche
    • Dessin des objets transparents ainsi triés, Depth Write désactivé.


    Tu devrais alors obtenir le rendu que tu souhaites obtenir.
    Si vous ne trouvez plus rien, cherchez autre chose...

    Vous trouverez ici des tutoriels OpenGL moderne.
    Mon moteur 3D: Castor 3D, presque utilisable (venez participer, il y a de la place)!
    Un projet qui ne sert à rien, mais qu'il est joli (des fois) : ProceduralGenerator (Génération procédurale d'images, et post-processing).

  3. #3
    Membre éclairé
    Profil pro
    Inscrit en
    Décembre 2007
    Messages
    560
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2007
    Messages : 560
    Par défaut
    Merci je vais essayer ca.

Discussions similaires

  1. Mettre en place une passerelle sous linux
    Par gorgonite dans le forum Contribuez
    Réponses: 49
    Dernier message: 02/11/2010, 10h20
  2. Réponses: 4
    Dernier message: 09/09/2006, 12h42
  3. Réponses: 24
    Dernier message: 12/07/2006, 12h11
  4. Mettre en place une sécurité niveau utilisateur
    Par rickar dans le forum Sécurité
    Réponses: 1
    Dernier message: 22/04/2006, 17h23
  5. Comment mettre en place une structure 3 tiers.
    Par WOLO Laurent dans le forum Débats sur le développement - Le Best Of
    Réponses: 13
    Dernier message: 27/07/2003, 23h01

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo