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 :

Comment utiliser le buffer-z ?


Sujet :

OpenGL

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Profil pro
    Inscrit en
    Avril 2008
    Messages
    51
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Avril 2008
    Messages : 51
    Par défaut Comment utiliser le buffer-z ?
    Salut, je débute en OpenGl(et glut) et je suis déjà bloquer, j'ai essayer de faire un cube, mais les faces ce chevauche. Je sais que pour éviter ce problème il faut utiliser le buffer-z, mais comment l'utiliser sans windows.h ?
    Voici mon code:
    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
    #include <gl/glut.h>
     
    void Clavier(unsigned char touche,int x,int y);
    void Reshape(int w, int h);  
    void Affichage();  
     
    int main( int argc, char** argv)
    {   
        glutInit(&argc, argv);
     
        glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE);
        glutInitWindowSize(250, 250); 
        glutInitWindowPosition(500, 300);  
     
        glutCreateWindow("OpenGL");
        glClearColor(0.0,0.0,0.0,0.0);
        glutReshapeFunc(Reshape);
        glutDisplayFunc(Affichage);
    	glutKeyboardFunc(Clavier);
        glutMainLoop();
        return 0;
    }
     
    void Affichage()
    { 
     glClear(GL_COLOR_BUFFER_BIT);
     glMatrixMode(GL_MODELVIEW) ;
     glLoadIdentity();
     
     gluLookAt(7,7,-10,0,0,0,0,1,0);
     
    			glBegin (GL_QUADS); 
    			glColor3d(1.0f, 0.f, 0.0f);
    				glVertex3i (-1,-1,1); // 1
    			glColor3d(0.0f, 1.f, 0.0f);
    				glVertex3i (-1,1,1);
    			glColor3d(0.0f, 0.f, 1.0f);
    				glVertex3i (1,1,1);
    			glColor3d(1.0f, 1.f, 1.0f);
    				glVertex3i (1,-1,1);
    			glColor3d(1.0f, 0.f, 0.0f);
    				glVertex3i (-1,-1,-1); // 2
    			glColor3d(0.0f, 1.f, 0.0f);
    				glVertex3i (-1,1,-1);
    			glColor3d(0.0f, 0.f, 1.0f);
    				glVertex3i (1,1,-1);
    			glColor3d(1.0f, 1.f, 1.0f);
    				glVertex3i (1,-1,-1);
    			glColor3d(1.0f, 0.f, 0.0f);
    				glVertex3i (-1,1,-1); // 3
    			glColor3d(0.0f, 1.f, 0.0f);
    				glVertex3i (1,1,-1);
    			glColor3d(0.0f, 0.f, 1.0f);
    				glVertex3i (1,1,1);
    			glColor3d(1.0f, 1.f, 1.0f);
    				glVertex3i (-1,1,1);
    			glColor3d(1.0f, 0.f, 0.0f);
    				glVertex3i (-1,-1,-1); // 4
    			glColor3d(0.0f, 1.f, 0.0f);
    				glVertex3i (1,-1,-1);
    			glColor3d(0.0f, 0.f, 1.0f);
    				glVertex3i (1,-1,1);
    			glColor3d(1.0f, 1.f, 1.0f);
    				glVertex3i (-1,-1,1);
    			glColor3d(1.0f, 0.f, 0.0f);
    				glVertex3i (-1,-1,-1); // 5
    			glColor3d(0.0f, 1.f, 0.0f);
    				glVertex3i (-1,-1,1);
    			glColor3d(0.0f, 0.f, 1.0f);
    				glVertex3i (-1,1,1);
    			glColor3d(1.0f, 1.f, 1.0f);
    				glVertex3i (-1,1,-1);
    			glColor3d(1.0f, 0.f, 0.0f);
    				glVertex3i (1,-1,-1); // 6
    			glColor3d(0.0f, 1.f, 0.0f);
    				glVertex3i (1,-1,1);
    			glColor3d(0.0f, 0.f, 1.0f);
    				glVertex3i (1,1,1);
    			glColor3d(1.0f, 1.f, 1.0f);
    				glVertex3i (1,1,-1);
    			glEnd();
    	glFlush();
    	//glutFullScreen();
     
     glutSwapBuffers();
    }
     
     
    void Reshape(int w, int h) 
    {
       glMatrixMode(GL_MODELVIEW); 
       glLoadIdentity();
       glViewport(0,0,w,h);
       glMatrixMode(GL_PROJECTION);
       glLoadIdentity();
       gluPerspective(45,(float) w/h,1.,500.);
    }
     
    void Clavier(unsigned char touche,int x,int y)
    {
    	switch (touche)
    	{
    		case 'd':
    		glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
    		glutPostRedisplay(); break;
    		case 'w':
    		glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
    		glutPostRedisplay(); break;
    		case 's' :
    		glPolygonMode(GL_FRONT_AND_BACK,GL_POINT);
    		glutPostRedisplay(); break;
    		case 'a' :
    		glutFullScreen(); break;
    		case 'q' :
    		exit(0);
    	}
    }

  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
    Il faut que tu ajoutes GLUT_DEPTH dans les paramètres de glutInitDisplayMode
    Et quand tu réinitialises l'affichage à chaque frame, réinitialises aussi le depth-buffer (depth buffer = z-buffer) :

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  3. #3
    Membre averti
    Profil pro
    Inscrit en
    Avril 2008
    Messages
    51
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Avril 2008
    Messages : 51
    Par défaut
    Ouais ! Merci, ça marche !

    J'ai un autre problème, c'est pour faire une translation d'un cude sur l'axe Z. Je ne sais pas ou mettre
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    if (a <= -8) ecranComplet = 0; 
    if (a >= 8) ecranComplet = 1; 
    if (!ecranComplet) a += 0.1; 
    if (ecranComplet) a -= 0.1; 
    glTranslated (0,0,a);
    Code complet:
    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
    #include <gl/glut.h>
    #include <string.h>
     
    void bitmap_output(int x,int y,char *string,void *font);
    void Clavier(unsigned char touche,int x,int y);
    void Reshape(int w, int h);  
    void Affichage();  
     
    double a = 1;
    int ecranComplet;
     
    int main( int argc, char** argv)
    {   
        glutInit(&argc, argv);
     
        glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE);
        glutInitWindowSize(250, 250);
        glutInitWindowPosition(500, 300);
     
        glutCreateWindow("OpenGL");
        glClearColor(0.0,0.0,0.0,0.0);
    	glEnable(GL_DEPTH_TEST);
        glutReshapeFunc(Reshape);
        glutDisplayFunc(Affichage);
    	glutKeyboardFunc(Clavier);
     
        glutMainLoop();
        return 0;
    }
     
    void Affichage()
    { 
     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
     glMatrixMode(GL_MODELVIEW) ;
     glLoadIdentity();
     
     gluLookAt(0,0,-10,0,0,0,0,1,0);
     
    if (a <= -8) ecranComplet = 0; 
    if (a >= 8) ecranComplet = 1; 
    if (!ecranComplet) a += 0.1; 
    if (ecranComplet) a -= 0.1; 
    glTranslated (0,0,a);
     
    				glBegin (GL_QUADS); 
    				glColor3d (0,1,1);glVertex3i (-3,-3,3);
    				glColor3d (1,0,0);glVertex3i (-3,3,3);
    				glColor3d (0,1,0);glVertex3i (3,3,3);
    				glColor3d (1,0,1);glVertex3i (3,-3,3);
     
    				glColor3d (0,0,1);glVertex3i (-3,-3,-3);
    				glColor3d (1,1,0);glVertex3i (-3,3,-3);
    				glColor3d (1,1,1);glVertex3i (3,3,-3);
    				glColor3d (.5,.5,.5);glVertex3i (3,-3,-3);
     
    				glColor3d (1,1,0);glVertex3i (-3,3,-3);
    				glColor3d (1,1,1);glVertex3i (3,3,-3);
    				glColor3d (0,1,0);glVertex3i (3,3,3);
    				glColor3d (1,0,0);glVertex3i (-3,3,3);
     
    				glColor3d (0,0,1);glVertex3i (-3,-3,-3);
    				glColor3d (.5,.5,.5);glVertex3i (3,-3,-3);
    				glColor3d (1,0,1);glVertex3i (3,-3,3);
    				glColor3d (0,1,1);glVertex3i (-3,-3,3);
     
    				glColor3d (0,0,1);glVertex3i (-3,-3,-3);
    				glColor3d (0,1,1);glVertex3i (-3,-3,3);
    				glColor3d (1,0,0);glVertex3i (-3,3,3);
    				glColor3d (1,1,0);glVertex3i (-3,3,-3);
     
    				glColor3d (.5,.5,.5);glVertex3i (3,-3,-3);
    				glColor3d (1,0,1);glVertex3i (3,-3,3);
    				glColor3d (0,1,0);glVertex3i (3,3,3);
    				glColor3d (1,1,1);glVertex3i (3,3,-3);
    				glEnd();
    	glFlush();
    	//glutFullScreen();
     
     glutSwapBuffers();
    }
     
     
    void Reshape(int w, int h) 
    {
       glMatrixMode(GL_MODELVIEW); 
       glLoadIdentity();
       glViewport(0,0,w,h);
       glMatrixMode(GL_PROJECTION);
       glLoadIdentity();
       gluPerspective(45,(float) w/h,1.,500.);
    }
     
    void Clavier(unsigned char touche,int x,int y)
    {
    	switch (touche)
    	{
    		case 'd':
    		glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
    		glutPostRedisplay(); break;
    		case 'w':
    		glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
    		glutPostRedisplay(); break;
    		case 's' :
    		glPolygonMode(GL_FRONT_AND_BACK,GL_POINT);
    		glutPostRedisplay(); break;
    		case 'a' :
    		glutFullScreen(); break;
    		case 'q' :
    		exit(0);
    	}
    }
    Ca compile, mais ne fait absolument rien !
    Pourquoi ?

  4. #4
    Responsable 2D/3D/Jeux


    Avatar de LittleWhite
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Mai 2008
    Messages
    27 122
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Mai 2008
    Messages : 27 122
    Billets dans le blog
    148
    Par défaut
    Je ne suis pas sur ... mais après 10 minutes de recherche je pense que tu devrais essayer ça :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    glutIdleFunc(Affichage);
    après la fonction glutDisplayFunc();

    Mais je n'en suis pas sur ...

    GLUT , lorsqu'il n'a rien à faire , il va appeler la fonction passer dans glutIdleFunc ( soit réaffichage de ta scène ... au sinon , comme le cas présent , il reaffiche pas , donc le cube bouge pas )
    Vous souhaitez participer à la rubrique 2D/3D/Jeux ? Contactez-moi

    Ma page sur DVP
    Mon Portfolio

    Qui connaît l'erreur, connaît la solution.

Discussions similaires

  1. comment utiliser un buffer dans java
    Par javadz dans le forum AWT/Swing
    Réponses: 0
    Dernier message: 24/02/2014, 19h54
  2. Réponses: 4
    Dernier message: 24/02/2009, 12h06
  3. comment utiliser actionscript ?
    Par webs dans le forum Flash
    Réponses: 3
    Dernier message: 09/02/2003, 23h11
  4. Comment utiliser OUT ?
    Par Bouziane Abderraouf dans le forum CORBA
    Réponses: 3
    Dernier message: 20/07/2002, 09h35
  5. Réponses: 5
    Dernier message: 11/06/2002, 15h21

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