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 :

VBO : plantage sur glDrawArrays


Sujet :

OpenGL

  1. #1
    Membre à l'essai
    Profil pro
    Inscrit en
    Août 2007
    Messages
    10
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2007
    Messages : 10
    Points : 10
    Points
    10
    Par défaut VBO : plantage sur glDrawArrays
    Bonjour,
    Je m'essaie aux VBO avec peu de réussite. Après 3 jours de fighting, j'en appelle à vous:

    Je fais mes essais sous mingw/gdb/eclipse glut/glew

    Application glut classique: basée sur le définition de 3 fonctions init, display et resize.

    Je cherche à :
    - définir mes VBO dans le init et les envoyer à la carte
    - les retrouver dans la fonction display pour les afficher

    Tout se compile bien, mais plantage à l'exec : dans display, à l'affichage de mon malheureux triangle blanc:
    glDrawArrays(GL_TRIANGLES, 0, VertexCount);

    Erreur de segmentation

    Au secours!

    Ci-dessous le 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
     #include <GL/glew.h>
    #include <GL/gl.h>     
    #include <GL/glut.h>   
     
    static GLuint buf; 
    static const int BufferSize = 2;
    static GLuint BufferName[BufferSize]={0,1};
    static const GLsizei VertexCount = 3;
     
    static const GLfloat positionData[9] = {-1.0f, -1.0f, 0.0f, 
                        1.0f, -1.0f, 0.0f, 
                        1.0f, 1.0f, 0.0f};
     
    static const GLubyte colorData[9] = {255, 255, 255, 
                                255, 255, 255,
                                255, 255, 255};
    enum
    {
        POSITIONS=0,
        COLORS=1
    };
     
    void init (void) 
    {
        glewInit();
        glGenBuffers(1, &buf);
        GLsizeiptr positionSize = VertexCount*3*sizeof(GLfloat);
        GLsizeiptr colorSize     = VertexCount*3*sizeof(GLubyte);
     
        glBindBuffer(GL_ARRAY_BUFFER, BufferName[COLORS]);
        glBufferData(GL_ARRAY_BUFFER, colorSize, colorData, GL_STREAM_DRAW);
     
        glBindBuffer(GL_ARRAY_BUFFER, BufferName[POSITIONS]);
        glBufferData(GL_ARRAY_BUFFER, positionSize, positionData, GL_STREAM_DRAW);
     
        glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
        glShadeModel(GL_FLAT);    
     }
     
    void display(void)
    {
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
     
        glBindBuffer(GL_ARRAY_BUFFER, BufferName[COLORS]);
        glVertexPointer(3, GL_UNSIGNED_BYTE, 0, 0);
     
        glBindBuffer(GL_ARRAY_BUFFER, BufferName[POSITIONS]);
        glVertexPointer(3, GL_FLOAT, 0, 0);
     
        glEnableClientState(GL_VERTEX_ARRAY);
        glEnableClientState(GL_COLOR_ARRAY);
        glDrawArrays(GL_TRIANGLES, 0, VertexCount);
        glDisableClientState(GL_COLOR_ARRAY);
        glDisableClientState(GL_VERTEX_ARRAY);
     
        glFlush();
    }
     
    void reshape(int width, int height)
     {
         int side=0;
        if (width < height) side = width; else side=height;
        glViewport((width - side) / 2, (height - side) / 2, side, side);
     
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        gluPerspective(45.0f, (GLfloat)width/(GLfloat)height, 0.1f, 100.0f);
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
     }
     
    int main (int argc, char** argv)
    {
        glutInit(&argc, argv);
        glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
        glutInitWindowSize (300, 200); 
        glutInitWindowPosition (100, 100);
        glutCreateWindow ("hello");
        init ();
        glutReshapeFunc (reshape);
        glutDisplayFunc(display); 
        glutMainLoop();
        return 0;
    }

  2. #2
    Rédacteur
    Avatar de bafman
    Profil pro
    Développeur informatique
    Inscrit en
    Novembre 2003
    Messages
    2 574
    Détails du profil
    Informations personnelles :
    Âge : 40
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Industrie

    Informations forums :
    Inscription : Novembre 2003
    Messages : 2 574
    Points : 5 323
    Points
    5 323
    Par défaut
    ton glVertexPointer prend un pointeur en dernier paramètre (cf doc)
    et toi, tu lui passe 0 (donc NULL)
    * Il est infiniment plus simple de faire rapidement un code qui marche que de faire un code rapide qui marche
    * pour faciliter les recherches, n'oubliez pas de voter pour les réponses pertinentes
    Mes articles

  3. #3
    Membre à l'essai
    Profil pro
    Inscrit en
    Août 2007
    Messages
    10
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2007
    Messages : 10
    Points : 10
    Points
    10
    Par défaut
    ton glVertexPointer prend un pointeur en dernier paramètre (cf doc)
    et toi, tu lui passe 0 (donc NULL)
    le dernier argument de glVertexPointer est OK : c'est un décalage d'indice, pas un pointeur.


    par contre il y avait de nombreuses autres erreurs. Merci à MatRem et son exemple : http://www.developpez.net/forums/sho...=378088&page=2

    ci-dessous le code corrigé.

    Si ça peut servir à d'autres.


    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
     
    #include <GL/glew.h>
    #include <GL/gl.h>     
    #include <GL/glut.h>   
     
    static const int BufferSize = 2;
    static GLuint BufferName[BufferSize]={0,0};
    static const GLsizei VertexCount = 3;
     
    static const GLfloat positionData[9] = {0.0f, 1.0f, 0.0f, 
    					-1.0f, -1.0f, 0.0f, 
    					1.0f, -1.0f, 0.0f};
     
    static const GLfloat colorData[12] = {1.0f, 1.0f, 1.0f, 0.5f, 
    							1.0f, 1.0f, 1.0f, 0.5f,
    							1.0f, 1.0f, 1.0f, 0.5f};
    enum
    {
    	POSITIONS=0,
    	COLORS=1
    };
     
    void init (void) 
    {
     
    	glewInit();
    	glGenBuffers(2, BufferName);
    	GLsizeiptr positionSize = VertexCount*3*sizeof(GLfloat);
    	GLsizeiptr colorSize 	= VertexCount*4*sizeof(GLfloat);
     
    	glBindBuffer(GL_ARRAY_BUFFER, BufferName[COLORS]);
    	glBufferData(GL_ARRAY_BUFFER, colorSize, colorData, GL_STATIC_DRAW);
     
    	glBindBuffer(GL_ARRAY_BUFFER, BufferName[POSITIONS]);
    	glBufferData(GL_ARRAY_BUFFER, positionSize, positionData, GL_STATIC_DRAW);
     
    	glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
    	glShadeModel(GL_FLAT);
    }
     
    void display(void)
    {
    	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    	glLoadIdentity();
    	glTranslatef(-1.5f, 0.0f, -6.0f);
     
    	glBindBuffer(GL_ARRAY_BUFFER, BufferName[COLORS]);
    	glColorPointer(4, GL_FLOAT, 0, 0);
     
    	glBindBuffer(GL_ARRAY_BUFFER, BufferName[POSITIONS]);
    	glVertexPointer(3, GL_FLOAT, 0, 0);
     
    	glEnableClientState(GL_VERTEX_ARRAY);
    	glEnableClientState(GL_COLOR_ARRAY);
    	glDrawArrays(GL_TRIANGLES, 0, VertexCount);
    	glDisableClientState(GL_COLOR_ARRAY);
    	glDisableClientState(GL_VERTEX_ARRAY);
     
    	glutSwapBuffers();
    }
     
    void reshape(int width, int height)
    {
     	int side=0;
    	if (width < height) side = width; else side=height;
    	glViewport((width - side) / 2, (height - side) / 2, side, side);
     
    	glMatrixMode(GL_PROJECTION);
    	glLoadIdentity();
    	gluPerspective(45.0f, (GLfloat)width/(GLfloat)height, 0.1f, 100.0f);
    	glMatrixMode(GL_MODELVIEW);
    	glLoadIdentity();
    }
     
    int main (int argc, char** argv)
    {
    	glutInit(&argc, argv);
    	glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGBA);
    	glutInitWindowSize (300, 200); 
    	glutInitWindowPosition (100, 100);
    	glutCreateWindow ("hello");
    	init ();
    	glutReshapeFunc (reshape);
    	glutDisplayFunc(display); 
    	glutMainLoop();
    	return 0;
    }

  4. #4
    Membre éclairé Avatar de MatRem
    Profil pro
    Inscrit en
    Décembre 2002
    Messages
    750
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2002
    Messages : 750
    Points : 693
    Points
    693
    Par défaut
    De rien ...
    En tout cas c'est bien que la fonction recherche soit utilisée et utile

    Sinon il peut être intéressant de désactiver l'utilisation d'un VBO à la fin de l'affichage :
    glBindBuffer(GL_ARRAY_BUFFER, 0);

    Et il est aussi intéressant d'utiliser le même VBO (avec glBufferSubData).

Discussions similaires

  1. [MFC] Plantage sur LoadFrame
    Par thieum74 dans le forum MFC
    Réponses: 11
    Dernier message: 06/09/2007, 13h15
  2. Plantage sur boutton.enabled
    Par ip203 dans le forum IHM
    Réponses: 2
    Dernier message: 15/06/2006, 15h04
  3. [firefox] plantage sur une url
    Par ggnore dans le forum Firefox
    Réponses: 2
    Dernier message: 12/05/2005, 22h06
  4. [DB2]Plantage sur COMMIT
    Par Dundee dans le forum DB2
    Réponses: 1
    Dernier message: 24/11/2004, 11h05
  5. [LG]plantage sur une commande basique !
    Par Jeff on the web dans le forum Langage
    Réponses: 5
    Dernier message: 13/01/2004, 19h07

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