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 :

Probleme OpenGL: pas de triangles affichés [OpenGL 3.x]


Sujet :

OpenGL

  1. #1
    Futur Membre du Club
    Homme Profil pro
    Analyste programmeur
    Inscrit en
    Août 2013
    Messages
    6
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Togo

    Informations professionnelles :
    Activité : Analyste programmeur
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Août 2013
    Messages : 6
    Points : 7
    Points
    7
    Par défaut Probleme OpenGL: pas de triangles affichés
    Salut tout le monde sur le forum !
    Bon voilà, il y a quelques jours, je me suis mis à visionner des tutos pour programmer avec l'API OpenGL !
    Mais, lorsque j'essais d'afficher des triangles avec les VBOs il ne ce passe rien, je ne comprend pas dutout, c'est pour ça que je demande de l'aide .
    Pour info les tutoriels viennent d'ici
    Fichiers attachés Fichiers attachés

  2. #2
    Membre actif Avatar de monwarez
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2009
    Messages
    144
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 30
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2009
    Messages : 144
    Points : 293
    Points
    293
    Par défaut
    Bonour, merci d'avoir mis les sources, ton problème viens d'un oublie de SDL_GL_SwapWindow(mWindow); (en tout cas en le mettant on voit un carré rose )
    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
     
    void MainGame::drawGame()
    {
         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) ;
         glClearDepth(1.0) ;
     
         glEnableClientState(GL_VERTEX_ARRAY) ;
     
         colorShader.use() ;
     
         m_sprite.Sprite_Draw() ;
     
         colorShader.unse() ;
         SDL_GL_SwapWindow(mWindow);
    }
    Autre remarque: lors de la lecture d'erreur pour le link, il ne faut pas détruire le program avant glGetProgramInfoLog
    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
     
    if(!infoLog){return ;}
     
            glGetProgramInfoLog(programID, infoLogLenth, &infoLogLenth, infoLog)     ;
            std::cout << "error "<< '\n';
            std::cout << infoLog << '\n' ;
            std::cout << __FILE__  << __LINE__ << '\n' ;
            std::cout << "Impossible de linker le Program !\n" ;
     
            delete [] infoLog ;
            glDeleteProgram(programID) ;
            glDetachShader(programID, vertexID) ;
            glDetachShader(programID, fragmentID) ;
            glDeleteShader(vertexID) ;
            glDeleteShader(fragmentID) ;
            return ;

  3. #3
    Futur Membre du Club
    Homme Profil pro
    Analyste programmeur
    Inscrit en
    Août 2013
    Messages
    6
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Togo

    Informations professionnelles :
    Activité : Analyste programmeur
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Août 2013
    Messages : 6
    Points : 7
    Points
    7
    Par défaut
    Merci pour ta réponse !
    J'ai corrigé les erreurs comme tu me les a indiquées, la fenetre s'ouvre avec une couleur de fond, mais le sprite n'est pas afficher
    Pour info, j'utilise Elementary OS et ma version de openGL est 3.0

  4. #4
    Membre actif Avatar de monwarez
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2009
    Messages
    144
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 30
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2009
    Messages : 144
    Points : 293
    Points
    293
    Par défaut
    J'ai trouvé
    il faut changer cette ligne : sprite.cpp ligne 74
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, vertice) ;
    par
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, 0) ;
    En effet lors de l'utilisation des VBO, le dernier argument est l'adresse dans le VBO, dans ton cas il n'y a qu'un seul tableau, donc l'adresse est 0.
    PS: pour le SDL_GL_SwapWindow je n'avais pas vu qu'il était dans la partie de gestion de fps que j'avais enlevé vu qu'il me manquait un fichier timer.hxx

  5. #5
    Futur Membre du Club
    Homme Profil pro
    Analyste programmeur
    Inscrit en
    Août 2013
    Messages
    6
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Togo

    Informations professionnelles :
    Activité : Analyste programmeur
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Août 2013
    Messages : 6
    Points : 7
    Points
    7
    Par défaut
    ça ne marche toujours pas ?
    Meme sur une autre distibution linux que j'ai mise en machine virtuel
    mais quand j'utilise glBegin() avec les fonctions glVertex*() et glEnd() pour déssiner, le triangle est bien affiché .

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    glBegin(GL_TRIANGLES) ;
            glColor3f(1.0, 1.0, 1.0) ;
            glVertex2f(0, 0) ;
            glVertex2f(0, 500) ;
            glVertex2f(500, 500) ;
        glEnd() ;
    Nom : Capture du 2016-09-04 21:50:08.png
