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 :

Impossible d'afficher mon triangle a l'écran OPENGL 4.1 GLM GLEW et GLFW


Sujet :

OpenGL

  1. #1
    Futur Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Septembre 2016
    Messages
    8
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 30
    Localisation : France, Gironde (Aquitaine)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Septembre 2016
    Messages : 8
    Points : 6
    Points
    6
    Par défaut Impossible d'afficher mon triangle a l'écran OPENGL 4.1 GLM GLEW et GLFW
    Bonjour, je viens vers vous pour avoir votre avis sur un petit soucis que j'ai..
    Je développe en ce moment un petit soft de visualisation de rendu 3D et j'ai un soucis avec simplement afficher un simple triangle..
    J'ai deja développé sous OPENGL auparavant mais je ne comprend pas d'ou peut venir mon problème..


    Voici les fonction de ma classe mesh que j'appel pour l'affichage du rendu :

    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
    void Mesh::init(Shader *_shader)
    {
      glGenVertexArrays(1,&_vao);
      glBindVertexArray(_vao);
     
      glGenBuffers(1,&_vbo);
      checkGLError();
      //bind des caracteristiques du mesh...
      glBindBuffer(GL_ARRAY_BUFFER,_vbo);
      checkGLError();
      //On donne nos données au VBO.
      glBufferData(GL_ARRAY_BUFFER, sizeof(vec3) * Vertices.size(), Vertices.data(), GL_STATIC_DRAW);
      checkGLError();
     
      int vertex_loc = _shader->getAttribLocation("V_position");
      std::cout << "vertex_loc = " << vertex_loc << std::endl;
      if(vertex_loc>=0)
      {
          glVertexAttribPointer(vertex_loc, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)0);
          glEnableVertexAttribArray(vertex_loc);
      }
     
      int color_loc = _shader->getAttribLocation("V_color");
      std::cout << "color_loc = " << color_loc << std::endl;
      if(color_loc>=0)
      {
          glVertexAttribPointer(color_loc, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)sizeof(vec3));
          glEnableVertexAttribArray(color_loc);
      }
     
      int normal_loc = _shader->getAttribLocation("V_normal");
      std::cout << "normal_loc = " << normal_loc << std::endl;
      if(normal_loc>=0)
      {
          glVertexAttribPointer(normal_loc, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)(2*sizeof(vec3)));
          glEnableVertexAttribArray(normal_loc);
      }
     
      if(vertex_loc>=0)
          glDisableVertexAttribArray(vertex_loc);
      if(color_loc>=0)
          glDisableVertexAttribArray(color_loc);
      if(normal_loc>=0)
          glDisableVertexAttribArray(normal_loc);
     
          glBindVertexArray(0);
     
      this->_ready = true;
     
    }

    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
    void Mesh::draw(Shader *_shader)
    {
     
        if(!_ready)
        {
          init(_shader);
          std::cout << "Initialisation du mesh terminer" << std::endl;
        }
     
        glBindVertexArray(_vao);
     
        glDrawArrays(GL_TRIANGLES, 0,3);
     
        glBindVertexArray(0);
     
     
    }
    Voici comment j'initialise mon screen et mon contexte OPENGL

    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
    bool S2Viewer::init()
    {
      /* Initialize the library */
        if (!glfwInit())
            return -1;
     
        // Set all the required options for GLFW
        glfwWindowHint (GLFW_CONTEXT_VERSION_MAJOR, 4);
        glfwWindowHint (GLFW_CONTEXT_VERSION_MINOR, 1);
        glfwWindowHint (GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
        glfwWindowHint (GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
        /* Create a windowed mode window and its OpenGL context */
        this->_S2viewer = glfwCreateWindow(this->_width,this-> _height, this->_nameScreen, NULL, NULL);
        if (!_S2viewer)
        {
            glfwTerminate();
            return 0;
        }
     
        /* Make the window's context current */
        glfwMakeContextCurrent(_S2viewer);
        glewExperimental = GL_TRUE;
        if(glew_init() == EXIT_FAILURE)
        {
          return 0;
        }
     
        return 1;
    }


    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
    void S2Viewer::runLoop()
    {
      /* Loop until the user closes the window */
      glClearColor(1.0, 1.0, 1.0, 0.0);
     
        while (!glfwWindowShouldClose(_S2viewer))
        {
          Shaders[0]->use();
          glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
          for (std::vector<Mesh*>::iterator mesh = Meshs.begin(); mesh < Meshs.end(); mesh++)
          {
              (*mesh)->draw(Shaders[0]);
          }
            glfwSwapBuffers(_S2viewer);
            glfwPollEvents();
            Shaders[0]->desactivate();
        }
        glfwTerminate();
    }

    et voici mon main.cpp :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    int main(int argc,char** argv)
    {
      std::cout << "Hello fuck**g World" <<std::endl;
      S2Viewer viewer;
      viewer.init();
      //initialisation des shaders et des mesh...
      Mesh mesh = Mesh("mesh");
      Shader shader(DATA_DIR"/data/shader/simple.vert",DATA_DIR"/data/shader/simple.frag");
     
      viewer.addMesh(&mesh);
      viewer.addShader(&shader);
     
      viewer.runLoop();
    }
    Mon problème de vient pas de mon shader (j'ai deja utilisé ma classe shader sur d'autre projet et elle fonctionne bien ... et plus vertex_loc =2, color_loc =1, et normal_loc = 0....
    )

    et quand j'execute mon programme l'écran s'affiche mais pas le triangle..

    Merci pour vos futurs réponse

  2. #2
    Expert éminent sénior

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

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

    Informations forums :
    Inscription : Juin 2005
    Messages : 2 031
    Points : 11 388
    Points
    11 388
    Billets dans le blog
    11
    Par défaut
    Salut !
    Le fond de ta fenêtre est noir ?
    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).

Discussions similaires

  1. Impossible d'afficher mon etat pdf dans ma page JSF
    Par hypoass dans le forum iReport
    Réponses: 0
    Dernier message: 07/06/2012, 18h25
  2. Impossible d'afficher mon tableau
    Par lechtinico dans le forum Langage
    Réponses: 18
    Dernier message: 04/01/2011, 16h43
  3. Impossible d'afficher mon image
    Par Olivier Regnier dans le forum Langage
    Réponses: 5
    Dernier message: 02/11/2007, 14h58
  4. [EasyPHP] impossible d'afficher mon site web depuis un autre PC
    Par bcd_30 dans le forum EDI, CMS, Outils, Scripts et API
    Réponses: 3
    Dernier message: 12/10/2007, 15h30
  5. [MySQL] Impossible d'afficher mon code
    Par Invité dans le forum PHP & Base de données
    Réponses: 11
    Dernier message: 21/09/2007, 13h33

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