Important: Please read the Qt Code of Conduct -

How can I translate this openGL functions to Qt?

  • 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?

    - 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
        // - 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
        glVertexAttribPointer(1, sizeof(QVector3D) / sizeof(GLfloat), GL_FLOAT, GL_FALSE, sizeof(PosNorm), ((GLubyte *)NULL + (sizeof(QVector3D))));
        glBufferData(GL_ARRAY_BUFFER, posNormPlane.size() * sizeof(PosNorm),, GL_STATIC_DRAW);


  • Lifetime Qt Champion


    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.

  • 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?

  • @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


    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?.

  • @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;

  • 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. 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.

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

  • 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?

    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.

  • @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!

Log in to reply