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 can I translate this openGL functions to Qt?
QtWS25 Last Chance

How can I translate this openGL functions to Qt?

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 3 Posters 983 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.
  • J Offline
    J Offline
    JesusM
    wrote on last edited by
    #1

    I have this piece of code. I know that to translate this code using the QOpenGLBuffer Class functions.
    My VAO, VBOs and IBOs are created with this class but when I have to fill them with data I am not sure how to do it. I saw in different examples that I have to use allocate to introduce data but I am using an intertwined array so I have to specified the offset of each part of the array and the allocate function doesn't allow me to do it. If I understood it well, with that function I intriduce the data and the size of the array, but that's all.
    How can I do it correctly?

    // 
        this->vaoPlane.bindVAO();
        this->vaoPlane.bindVBO(POSNORM);
    - Aquí se indica que uno de los elementos del array entrelazado va asociado con el layout (location=0) en el shader, en concreto la posición
        glEnableVertexAttribArray(0);
        // - Aquí se describen las características del puntero que permite a la GPU acceder a las posiciones
        glVertexAttribPointer(0, sizeof(QVector3D) / sizeof(GLfloat), GL_FLOAT, GL_FALSE, sizeof(PosNorm), ((GLubyte *)NULL + (0)));
    
        // - Como es un array entrelazado, hay que repetir el proceso para los demás elementos, en este caso para la normal
        glEnableVertexAttribArray(1);
        glVertexAttribPointer(1, sizeof(QVector3D) / sizeof(GLfloat), GL_FLOAT, GL_FALSE, sizeof(PosNorm), ((GLubyte *)NULL + (sizeof(QVector3D))));
        glBufferData(GL_ARRAY_BUFFER, posNormPlane.size() * sizeof(PosNorm), posNormPlane.data(), GL_STATIC_DRAW);
    
    

    Thanks

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      The first step I would use to port that kind of code base is using QOpenGLFunctions. You have access through it to the OpenGL methods you are currently using.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      J 1 Reply Last reply
      1
      • fcarneyF Offline
        fcarneyF Offline
        fcarney
        wrote on last edited by
        #3

        We need to see more of the code. I have no idea what PosNorm, posNormPlane, etc are defined as. It sounds like you are having issues with how to index data in a Qt object based structure?

        C++ is a perfectly valid school of magic.

        J 1 Reply Last reply
        0
        • SGaistS SGaist

          Hi,

          The first step I would use to port that kind of code base is using QOpenGLFunctions. You have access through it to the OpenGL methods you are currently using.

          J Offline
          J Offline
          JesusM
          wrote on last edited by
          #4

          @SGaist said in How can I translate this openGL functions to Qt?:

          he first step I would use to port that kind of code base is using QOpenGLFunctions. You have access through it to the OpenGL methods you are currently using.

          I see, I included

          #include <QOpenGLFunctions>
          #include <QOpenGLFunctions_4_1_Core>
          

          and I did this in the constructor, so now I can use these functions

          initializeOpenGLFunctions();
          

          My question now is that if I am using QOpenGLVertexArrayObject and QOpenGLBuffer, will this code work well with these classes instead of using functions like allocate?.

          1 Reply Last reply
          0
          • fcarneyF fcarney

            We need to see more of the code. I have no idea what PosNorm, posNormPlane, etc are defined as. It sounds like you are having issues with how to index data in a Qt object based structure?

            J Offline
            J Offline
            JesusM
            wrote on last edited by
            #5

            @fcarney
            PosNorm is a struct with a QVector3D (positions) and a QVector3D (normals).
            vao is a class that implements QOpenGLVertexArrayObject .

            QVector<PosNorm> posNormPlane;
            QVector<QVector2D> texturasPlane;
            QVector<QVector3D> tangentesPlane;
            QVector<GLuint> indicesPlaneNM;
            QVector<GLuint> indicesPlaneA;
             vao vaoPlane;
            
            1 Reply Last reply
            0
            • fcarneyF Offline
              fcarneyF Offline
              fcarney
              wrote on last edited by
              #6

              Internally the data in QVector3D is float v[3]; The returned size is 12 bytes. Each float is 4 bytes.

              QVector3D test;
              
              qInfo() << sizeof(test);
              

              So theoretically it should be similar to using just a raw array of floats for each point.
              posNormPlane.data() should point to the struct array. You could write a mem copy test function to see if things are really transferring data as expected. Write to your new structure, mem copy to an equivalent structure made of just an array of structs and test if it matches.

              C++ is a perfectly valid school of magic.

              J 1 Reply Last reply
              0
              • fcarneyF fcarney

                Internally the data in QVector3D is float v[3]; The returned size is 12 bytes. Each float is 4 bytes.

                QVector3D test;
                
                qInfo() << sizeof(test);
                

                So theoretically it should be similar to using just a raw array of floats for each point.
                posNormPlane.data() should point to the struct array. You could write a mem copy test function to see if things are really transferring data as expected. Write to your new structure, mem copy to an equivalent structure made of just an array of structs and test if it matches.

                J Offline
                J Offline
                JesusM
                wrote on last edited by
                #7

                @fcarney but this is not my problem. I just need to know if I can implement QOpenGLFunctions with the QOpenGLVertexArrayObject and QOpenGLBuffer

                1 Reply Last reply
                0
                • fcarneyF Offline
                  fcarneyF Offline
                  fcarney
                  wrote on last edited by fcarney
                  #8

                  How are you including the object in your class?
                  For using OpenGLFunction I had to make a class inherit from the functions specifically for OpengGL 3.3 to get all the 3.3 functions. So in the examples it usually shows something like this:

                  class MainWidget : public QOpenGLWidget, protected QOpenGLFunctions
                  

                  There should be a specific QOpenGLFunctions for the version of opengl you want to use. Replace it with that version. So for in your case:

                  class MainWidget : public QOpenGLWidget, protected QOpenGLFunctions_4_1_Core
                  

                  That "should" give you access to all the opengl functions from that version of the library.

                  Is this what you are looking for?

                  Edit:
                  Something that helped me a lot with opengl stuff in Qt is wading through the help files that come with Qt Creator. Exploring that and looking through their examples was really eye opening about how much stuff there is in Qt related to opengl stuff. There are lots of hidden things that can be hard to find that really make your life easier.

                  Just remember that any object that calls opengl functions must call that initializeOpenGLFunctions function for it. I had some issues where I was trying to encapsulate some things in classes and had to ensure that in that context the initializeOpenGLFunctions function had been called once.

                  C++ is a perfectly valid school of magic.

                  J 1 Reply Last reply
                  0
                  • fcarneyF fcarney

                    How are you including the object in your class?
                    For using OpenGLFunction I had to make a class inherit from the functions specifically for OpengGL 3.3 to get all the 3.3 functions. So in the examples it usually shows something like this:

                    class MainWidget : public QOpenGLWidget, protected QOpenGLFunctions
                    

                    There should be a specific QOpenGLFunctions for the version of opengl you want to use. Replace it with that version. So for in your case:

                    class MainWidget : public QOpenGLWidget, protected QOpenGLFunctions_4_1_Core
                    

                    That "should" give you access to all the opengl functions from that version of the library.

                    Is this what you are looking for?

                    Edit:
                    Something that helped me a lot with opengl stuff in Qt is wading through the help files that come with Qt Creator. Exploring that and looking through their examples was really eye opening about how much stuff there is in Qt related to opengl stuff. There are lots of hidden things that can be hard to find that really make your life easier.

                    Just remember that any object that calls opengl functions must call that initializeOpenGLFunctions function for it. I had some issues where I was trying to encapsulate some things in classes and had to ensure that in that context the initializeOpenGLFunctions function had been called once.

                    J Offline
                    J Offline
                    JesusM
                    wrote on last edited by
                    #9

                    @fcarney that's what I needed!.
                    I had :

                    protected QOpenGLFunctions
                    

                    but,as you said, some specific OpenGL functions are not there and I needed:

                    protected QOpenGLFunctions_4_2_Core
                    

                    to use them.

                    Thank you so much!

                    1 Reply Last reply
                    1

                    • Login

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