Affichages : 201
Taille : 24,7 Ko

  6. #6
    Membre actif Avatar de monwarez
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2009
    Messages
    144
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 30
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2009
    Messages : 144
    Points : 293
    Points
    293
    Par défaut
    que donne un glxinfo ?
    Par exemple que donne: glxinfo | grep vertex_buffer_object ?
    Si cette commande ne retourne pas de texte, alors il ce peut que les Vertex Buffer Object ne soient pas supporté, dans ce cas il s'agit soit d'un problème de pilote, soit d'une carte/chipset graphique trop ancienne. Un ajout de ligne telle que
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    std::cout << "OpenGL Vendor: " << glGetString(GL_VENDOR) << std::endl;
    std::cout << "Version: " << glGetString(GL_VERSION) << std::endl;
    après la création de contexte peut être utile.
    Par ailleurs j'ai aussi changer le vertexShader en
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
     
    #version 130
     
    // in: variables en entrée provenant de OpenGL
    in vec2 position ;
     
    void main()
    {
    	gl_Position	=	vec4(position,0,1.0);
    }
    en pièce jointe les modifications faite, par ailleurs j'ai du commenter le timer à essayer avec et sans pour voir.
    Fichiers attachés Fichiers attachés

  7. #7
    Futur Membre du Club
    Homme Profil pro
    Analyste programmeur
    Inscrit en
    Août 2013
    Messages
    6
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Togo

    Informations professionnelles :
    Activité : Analyste programmeur
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Août 2013
    Messages : 6
    Points : 7
    Points
    7
    Par défaut
    voila la sorti de ta commande: GL_ARB_vertex_buffer_object, GL_ARB_vertex_program, GL_ARB_vertex_shader,
    j'ai insérertes bouts de code dans le mien, et la version de OpenGL sortie est 3.0 et glGetString(GL_VENDOR) donne Intel Open Source Technology Center
    j'ai tester ton code et ça fonctionne bien. Je vais le comparer avec le mien et voir ce que j'ai manqué !
    merci de ton aide

  8. #8
    Membre actif Avatar de monwarez
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2009
    Messages
    144
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 30
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2009
    Messages : 144
    Points : 293
    Points
    293
    Par défaut
    De rien, en fait j'avais aussi enlevé une partie qui est utilisée pour les vertex array object.
    Dans le fichier mainGame.hpp
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
     
    -    GLuint VertexArrayID;
    -    glGenVertexArrays(1, &VertexArrayID);
    -    glBindVertexArray(VertexArrayID);
    +    //GLuint VertexArrayID; 
    +    //glGenVertexArrays(1, &VertexArrayID);
    +    //glBindVertexArray(VertexArrayID);
    Pour les VAO il faut d'une part les créer, les bind , puis bind les VBO, puis utiliser glVertexAttribPointer ou équivalent, ainsi que glEnableVertexAttribArray ou équivalent.
    Enfin lors de la phase de rendu, il n'y a plus qu'à glBindVertexArray(VertexArrayID);Voici un exemple: phase d'initialisation (BUFFER_OFFSET est une macro qui transforme un entier en une adresse)
    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
     
    glGenBuffers(1,&VB);
     
    glGenVertexArrays(1,&VAO);
     
     
    // Vertex Array Object to OpenGL 3.2 core profile
    glBindVertexArray(VAO);
     
    	glBindBuffer(GL_ARRAY_BUFFER, VB);
    		glBufferData(GL_ARRAY_BUFFER, sizeof(Vertex) * vertices.size(), vertices.data(), GL_STATIC_DRAW);
     
    		glVertexAttribPointer(POSITION_LOCATION,3,GL_FLOAT, GL_FALSE,sizeof(Vertex), 0);
    		glVertexAttribPointer(TEX_COORD_LOCATION,2,GL_FLOAT, GL_FALSE,sizeof(Vertex), BUFFER_OFFSET(12));
    		glVertexAttribPointer(NORMAL_LOCATION,3,GL_FLOAT, GL_FALSE,sizeof(Vertex), BUFFER_OFFSET(20));
     
    		glEnableVertexAttribArray(POSITION_LOCATION);
    		glEnableVertexAttribArray(TEX_COORD_LOCATION);
    		glEnableVertexAttribArray(NORMAL_LOCATION);
     
    glBindVertexArray(0);
    phase d'affichage:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
     
    glBindVertexArray(entries.VAO);
    			auto 	materialIndex	=	entries.MaterialIndex;
     
    			if (materialIndex < m_Textures.size())
    			{
    				glBindTexture(GL_TEXTURE_2D, m_Textures[materialIndex].GetID());
    			}
    			glDrawElements(GL_TRIANGLES, entries.NumIndices, GL_UNSIGNED_INT, 0);
     
     
    glBindVertexArray(0);
    Voici un diff global:
    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
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
     
    diff --git a/GLSLProgram.cpp b/GLSLProgram.cpp
    index 8ee16d8..6ddd32f 100644
    --- a/GLSLProgram.cpp
    +++ b/GLSLProgram.cpp
    @@ -33,11 +33,6 @@ void GLSLProgram::linkShaders()
         glGetProgramiv(programID, GL_LINK_STATUS, &isLinked) ;
         if(isLinked != GL_TRUE)
         {
    -        glDeleteProgram(programID) ;
    -        glDetachShader(programID, vertexID) ;
    -        glDetachShader(programID, fragmentID) ;
    -        glDeleteShader(vertexID) ;
    -        glDeleteShader(fragmentID) ;
     
             /* Récupération des log */
             GLchar *infoLog = nullptr ;
    @@ -47,11 +42,17 @@ void GLSLProgram::linkShaders()
             if(!infoLog){return ;}
     
             glGetProgramInfoLog(programID, infoLogLenth, &infoLogLenth, infoLog) ;
    -        std::cout << infoLog << '\n' ;
    +        std::cout << "error "<< '\n';
    +		std::cout << infoLog << '\n' ;
             std::cout << __FILE__  << __LINE__ << '\n' ;
             std::cout << "Impossible de linker le Program !\n" ;
     
             delete [] infoLog ;
    +        glDeleteProgram(programID) ;
    +        glDetachShader(programID, vertexID) ;
    +        glDetachShader(programID, fragmentID) ;
    +        glDeleteShader(vertexID) ;
    +        glDeleteShader(fragmentID) ;
             return ;
         }
     
    @@ -59,7 +60,6 @@ void GLSLProgram::linkShaders()
         glDetachShader(programID, fragmentID) ;
     
     }
    -
     void GLSLProgram::addAttribute(const std::string &attributeName)
     {
         glBindAttribLocation(programID, numAtrrib, attributeName.c_str()) ;
    diff --git a/GLSLProgram.hpp b/GLSLProgram.hpp
    index 2f5b105..e90c008 100644
    --- a/GLSLProgram.hpp
    +++ b/GLSLProgram.hpp
    @@ -3,6 +3,7 @@
     
     #include <GL/glew.h>
     #include <iostream>
    +#include <string>
     
     class GLSLProgram
     {
    @@ -23,7 +24,6 @@ public:
     	void addAttribute(const std::string &attributeName) ;
         void compileShaders(const std::string &vertexShaderFilePath, const std::string &fragmentShaderFilePath) ;
         void linkShaders() ;
    -
         inline void use()
         {
     		glUseProgram(programID);
    diff --git a/mainGame.hpp b/mainGame.hpp
    index 358ead1..430bcc8 100644
    --- a/mainGame.hpp
    +++ b/mainGame.hpp
    @@ -6,7 +6,7 @@
     #include <SDL2/SDL.h>
     #include "sprite.hpp"
     #include "GLSLProgram.hpp"
    -#include "../../../Documents/2015-2016/C++/Game Programming/SDL2/Labo/essential/timer.hxx"
    +//#include "../../../Documents/2015-2016/C++/Game Programming/SDL2/Labo/essential/timer.hxx"
     
     #define RED			glColor3f(1.0f, 0.0f, 0.0f)
     #define GREEN		glColor3f(0.0f, 1.0f, 0.0f)
    @@ -32,7 +32,7 @@ private:
         GLSLProgram colorShader ;
     
         /*Un chrono pour la gestion des FPS*/
    -    Timer fps ;
    + //   Timer fps ;
     
         /* Le Gamestate*/
         GAMESTATE mstate ;
    @@ -73,7 +73,7 @@ public:
     } ;
     
     MainGame::MainGame(std::string label, int w, int h):
    -				   mLabel(label), width(w), height(h), m_sprite(), fps()
    +				   mLabel(label), width(w), height(h), m_sprite()
     {
         mWindow = nullptr ;
         glContext = nullptr ;
    @@ -121,9 +121,9 @@ bool MainGame::initSystems()
             return false ;
         }
     
    -    GLuint VertexArrayID;
    -    glGenVertexArrays(1, &VertexArrayID);
    -    glBindVertexArray(VertexArrayID);
    +    //GLuint VertexArrayID;
    +    //glGenVertexArrays(1, &VertexArrayID);
    +    //glBindVertexArray(VertexArrayID);
     
         // Attriubu pour activer opengl 3.1
         SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3) ;
    @@ -131,7 +131,7 @@ bool MainGame::initSystems()
         SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1) ;
     
         // Couleur de fond
    -    glClearColor(1, 0, 1, 0) ;
    +    glClearColor(1, 1, 1, 0) ;
     
         // Initialisation du shader
         initShader() ;
    @@ -141,7 +141,7 @@ bool MainGame::initSystems()
     
     void MainGame::initShader()
     {
    -    colorShader.compileShaders("/home/jordy/Codes Sources/Game OGL/OpenGL/vertexShader.vert" ,"/home/jordy/Codes Sources/Game OGL/OpenGL/fragmentShader.frag") ;
    +    colorShader.compileShaders("./vertexShader.vert" ,"./fragmentShader.frag") ;
         colorShader.addAttribute("position") ;
         colorShader.linkShaders() ;
     }
    @@ -154,10 +154,10 @@ void MainGame::drawGame()
         glEnableClientState(GL_VERTEX_ARRAY) ;
     
         colorShader.use() ;
    -
         m_sprite.Sprite_Draw() ;
     
         colorShader.unse() ;
    +	SDL_GL_SwapWindow(mWindow);
     }
     
     void MainGame::input()
    @@ -191,7 +191,7 @@ void MainGame::gameLoop()
                 SDL_GL_SwapWindow(mWindow) ;
                 //std::cout << "Frame: " << frame << '\n' ;
             }
    -        frame = (int) fps.Timer_GetTicks() ;
    +        //frame = (int) fps.Timer_GetTicks() ;
         }
     }
     
    @@ -202,7 +202,7 @@ void MainGame::run()
         std::cout << "OPENGL: " << glGetString(GL_VERSION) << " GLSL " << glGetString(GL_SHADING_LANGUAGE_VERSION) << '\n' ;
     
         /* Le conteur de FPS est activer*/
    -    fps.Timer_Start() ;
    +    //fps.Timer_Start() ;
     
     	m_sprite.Sprite_Init(-1.0f, -1.0f, 1.0f, 1.0f) ;
     
    diff --git a/sprite.cpp b/sprite.cpp
    index 1ef0ae5..8903104 100644
    --- a/sprite.cpp
    +++ b/sprite.cpp
    @@ -1,6 +1,5 @@
     #include <iostream>
     #include "sprite.hpp"
    -
     Sprite::~Sprite()
     {
         if(VBO)
    @@ -62,7 +61,7 @@ void Sprite::Sprite_Draw()
     
     	glEnableVertexAttribArray(0) ;
     
    -	glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, vertice) ;
    +	glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, 0) ;
     
     	glDrawArrays(GL_TRIANGLES, 0, 6) ;
     
    diff --git a/vertexShader.vert b/vertexShader.vert
    index c236b4c..f2677bc 100644
    --- a/vertexShader.vert
    +++ b/vertexShader.vert
    @@ -2,10 +2,7 @@
     
     // in: variables en entrée provenant de OpenGL
     in vec2 position ;
    -
     void main()
     {
    -	gl_Position.xy = position ;
    -	gl_Position.y = 0 ;
    -	gl_Position.w = 1.0 ;
    +	gl_Position	=	vec4(position,0,1.0);
     }

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Probleme PHP qui ne s'affiche pas
    Par somewere dans le forum 1&1
    Réponses: 4
    Dernier message: 12/12/2007, 17h37
  2. Trouver le probleme mais pas la soluce
    Par orphen dans le forum Mise en page CSS
    Réponses: 7
    Dernier message: 24/02/2007, 12h19
  3. [AJAX] Liste déroulante pour afficher les informations en ajax div ?
    Par rob2-9 dans le forum Général JavaScript
    Réponses: 13
    Dernier message: 17/11/2006, 09h06
  4. Sql Server Probleme Truncate / Pas Arrondi
    Par Nathan_2 dans le forum MS SQL Server
    Réponses: 1
    Dernier message: 02/05/2006, 19h09
  5. [C++.NET][DX9] pas moyen d'afficher un triangle
    Par NicolasG dans le forum DirectX
    Réponses: 13
    Dernier message: 02/01/2006, 15h55

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