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:

    1. glGenBuffers
    2. glBindBuffer
    3. glEnableClientState(GL_VERTEX_ARRAY)
    4. glBufferData to create a buffer
    5. fill data
    6. glInterleavedArrays
    7. glDrawArrays

    Now to QT:

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

    2. 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));
      }

    3. Now I need to display the data. How?

    CU
    mts


  • Moderators

    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 anything

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


  • Moderators


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.