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 6 of 6

Thread: How to enable a vertex attribute array with VBOs?

  1. #1
    Junior Member Regular Contributor
    Join Date
    Nov 2010
    Location
    Brazil, Rio de Janeiro
    Posts
    147

    How to enable a vertex attribute array with VBOs?

    I'm trying to set a vertex attribute array using VBOs.
    The VBO is already set and now I'm with some doubts regarding how to enable my attributes array.

    Let's say that my VBO ID is bufferID and, to enable this array I do:

    Code :
    glBindBuffer( GL_ARRAY_BUFFER, bufferID );
    GLint loc = glGetAttribLocation( shader.getShaderProgram(), "inTriangleID" );
    glEnableClientState( GL_VERTEX_ARRAY );
    glEnableVertexAttribArray( loc );
    glVertexAttribPointer( loc, 1, GL_FLOAT, GL_FALSE, 0, NULL );

    My question is if after the call for glVertexAttribPointer I can bind another buffer to GL_ARRAY_BUFFER.

    After the above calls comes the rendering calls. Something like

    Code :
    glPushClientAttrib( GL_CLIENT_VERTEX_ARRAY_BIT );
    glBindBuffer( GL_ARRAY_BUFFER, mPositionVboID );
    glVertexPointer( mVertexSize, GL_FLOAT, 0, NULL );
    glEnableClientState( GL_VERTEX_ARRAY);
    glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, mEboID );
    glDrawElements( GL_TRIANGLES, mIndices->size(), GL_UNSIGNED_INT, NULL );

    As one can see, another buffer is bind to GL_ARRAY_BUFFER. This doesn't unbind the previous buffer, which was the vertex attrib buffer or does glPushClientAttrib saves the previous buffer?

    How is the correct way of set a vertex attribute array using VBOs?

  2. #2
    Senior Member OpenGL Pro BionicBytes's Avatar
    Join Date
    Mar 2009
    Location
    UK, London
    Posts
    1,171

    Re: How to enable a vertex attribute array with VBOs?

    You seem to be mixing old style and new style arrays which is not going to work.

    Code :
    glBindBuffer( GL_ARRAY_BUFFER, bufferID );
    GLint loc = glGetAttribLocation( shader.getShaderProgram(), "inTriangleID" );
    glEnableClientState( GL_VERTEX_ARRAY );
    glEnableVertexAttribArray( loc );
    glVertexAttribPointer( loc, 1, GL_FLOAT, GL_FALSE, 0, NULL );
    You can't have this line in there
    glEnableClientState( GL_VERTEX_ARRAY )
    As that is the old style vertex array.

    However your rendering code is correctly using the old style arrays so reuse those lines of code.
    ]

  3. #3
    Junior Member Regular Contributor
    Join Date
    Nov 2010
    Location
    Brazil, Rio de Janeiro
    Posts
    147

    Re: How to enable a vertex attribute array with VBOs?

    It is because I'm writting an application that needs to work both on Mac and PC. Since MacOSX does not support GLSL > 1.2 I need to use this old style method.

    But this piece of code is working. But, you're are saying that I just need to remove glEnableClientState?

  4. #4
    Intern Contributor
    Join Date
    Jan 2011
    Posts
    78

    Re: How to enable a vertex attribute array with VBOs?

    Yes, you should remove glEnableClientState. As you can see in the documentation, glEnableVertexAttribArray was introduced in OpenGL 2.0, thus it will work fine on the MacOSX.

  5. #5
    Advanced Member Frequent Contributor arekkusu's Avatar
    Join Date
    Nov 2003
    Posts
    676

    Re: How to enable a vertex attribute array with VBOs?

    glEnableVertexAttribArray has been around since OpenGL 1.3 (with ARB_vertex_program.) You don't need GLSL > 1.20.

    You should read the part of the spec that talks about VERTEX_ATTRIB_ARRAY_BUFFER_BINDING (the binding is copied when setting the pointer.)

  6. #6
    Junior Member Regular Contributor
    Join Date
    Nov 2010
    Location
    Brazil, Rio de Janeiro
    Posts
    147

    Re: How to enable a vertex attribute array with VBOs?

    Ok, I'll check.
    Thanks a lot.

Posting Permissions

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