Trouble understanding VBOs

I’m finally getting into the rendering of my MORPG, but I’m having a lot of trouble with learning how to use VBOs…

I just have a couple questions when it comes to VBOs:

First question: when I get to monsters/players and stuff, I will have many objects that all need to render the same texture/model/etc. However, they will all have different positions and such. As a result, do I need to create separate VBOs for every entity I have in the game, or is there a way to use a single VBO for the objects using the same texture/model/etc.? If so, how?

Second, how would I do animation with VBOs? Do I just have a VBO for each frame of the animation and iterate through them? Seems inefficient, but I don’t know…

What is a VBO? I’m not all that familiar with terminology.

Are you making a 2D, or 3D game?

‘Vertex buffer object’. The term is used in reference to OpenGL, although the same concept (and maybe the term as well) is used elsewhere as well.

This was just being discussed in another thread. A way to use the same VBO(s) and a single draw call for a large group of entities is to pre-transform the geometry. For 2-d games, where entity geometry tends to consist of simple quads, this is fairly straightforward. But, you mentioned animation with respect to VBOs, so maybe you have something else in mind. So as LukeD asked, maybe you could provide some more info on what you’re doing exactly.

It’s completely normal to upload data to a VBO each frame and only use it once. There’s a hint you can use while creating/uploading data to the VBO using glBufferData(), GL_STREAM_DRAW, just for this purpose.

It’s a 3D game, however it will have 2D graphics that are used in the GUIs. I’m trying to make a game similar to Runescape, if you know what that is.

What kind of animation are you doing? (E.g. keyframes, interpolated keyframes, skeletal, etc…)

I have no clue yet, I’ve never done animation before. I took up this project of mine because it’d be (and so far has definitely proven to be!) a great learning experience for me. Would you recommend a specific style? I was thinking I’d use Blender (I parse my models from blender .obj files) to create the animation, and then modify my parser to accommodate for Blender animation. I have no clue how I will go about this, but right now I just need to get VBOs sorted out. :slight_smile:

Here’s a possible starting point. (This is just what first comes to mind - others may offer different advice.)

  • Simple keyframe animation might be the simplest place to start, if you’re comfortable generating that sort of content. (Later you could look into interpolation if you want a smoother effect.)

  • Don’t worry about batching or grouping multiple meshes in the same VBO to begin with. Just use a separate VBO for each animation frame, and bind the correct one as needed, as you mentioned in your first post.

This would be a good start, and would allow you to get VBOs working without too much complexity.

Once you’ve got that working, there are some improvements you could make. First, even with no other changes, grouping draw calls by render state (textures, shaders, etc.) can be a worthwhile optimization even if the number of draw calls is the same, due to the reduced state changes. As for number of draw calls, unless you’re targeting limited platforms or will have many entities rendered each frame, you might be able to get away with no further batching (that is, each entity can still be a separate draw call).

You may find that a VBO per animation frame leaves you with a lot of VBOs, which can introduce both memory and performance overhead. To address this, you can store multiple meshes in a single VBO. Here’s the first thing I found on Google - no guarantees it’s a good reference (it’s a few years old), but those are the kinds of techniques you’d use, I think.

There are other more complicated approaches, but it seems like the above would be a good start (others may offer different suggestions though).

Edit: Note also that if the texture coordinates for all frames of an animation are the same, you can use a single VBO for the texture coordinates, and then one VBO per frame for the positions.