Vertex array objects

With openGL 3 came a few cool features most of these are pretty small and quick to learn, VAOs are among these, I really didn’t want to write a full fledged tutorial about it before, but seeing as I’m changing the format to promote shorter and more article like posts, it seemed like as good as place as any to start.

There hasn’t been that much written about the vertex_array_object extension, also there is some confusion on where to use it and how.
Simply put it couldn’t be simpler, it’s used to make the daily life of using VBOs easier and the code prettier, earlier you had to call these three functions for each buffer to set up rendering, normally that would be at least 3.

glEnableClientState
glBindBuffer
glTexCoordPointer

Now add a few ifs and other miscellaneous code and setting up a VBO can be quite a hassle, now you still have to write all that code but only once and you can keep it in one place and you can make that code easier still.

Now all you have to do is call this code segment
unsigned int vao;
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);

that’s it you’re done, now all you have to do is set it up once and each time you call glBindVertexArray(vao); those settings will be recalled, simple.
And when your done rendering call glBindVertexArray(0); so that you don’t accidentally overwrite it

So now rendering is a 3 line affair instead of about a page worth of code

glBindVertexArray(vao);
glDrawArrays(GL_TRIANGLES ,0, 12);
glBindVertexArray(0);

And now you have learned to use VAOs.


1 Comment

  • By Peter Wallström, May 4, 2010 @ 17:04

    -old comments-

    Comment by Jason on 2009:05:10 12:39
    I think it’s important to state the Vertex Array Objects are not shared over multiple contexts.

    Comment by alex on 2009:05:12 13:43
    Thank you for your tutorial. I’d be interested in seeing more tutorials like these that will bring the rest of us OpenGL1.1/OpenGL2.1 newbies up to speed on OpenGL3.1

    Comment by Overlord on 2009:05:12 23:31
    Thanks, yea i am working on that currently, OpenGL 3.0 in forward compatible mode is more complicated, they basically dropped stuff like, glColor, glVertexPointer, glRotatef, glTranslatef, glVertex3f and so on, it’s basically an entirely new way of doing things, first of all shaders are mandatory unless that is if black is your favorite color, next all translations are made by you by hand, which would be only slightly annoying if they would have kept the old glLoadMatrixf, naturally they didn’t.
    It’s definitely more powerful though but it’s gonna take a few days to dig trough.

Other Links to this Post

RSS feed for comments on this post. TrackBack URI

Leave a comment


WordPress Themes