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 :

Problème de transparence


Sujet :

OpenGL

  1. #1
    Membre confirmé
    Profil pro
    Inscrit en
    Novembre 2006
    Messages
    136
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2006
    Messages : 136
    Par défaut Problème de transparence
    Bonjour!

    J'ai un (gros) problème depuis un petit moment. J'ai fais un petit programme mais maintenant je me rends compte qu'il ne gère pas la transparence (alpha blending) malgré tout ce que j'ai fais. J'ai galéré un moment avant de trouver que ça venait de la transparence car j'ai pourtant fais TOUT comme il faut.

    Bref j'ai créé un nouveau projet avec un minimum de code et un max de copier-coller de l'ancien projet et celui-là gère la transparence... Pourtant j'ai vérifié, le code est exactement le même, mais d'un côté ça fonctionne, et de l'autre pas...

    Nouveau projet qui fonctionne:
    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
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    #include <windows.h>
    #include <GL/glut.h>
     
    void displayFunc();
     
    int main(int argc, char ** argv)
    {
        glutInit(&argc, argv);
        glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH | GLUT_ALPHA);
     
        glutInitWindowSize(600, 480);
        glutInitWindowPosition(200, 200);
        glutCreateWindow("transparence");
     
        glClearColor(0.0 ,0.0 ,0.0 ,0.0);
        glClearDepth(1.0);
     
        glEnable (GL_DEPTH_TEST);
        glEnable(GL_ALPHA_TEST);
        glEnable (GL_BLEND);
        glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
     
        glAlphaFunc(GL_GREATER,0.0);
     
        glutDisplayFunc(displayFunc);
     
        glFlush();
     
        glutMainLoop();
     
        return 0;
    }
     
    void displayFunc()
    {
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
     
        glColor4f(1.0,0.0,0.0,0.5);
     
        /*glBegin(GL_QUADS);
        glVertex3f(0.3 , 0.3 , 0.0);
        glVertex3f(0.3 , 0.0 , 0.0);
        glVertex3f(0.0 , 0.0 , 0.0);
        glVertex3f(0.0 , 0.3 , 0.0);
        glEnd();
        */
        glBegin(GL_QUADS);
        glVertex2f(0.3 , 0.3 );
        glVertex2f(0.3 , 0.0 );
        glVertex2f(0.0 , 0.0 );
        glVertex2f(0.0 , 0.3 );
        glEnd();
     
        glBegin(GL_QUADS);
        glVertex2f(1.0 , 1.0 );
        glVertex2f(1.0 , -1.0 );
        glVertex2f(-1.0 , -1.0 );
        glVertex2f(-1.0 , 1.0 );
        glEnd();
     
        glColor4f(0.0,0.0,1.0,0.5);
     
        glBegin(GL_QUADS);
        glVertex3f(0.15 , 0.15 , -0.05);
        glVertex3f(0.15 , -0.15 , -0.05);
        glVertex3f(-0.15 , -0.15 , -0.05);
        glVertex3f(-0.15 , 0.15 , -0.05);
        glEnd();
     
        glColor4f(0.0,1.0,0.0,0.5);
     
        glBegin(GL_QUADS);
        glVertex3f(-0.3 , -0.3 , -0.1);
        glVertex3f(-0.3 , 0.0 , -0.1);
        glVertex3f(0.0 , 0.0 , -0.1);
        glVertex3f(0.0 , -0.3 , -0.1);
        glEnd();
        glFlush();
     
        glutSwapBuffers();
    }
    L'autre programme est morcelé mais j'ai essayé de le résumer ici:

    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
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    #include <string>
    #include <list>
    #include <windows.h>
    #include <GL/glut.h>
     
    //toutes les déclarations
     
    int main(int argc, char **argv)
    {
     
        Logger::getInstance()->logOut("debut\n");
        Logger::getInstance()->logOut_EndLine();
     
        int x;
        int y;
     
        Logger::getInstance()->logOut("start\n");
        Logger::getInstance()->logOut_EndLine();
     
        glutInit(&argc, argv);
        glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH | GLUT_ALPHA);
     
        glutInitWindowSize(_INITIAL_WINDOW_X_SIZE_, _INITIAL_WINDOW_Y_SIZE_);
        glutInitWindowPosition(_INITIAL_WINDOW_X_POSITION_, _INITIAL_WINDOW_Y_POSITION_);
        glutCreateWindow(_WINDOW_NAME_);
     
        initialisation();
     
        glutDisplayFunc(displayFunc);
        glutReshapeFunc(reshapeFunc);
        glutIdleFunc(actualisation);
        glutKeyboardFunc(keyboardFunc);
        glutKeyboardUpFunc(keyboardUpFunc);
        glutMouseFunc(mouseFunc);
        glutMotionFunc(motionFunc);
        glutSpecialFunc(specialFunc);
        glutSpecialUpFunc(specialUpFunc);
        glutPassiveMotionFunc(passiveMotionFunc);
     
        glFlush();
     
        try
        {
            glutMainLoop();
        }
     
        catch(erreur m_erreur)
        {
            m_erreur.logErr();
            return EXIT_FAILURE;
        }
     
        catch (...)
        {
            Logger::getInstance()->logErr("default exception");
            Logger::getInstance()->logErr_EndLine();
            return EXIT_FAILURE;
        }
     
        return EXIT_SUCCESS;
    }
     
    void initialisation()
    {
     
     
        ///------------------------------------------------
        ///généralités
        ///------------------------------------------------
        gestionnaire_objet::getInstance()->setRefreshRate(30.0);
        atexit(tchao);
     
     
        ///------------------------------------------------
        ///rêglages OpenGL et GLUT
        ///------------------------------------------------
        glEnable(GL_TEXTURE_2D);
     
        glClearColor(0.0 ,0.0 ,0.0 ,0.0);
        glClearDepth(1.0);
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        gluOrtho2D(-1.0,1.0, -0.75, 0.75);
     
        glMatrixMode(GL_MODELVIEW);
     
        glEnable (GL_DEPTH_TEST);
        glEnable(GL_ALPHA_TEST);
        glEnable (GL_BLEND);
     
        glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
        glAlphaFunc(GL_GREATER,0.0);
     
     
        glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S, GL_CLAMP);
     
        glDisable(GL_TEXTURE_2D);
    }
     
    void tchao()
    {
        ///------------------------------------------------
        ///grand nettoyage
        ///------------------------------------------------
    	NewtonDestroy (theWorld);
    	delete p_struct;
     
    	Logger::getInstance()->logOut("shut down");
        Logger::getInstance()->logOut_EndLine();
    }
     
    void displayFunc()
    {
    glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
     
        gestionnaire_objet::getInstance()->dessiner();
     
    glColor4f(1.0,0.0,0.0,0.5);
     
        glBegin(GL_QUADS);
        glVertex3f(0.3 , 0.3 , 0.0);
        glVertex3f(0.3 , 0.0 , 0.0);
        glVertex3f(0.0 , 0.0 , 0.0);
        glVertex3f(0.0 , 0.3 , 0.0);
        glEnd();
     
        glColor4f(0.0,0.0,1.0,0.5);
     
        glBegin(GL_QUADS);
        glVertex3f(0.15 , 0.15 , -0.05);
        glVertex3f(0.15 , -0.15 , -0.05);
        glVertex3f(-0.15 , -0.15 , -0.05);
        glVertex3f(-0.15 , 0.15 , -0.05);
        glEnd();
     
        glColor4f(0.0,1.0,0.0,0.5);
     
        glBegin(GL_QUADS);
        glVertex3f(-0.3 , -0.3 , -0.1);
        glVertex3f(-0.3 , 0.0 , -0.1);
        glVertex3f(0.0 , 0.0 , -0.1);
        glVertex3f(0.0 , -0.3 , -0.1);
        glEnd();
        glFlush();
        glFlush();
        glutSwapBuffers();
    }
    Bref je vous ai fais une reconstitution mais plus franchement je ne vois pas où ça cloche... Pouvez vous m'indiquer où chercher?

    Edit : j'ai vérifié : openGL ne détecte AUCUNE erreur

  2. #2
    Membre expérimenté
    Homme Profil pro
    Inscrit en
    Mars 2005
    Messages
    249
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Bas Rhin (Alsace)

    Informations forums :
    Inscription : Mars 2005
    Messages : 249
    Par défaut
    Je ne sais pas d'où vient le problème, j'ai testé ton code et j'obtiens bien de la transparence.
    A part ça, tu n'initialises pas la matrice de projection? L'erreur ne pourrait pas venir de là?

Discussions similaires

  1. [ImageList] problème de transparence
    Par Rayek dans le forum Delphi
    Réponses: 7
    Dernier message: 19/05/2006, 11h12
  2. Réponses: 13
    Dernier message: 01/12/2005, 05h34
  3. Réponses: 5
    Dernier message: 18/03/2005, 20h10
  4. [DX9] [Debutant] Problème de transparence :(
    Par SekYo dans le forum DirectX
    Réponses: 5
    Dernier message: 10/09/2004, 14h19
  5. Réponses: 8
    Dernier message: 06/07/2004, 18h30

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