c++qtopenglqtguiqvector3d

Draw points in OpenGL with QVector3D


I have a list of QVector3D, which is a list of points, I want to draw a list of points with glDrawArrays.

initializeGLFunctions();

glGenBuffers(2, vbo);
//the vertices 
QVector3D *vertices = &data[0];

glBindBuffer(GL_ARRAY_BUFFER, vbo[0]);
glBufferData(GL_ARRAY_BUFFER, data.size() * sizeof(QVector3D), vertices, GL_STATIC_DRAW);

glDrawArrays(GL_POINTS,??);

or what other method I can use to deal with this?


Solution

  • glBufferData(GL_ARRAY_BUFFER, data.size() * sizeof(QVector3D), vertices, GL_STATIC_DRAW);

    This is correct, but I would suggest to use more intelligent containers like QVector outside an then constData as follows:

    glBufferData(GL_ARRAY_BUFFER, data.size() * sizeof(QVector3D), myVector.constData(), GL_STATIC_DRAW);
    

    Here is another official example how to use glBufferData in the context of QVector3D:

    geometryengine.cpp Example File

    Here can you find another third-party example following the official example:

    FabScan100

    Then, you could write:

    glDrawArrays(GL_POINTS, 0, data.size());