Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Game Development
  4. OpenGL VBO
Qt 6.11 is out! See what's new in the release blog

OpenGL VBO

Scheduled Pinned Locked Moved Game Development
7 Posts 2 Posters 4.2k Views 1 Watching
  • 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.
  • S Offline
    S Offline
    Sleicreider
    wrote on last edited by
    #1

    hey,

    I'm working with VBO's and trying to understand why the following code works with std::vector<GLfloat> vertices
    and doesn't work with std::vector<GLfloat> vertices = new std::vector<GLfloat>();
    @
    std::vector<GLfloat> vertices;

    vertices.push_back(0.0f);
    vertices.push_back(0.0f);
    vertices.push_back(-2.0f);

    GLuint bufferID;

    glGenBuffers(1,&bufferID);
    glBindBuffer(GL_ARRAY_BUFFER,bufferID);
    glBufferData(GL_ARRAY_BUFFER,sizeof(float)*3,&vertices[0],GL_STATIC_DRAW);

    glVertexPointer(3,GL_FLOAT,0,BUFFER_OFFSET(0));
    glEnableClientState(GL_VERTEX_ARRAY);

    glPointSize(4);
    glDrawArrays(GL_POINTS,0,1);
    glDisableClientState(GL_VERTEX_ARRAY);
    glDeleteBuffers(1,&bufferID);
    @

    using new:

    @
    std::vector<GLfloat> *vertices2 = new std::vector<GLfloat>();

    vertices.push_back(0.0f);
    vertices.push_back(0.0f);
    vertices.push_back(-2.0f);

    GLuint bufferID;

    glGenBuffers(1,&bufferID);
    glBindBuffer(GL_ARRAY_BUFFER,bufferID);
    glBufferData(GL_ARRAY_BUFFER,sizeof(GLfloat)*3,&vertices2[0],GL_STATIC_DRAW);
    //also tried glBufferData(GL_ARRAY_BUFFER,sizeof(GLfloat)*3,vertices2,GL_STATIC_DRAW);
    glVertexPointer(3,GL_FLOAT,0,BUFFER_OFFSET(0));
    glEnableClientState(GL_VERTEX_ARRAY);

    glPointSize(4);
    glDrawArrays(GL_POINTS,0,1);
    glDisableClientState(GL_VERTEX_ARRAY);
    glDeleteBuffers(1,&bufferID);
    @

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      In the first case, you are giving the address of the first element of the vector in the second case since you have a pointer to a vector, you are giving the address of the vector itself.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • S Offline
        S Offline
        Sleicreider
        wrote on last edited by
        #3

        I also thought this could be the problem, but I don't know the solution how I get the adress of the vector element with *vector = new vector() version

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          You need to deference it first

          @&(*vector)[0]@

          But it looks like you are going in unknown territory. Why not simply use a QVector ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • S Offline
            S Offline
            Sleicreider
            wrote on last edited by
            #5

            I tried this one, but for

            @&vector->at(1)@
            and
            @&(*vector)[1]@

            i get the same address as output.

            I'm not using QVector because, it's a Non-QT Project

            1 Reply Last reply
            0
            • S Offline
              S Offline
              Sleicreider
              wrote on last edited by
              #6

              and if I use @&vector@ it's a different address than the both i posted above.

              1 Reply Last reply
              0
              • S Offline
                S Offline
                Sleicreider
                wrote on last edited by
                #7

                ok but @&vector[0]@
                is an different address,
                mby
                @ &vector->at(0) @
                (or
                @&(*vector)[0] @
                seem to be the same)
                will work in openlgl I'll try that
                but i think I alrdy tried &vector-at(0) and It didn't work, we'll see

                1 Reply Last reply
                0

                • Login

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