Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to use QOpenGLBuffer to render data?

How to use QOpenGLBuffer to render data?

Scheduled Pinned Locked Moved General and Desktop
openglvertexbufferqopenglbuffer
4 Posts 2 Posters 2.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    themts
    wrote on 9 Mar 2015, 22:45 last edited by
    #1

    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

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on 9 Mar 2015, 22:54 last edited by
      #2

      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?

      1 Reply Last reply
      0
      • T Offline
        T Offline
        themts
        wrote on 9 Mar 2015, 23:27 last edited by themts 3 Sept 2015, 23:30
        #3

        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 ?

        1 Reply Last reply
        0
        • ? Offline
          ? Offline
          A Former User
          wrote on 10 Mar 2015, 00:15 last edited by
          #4

          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

          1 Reply Last reply
          0

          2/4

          9 Mar 2015, 22:54

          • Login

          • Login or register to search.
          2 out of 4
          • First post
            2/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved