Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Game Development
  4. Multiple Vertex Array Objects
Qt 6.11 is out! See what's new in the release blog

Multiple Vertex Array Objects

Scheduled Pinned Locked Moved Unsolved Game Development
qtopenglvertex buffervertexarrayvaovbo
2 Posts 1 Posters 2.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sinanmut
    wrote on last edited by
    #1

    Hi,

    I am quite new in using QT and QTOpenGL. I want to render multiple objects with Vertex Array Objects. I create multiple VAO objects but it always renders the first one, and I see the other ones as only one dot.

    Vertex array objects are created in an update function as:


        std::shared_ptr<QOpenGLVertexArrayObject> new_PC_VAO = std::make_shared<QOpenGLVertexArrayObject>();
        std::shared_ptr<QOpenGLBuffer> new_PC_VBO = std::make_shared<QOpenGLBuffer>();
        new_PC_VAO->create();
        new_PC_VAO->bind();
        
        bool created = new_PC_VBO->create();
        if(created==false){
            std::cout<<"ERROR - Vertex Buffer Object Couldn't created!!!" << std::endl;
            exit(1);
        }
        new_PC_VBO->bind();
        new_PC_VBO->setUsagePattern(QOpenGLBuffer::StaticDraw);
        
        v_VAO.push_back(new_PC_VAO);
        v_VBO.push_back(new_PC_VBO);
        
        new_PC_VBO->allocate( new_data.constData(), new_data.size() * sizeof(GLfloat));
        
        QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions();
        f->glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat), 0);
        f->glEnableVertexAttribArray(0);
        
        f->glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat), (GLvoid*)(3 * sizeof(GLfloat)));
        f->glEnableVertexAttribArray(1);
       
        f->glBindBuffer(GL_ARRAY_BUFFER, 0);
        
        new_PC_VBO->release();
        new_PC_VAO->release();
        
        this->v_NumVert.push_back( m_logo.vertexCount() );
    

    Then in the GLWidget::paintGL() function after binding the shaders and setting the uniforms in the shaders:


    void GLWidget::paintGL() {
    //..................................
    QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions();
    ..........................
    for(int i=0; i<this->v_VAO.size(); i++) {
    this->v_VAO[i]->bind();
    f->glDrawArrays(GL_POINTS, 0, v_NumVert[i]);
    v_VAO[i]->release();
    f->glBindBuffer(GL_ARRAY_BUFFER,0);
    }

    ///.....................................

    m_program->release();
    context()->swapBuffers(context()->surface());

    }


    I tried the same idea with standard openGL, it works, but I don't understand what is different in QT pipeline.
    Any idea for the the solution will be a great help.
    Best,

    S 1 Reply Last reply
    1
    • S sinanmut

      Hi,

      I am quite new in using QT and QTOpenGL. I want to render multiple objects with Vertex Array Objects. I create multiple VAO objects but it always renders the first one, and I see the other ones as only one dot.

      Vertex array objects are created in an update function as:


          std::shared_ptr<QOpenGLVertexArrayObject> new_PC_VAO = std::make_shared<QOpenGLVertexArrayObject>();
          std::shared_ptr<QOpenGLBuffer> new_PC_VBO = std::make_shared<QOpenGLBuffer>();
          new_PC_VAO->create();
          new_PC_VAO->bind();
          
          bool created = new_PC_VBO->create();
          if(created==false){
              std::cout<<"ERROR - Vertex Buffer Object Couldn't created!!!" << std::endl;
              exit(1);
          }
          new_PC_VBO->bind();
          new_PC_VBO->setUsagePattern(QOpenGLBuffer::StaticDraw);
          
          v_VAO.push_back(new_PC_VAO);
          v_VBO.push_back(new_PC_VBO);
          
          new_PC_VBO->allocate( new_data.constData(), new_data.size() * sizeof(GLfloat));
          
          QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions();
          f->glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat), 0);
          f->glEnableVertexAttribArray(0);
          
          f->glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat), (GLvoid*)(3 * sizeof(GLfloat)));
          f->glEnableVertexAttribArray(1);
         
          f->glBindBuffer(GL_ARRAY_BUFFER, 0);
          
          new_PC_VBO->release();
          new_PC_VAO->release();
          
          this->v_NumVert.push_back( m_logo.vertexCount() );
      

      Then in the GLWidget::paintGL() function after binding the shaders and setting the uniforms in the shaders:


      void GLWidget::paintGL() {
      //..................................
      QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions();
      ..........................
      for(int i=0; i<this->v_VAO.size(); i++) {
      this->v_VAO[i]->bind();
      f->glDrawArrays(GL_POINTS, 0, v_NumVert[i]);
      v_VAO[i]->release();
      f->glBindBuffer(GL_ARRAY_BUFFER,0);
      }

      ///.....................................

      m_program->release();
      context()->swapBuffers(context()->surface());

      }


      I tried the same idea with standard openGL, it works, but I don't understand what is different in QT pipeline.
      Any idea for the the solution will be a great help.
      Best,

      S Offline
      S Offline
      sinanmut
      wrote on last edited by sinanmut
      #2

      @sinanmut When I create the 3D objects in the initializeGL function, it is fine paintGL function renders these objects. Later on when I want to add new objects to the scene I don't see these new ones being rendered by painGL function. Is there any flag that I have to add in paintGL fuinction or in initializeGL function?
      Thanks,

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved