2

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?

4

1 回答 1

3

glBufferData(GL_ARRAY_BUFFER, data.size() * sizeof(QVector3D), 顶点, GL_STATIC_DRAW);

这是正确的,但我建议在 constData 之外使用更智能的容器,如 QVector,如下所示:

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

这是另一个官方示例如何glBufferData在上下文中使用QVector3D

geometryengine.cpp 示例文件

在官方示例之后,您可以在此处找到另一个第三方示例:

FabScan100

然后,你可以写:

glDrawArrays(GL_POINTS, 0, data.size());
于 2014-04-11T02:21:46.603 回答