# How to enable a vertex attribute array with VBOs?

**URL:** <https://community.khronos.org/t/how-to-enable-a-vertex-attribute-array-with-vbos/64480>\
**Category:** OpenGL: Advanced Coding\
**Created:** [May 4, 2011, 11:46am UTC](https://community.khronos.org/t/how-to-enable-a-vertex-attribute-array-with-vbos/64480 "2011-05-04T11:46:01Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![McLeary](https://community.khronos.org/letter_avatar_proxy/v4/letter/m/e9c0ed/32.png) [@McLeary](https://community.khronos.org/u/McLeary)\
**Post date:** [May 4, 2011, 11:46am UTC](https://community.khronos.org/t/how-to-enable-a-vertex-attribute-array-with-vbos/64480/1 "2011-05-04T11:46:01Z")

</div>

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:

```auto

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

```auto

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?

---

<div class="post-metadata">

**Author:** ![BionicBytes](https://community.khronos.org/user_avatar/community.khronos.org/bionicbytes/32/137_2.png) [@BionicBytes](https://community.khronos.org/u/BionicBytes)\
**Post date:** [May 4, 2011, 2:20pm UTC](https://community.khronos.org/t/how-to-enable-a-vertex-attribute-array-with-vbos/64480/2 "2011-05-04T14:20:45Z")

</div>

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

```auto

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

---

<div class="post-metadata">

**Author:** ![McLeary](https://community.khronos.org/letter_avatar_proxy/v4/letter/m/e9c0ed/32.png) [@McLeary](https://community.khronos.org/u/McLeary)\
**Post date:** [May 4, 2011, 2:26pm UTC](https://community.khronos.org/t/how-to-enable-a-vertex-attribute-array-with-vbos/64480/3 "2011-05-04T14:26:51Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![DarkGKnight](https://community.khronos.org/letter_avatar_proxy/v4/letter/d/aca169/32.png) [@DarkGKnight](https://community.khronos.org/u/DarkGKnight)\
**Post date:** [May 4, 2011, 3:09pm UTC](https://community.khronos.org/t/how-to-enable-a-vertex-attribute-array-with-vbos/64480/4 "2011-05-04T15:09:52Z")

</div>

Yes, you should remove glEnableClientState. As you can see in the [documentation](http://www.opengl.org/sdk/docs/man/xhtml/glEnableVertexAttribArray.xml), glEnableVertexAttribArray was introduced in OpenGL 2.0, thus it will work fine on the MacOSX.

---

<div class="post-metadata">

**Author:** ![arekkusu](https://community.khronos.org/user_avatar/community.khronos.org/arekkusu/32/66_2.png) [@arekkusu](https://community.khronos.org/u/arekkusu)\
**Post date:** [May 4, 2011, 7:02pm UTC](https://community.khronos.org/t/how-to-enable-a-vertex-attribute-array-with-vbos/64480/5 "2011-05-04T19:02:11Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![McLeary](https://community.khronos.org/letter_avatar_proxy/v4/letter/m/e9c0ed/32.png) [@McLeary](https://community.khronos.org/u/McLeary)\
**Post date:** [May 5, 2011, 9:35am UTC](https://community.khronos.org/t/how-to-enable-a-vertex-attribute-array-with-vbos/64480/6 "2011-05-05T09:35:14Z")

</div>

Ok, I’ll check.  
Thanks a lot.
