Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 4 of 4

Thread: Problem with VBO

Hybrid View

  1. #1
    Junior Member Newbie
    Join Date
    Apr 2013
    Posts
    9

    Angry Problem with VBO

    Hey everybody,
    I've got a problem with the VBO in C++ (und Mac OS x Lion). First of all thats my code:
    Init:
    Code :
    float vertexBuffer[8] = {
            0.0F, 0.0F,
            0.0F, h,
            w, h,
            0.0F, h
        };
        unsigned int vertexIndices[4] = {
            0, 1, 2, 3
        };
     
        glGenBuffers(2, bufferId);
        glBindBuffer(GL_ARRAY_BUFFER, bufferId[0]);
        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferId[1]);
        glBufferData(GL_ARRAY_BUFFER, sizeof(vertexBuffer), vertexBuffer, GL_STATIC_DRAW);
        glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(vertexIndices), vertexIndices, GL_STATIC_DRAW);
    And render:
    Code :
    glBindBuffer(GL_ARRAY_BUFFER, bufferId[0]);
        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferId[1]);
        glEnableClientState(GL_VERTEX_ARRAY);
        glVertexPointer(2, GL_FLOAT, 8*sizeof(float), 0);
     
        glColor3f(1.0f, 1.0f, 1.0f);
        glDrawElements(GL_QUADS, 2, GL_UNSIGNED_INT, 0);
     
        glDisableClientState(GL_VERTEX_ARRAY);
        glBindBuffer(GL_ARRAY_BUFFER, 0);
        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
    Now the problem is it displays nothing. No error or sth like that. Can somebody please help me? Thanks
    Greedings,
    CookieSoft

  2. #2
    Advanced Member Frequent Contributor arekkusu's Avatar
    Join Date
    Nov 2003
    Posts
    783
    You've specified a stride between vertices of 8*sizeof(float) = 32 bytes. But your vertex data is tightly packed and actually has a stride of 2*sizeof(float) = 8 bytes.

    You've also drawn a QUAD with only two vertices, which is an incomplete primitive. You need four vertices per quad.

  3. #3
    Junior Member Newbie
    Join Date
    Apr 2013
    Posts
    9
    thx for the answer! But i tried it and it displays nothing... (By the way iam using glut if it helps)

  4. #4
    Junior Member Newbie
    Join Date
    Apr 2013
    Posts
    9
    ok i have the error the index array is wrong srry for the noob error vertexIndices must be 0, 2, 4, 6

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •