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. How to write 3D applications?
Forum Updated to NodeBB v4.3 + New Features

How to write 3D applications?

Scheduled Pinned Locked Moved Solved General and Desktop
21 Posts 2 Posters 6.0k 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by A Former User
    #9

    And now we put all that together and get this:

    my3dwidget.h

    #ifndef MY3DWIDGET_H
    #define MY3DWIDGET_H
    
    #include <QOpenGLWidget>
    #include <QOpenGLFunctions>
    #include <array>
    #include <QOpenGLShaderProgram>
    #include <QOpenGLBuffer>
    #include <QOpenGLVertexArrayObject>
    
    class My3dWidget
            : public QOpenGLWidget
            , protected QOpenGLFunctions
    {
        Q_OBJECT
    public:
        explicit My3dWidget(QWidget *parent = nullptr);
    
    protected:
        virtual void initializeGL() override;
        virtual void resizeGL(int w, int h) override;
        virtual void paintGL() override;
    
    private:
        std::array<float, 3 * 2> m_vertices = {{ // 3 vertices * 2 coordinates
            -0.75f, -0.75f, // vertex 1 : x, y
            -0.75f,  0.75f, // vertex 2 : x, y
             0.75f,  0.75f  // vertex 3 : x, y
        }};
    
        QOpenGLShaderProgram m_program;
        QOpenGLBuffer m_buffer;
        QOpenGLVertexArrayObject m_vao;
    };
    
    #endif // MY3DWIDGET_H
    

    my3dwidget.cpp

    #include "my3dwidget.h"
    
    My3dWidget::My3dWidget(QWidget *parent)
        : QOpenGLWidget(parent)
    {
    }
    
    void My3dWidget::initializeGL()
    {
        initializeOpenGLFunctions();
        glClearColor(0.0f, 0.0f, 1.0f, 1.0f); // blue
    
        m_program.addShaderFromSourceFile(QOpenGLShader::Vertex, ":/shaders/shader.vert");
        m_program.addShaderFromSourceFile(QOpenGLShader::Fragment, ":/shaders/shader.frag");
        m_program.link();
        m_program.bind();
    
        m_buffer.create();
        m_buffer.bind();
        m_buffer.allocate(m_vertices.data(), // pointer to first element of array
                          sizeof(m_vertices)); // size of array in bytes
    
        m_vao.create();
        m_vao.bind();
        m_program.enableAttributeArray(0); // vertex array at location 0
        m_program.setAttributeBuffer(0, // location 0
                                     GL_FLOAT, // elements of the array are of type GL_FLOAT (= float)
                                     0, // start at array position 0
                                     2, // number of elements per vertex (= x, y)
                                     0); // stride: densely packed (= no holes)
    
        m_vao.release();
        m_buffer.release();
        m_program.release();
    }
    
    void My3dWidget::resizeGL(int w, int h)
    {
        Q_UNUSED(w)
        Q_UNUSED(h)
    }
    
    void My3dWidget::paintGL()
    {
        glClear(GL_COLOR_BUFFER_BIT);
        m_program.bind();
        m_vao.bind();
        glDrawArrays(GL_TRIANGLES, 0, sizeof(m_vertices));
        m_vao.release();
        m_program.release();
    }
    

    End of tutorial.

    1 Reply Last reply
    2
    • P Offline
      P Offline
      parvizwpf
      wrote on last edited by A Former User
      #10

      very very thanks friend.
      so why i could not run qt 5 tutorial? link text
      what about GLUT? can i use glut commands in Qt?
      can i ask my questions if i had more on future?
      UPDATED:
      i can to run trent reed tutorial finally. of course in my laptop. but on my work pc not run. that get erros: link text

      [Edit: removed link, contains malware ~~ @Wieland]

      ? 1 Reply Last reply
      0
      • P parvizwpf

        very very thanks friend.
        so why i could not run qt 5 tutorial? link text
        what about GLUT? can i use glut commands in Qt?
        can i ask my questions if i had more on future?
        UPDATED:
        i can to run trent reed tutorial finally. of course in my laptop. but on my work pc not run. that get erros: link text

        [Edit: removed link, contains malware ~~ @Wieland]

        ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #11

        @parvizwpf said in How to write 3D applications?:

        very very thanks friend

        No worries. Please mark the thread as solved and vote-up the posts that were helpful.

        can i ask my questions if i had more on future

        Sure. Please start a new thread for each specific question.

        i can to run it of course in my laptop. but on my work pc not run. that get erros: link text

        The domain you linked to contains malware. Please use a different image hoster, e.g. http://postimages.org/

        1 Reply Last reply
        1
        • P Offline
          P Offline
          parvizwpf
          wrote on last edited by parvizwpf
          #12

          repaired error image link
          what about GLUT? can i use glut commands in Qt?
          whatever you help me to start opengl :-)))
          "vote-up the posts that were helpful." how?

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

            GLUT is old and stinks. You don't want to touch it.

            1 Reply Last reply
            1
            • P parvizwpf

              repaired error image link
              what about GLUT? can i use glut commands in Qt?
              whatever you help me to start opengl :-)))
              "vote-up the posts that were helpful." how?

              ? Offline
              ? Offline
              A Former User
              wrote on last edited by
              #14

              @parvizwpf said in How to write 3D applications?:

              "vote-up the posts that were helpful." how?

              see https://forum.qt.io/topic/71830

              1 Reply Last reply
              1
              • P Offline
                P Offline
                parvizwpf
                wrote on last edited by
                #15

                why? i see it in many web tutorials.

                ? 1 Reply Last reply
                0
                • P parvizwpf

                  why? i see it in many web tutorials.

                  ? Offline
                  ? Offline
                  A Former User
                  wrote on last edited by
                  #16

                  @parvizwpf said in How to write 3D applications?:

                  why? i see it in many web tutorials

                  because all these tutorials are outdated and written by n00bs

                  1 Reply Last reply
                  0
                  • P Offline
                    P Offline
                    parvizwpf
                    wrote on last edited by
                    #17

                    i can not see anything in your topic link.
                    how can i create a quote? i don't see it.
                    n00bs???? if those are n00bs ,so who am i?
                    do you tell me good tutorials ?

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


                      Edit: Oops, looks like you've been faster :-)

                      1 Reply Last reply
                      1
                      • P Offline
                        P Offline
                        parvizwpf
                        wrote on last edited by
                        #19

                        [????????]

                        1 Reply Last reply
                        0
                        • P parvizwpf

                          i can not see anything in your topic link.
                          how can i create a quote? i don't see it.
                          n00bs???? if those are n00bs ,so who am i?
                          do you tell me good tutorials ?

                          ? Offline
                          ? Offline
                          A Former User
                          wrote on last edited by A Former User
                          #20

                          but on my work pc not run.

                          Maybe your PC has a terribly outdated GPU or the driver has some problem.

                          do you tell me good tutorials ?

                          Actually I like Trent's tutorial for the Qt integration part. Anything else: get a book on GLSL.

                          P 1 Reply Last reply
                          0
                          • ? A Former User

                            but on my work pc not run.

                            Maybe your PC has a terribly outdated GPU or the driver has some problem.

                            do you tell me good tutorials ?

                            Actually I like Trent's tutorial for the Qt integration part. Anything else: get a book on GLSL.

                            P Offline
                            P Offline
                            parvizwpf
                            wrote on last edited by
                            #21

                            @Wieland
                            maybe. you right.
                            Good luck.

                            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