Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Use of QOpenGLVertexArrayObject
Forum Updated to NodeBB v4.3 + New Features

Use of QOpenGLVertexArrayObject

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 1.2k Views 1 Watching
  • 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.
  • roroR Offline
    roroR Offline
    roro
    wrote on last edited by
    #1

    Hello,
    first of all, excuse my poor English...

    I'm programming with Qt and try to display different vehicles : car, plane, ship...
    I have a parent class 'Vehicle' and child classes : 'car', 'plane', 'ship'...
    Each member of class 'vehicle' has attributes for vertex, indexes, color, which enable me to define QOpenGLBuffer.
    'Vehicle' class also has an attribute QOpenGLVertexArrayObject.

    class Vehicle
    {
        public:
            Vehicle();
            QOpenGLVertexArrayObject* getVAO();
            void load(QOpenGLShaderProgram *m_program);
     
        protected:
            QOpenGLVertexArrayObject m_vao;
            QVector <QVector3D> m_vertices;
            QVector <QVector3D> m_color;
            QVector <int> m_indexes;
    };
    

    One widget enables me to display all these instances with OpenGL and has an attribute QOpenGLShaderProgram :

    class GLWidget : public QOpenGLWidget, protected QOpenGLFunctions
    {
        Q_OBJECT
     
    public:
        GLWidget();
        void initializeGL();
        void resizeGL(int width, int height);
        void paintGL();
     
    private:
        QOpenGLShaderProgram m_program;
        QVector <Vehicle> m_vehicles;
    };
    

    Unfortunately, despite my researches in OpenGL, C++ or Qt lessons, I don't know how to display 'Vehicle' instances from the Widget...

    I thought I could load in a vector 'm_vehicle' all the instances of the child classes of 'Vehicle', then thanks to a method 'displayVehicle(Vehicle m)' called for each element of the list, load each of the VAO in the shader :

    void GLWidget::displayVehicle(Vehicle m)
    {
        m.getVAO().bind();
        glDrawElements(GL_TRIANGLES, 10*3, GL_UNSIGNED_INT, 0);
        m.getVAO().release();
    }
    

    Unfortunately, it doesn't work...
    Is it the right way to do ?

    Thanks a lot to those who could help me !!!

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      Hi, and welcome to the Qt forum! Have a look at this example, it has everything you need.

      1 Reply Last reply
      1
      • roroR Offline
        roroR Offline
        roro
        wrote on last edited by
        #3

        Thanks for your welcome, and for your answer, but in this sample there is only one object to display, and the VAO and VBO are defined in the widget class. What if I have multiple objects from various classes ?

        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