[SOLVED]Allocate QVector data in QOpenGLBuffer
-
Hello! Im tried allocate QVector data in QOpenGLBuffer but its not work. Why? Can i allocate QVector data in QOpenGLBuffer?
@QVector<QVector2D> points;
points.push_back(QVector2D(-0.90f, -0.90f));
points.push_back(QVector2D(0.85f, -0.90f));
points.push_back(QVector2D(-0.90f, 0.85f));
points.push_back(QVector2D(0.90f, -0.85f));
points.push_back(QVector2D(0.90f, 0.90f));
points.push_back(QVector2D(-0.85f, 0.90f));
m_vertexPositionBuffer.create();
m_vertexPositionBuffer.setUsagePattern(QOpenGLBuffer::StreamDraw);
if(!m_vertexPositionBuffer.bind())
{
qWarning()<<"Could not bind vertex buffer to the context";
return;
}
m_vertexPositionBuffer.allocate(points.constData(), points.length());@ -
-
Make sure that your OpenGL context is current at that point
-
The second argument to allocate() should be the actual size in bytes not the number of elements. E.g.
@
m_vertexPositionBuffer.allocate(points.constData(), points.length() * sizeof(QVector2D));
@- Make sure your vertex attribute data specification matches 2D vectors of floats.
-
-
This! :D thank you!
[quote author="ZapB" date="1393775844"]- The second argument to allocate() should be the actual size in bytes not the number of elements. E.g.
@
m_vertexPositionBuffer.allocate(points.constData(), points.length() * sizeof(QVector2D));
@[/quote]