How to use QOpenGLBuffer to render data?
-
Hey guys,
I'm porting some code to QT and I could need some help.
I want to create a VBO and render it as a linestrip.
In plain opengl I would:- glGenBuffers
- glBindBuffer
- glEnableClientState(GL_VERTEX_ARRAY)
- glBufferData to create a buffer
- fill data
- glInterleavedArrays
- glDrawArrays
Now to QT:
-
I created a QOpenGLBuffer:
m_vertexBuffer = new QOpenGLBuffer(QOpenGLBuffer::VertexBuffer);
m_vertexBuffer->create()
m_vertexBuffer->setUsagePattern(QOpenGLBuffer::DynamicDraw);
m_vertexBuffer->bind();
m_vertexBuffer->allocate(20 * sizeof(QVector2D)); //Lets use 20 fixed vertex here -
Fill buffer with some test-data
for (int i = 0; i < 20; i++) {
QVector2D vec;
vec.setX(i);
vec.setY(sin(i));
m_vertexBuffer->write(i * sizeof(QVector2D), &vec, sizeof(QVector2D));
} -
Now I need to display the data. How?
CU
mts -
Hi!
Are you using QWidgets or QtQuick? You wrote you would use glDrawArrays in plain opengl. Why don't you want to use it here?
-
I'm using QtQuick.
I tried using glDrawArrays, but I don't see anythingvoid NTestFboRenderer::render()
{
m_vertexBuffer->bind();
for (int i = 0; i < 20; i++) {
QVector2D vec;
vec.setX(i);
vec.setY(sin(i));
m_vertexBuffer->write(i * sizeof(QVector2D), &vec, sizeof(QVector2D));
}glColor4f(1, 0, 0, 1); glDrawArrays(GL_LINE_STRIP, 0, 20); m_vertexBuffer->release();
}
How do I tell opengl how to interpret my vertexbuffer?
I thought I can do it by glInterleavedArrays but can I interpret a QVector2D as GL_V2F ? -
I'm not an expert in the field. Maybe this example code can help you: https://qt.gitorious.org/qt/qtdeclarative/source/15e58df3386b5438f6ae114a51ad4a258085e70b:examples/quick/scenegraph/shared/logorenderer.cpp
The whole example can be found here: http://doc.qt.io/qt-5/qtquick-scenegraph-textureinthread-example.html