So basically this is my problem: I am creating a game that needs a texture for each object. Now I would use a sprite sheet but the textures are different sizes. I am using VBOs and I need to some how bind the correct textures when calling drawElements. Now I don't know what to do because I don't want to separate each class to its own VBO because that will just make it like 100+ VBO per level which isn't so efficient (or maybe it is?) Note this is a 2D game but I still want to make it efficient.

Maybe there is some thing I can do with shaders? I am using shaders...

So that is my question: What Do I Do?

Things I came up with:

  • Separate the classes to different VBOs (Easy but I am not sure if very efficient)
  • Use sprite sheets but have a really really big cellsize then just draw big quads with transparent backgrounds.. (Seems like a stupid idea :P)

Thats it.. So I hope you have ideas!

EDIT: I read some where its possible to have an attribute of which texture to use and pass it in as an element and then the fragment shaders use it.. If this is true I'd love if some one could describe it in more detail and add some examples.. (Also if you need to customize the fragment shader please tell me how because I dont know how to write shaders)


2 Answers 2


Based on my experience, you should go on with your VBO per class solution. I don't know whats your target platform, but any computer should be able to handle a couple thousand VBOs without problem, especially as you are talking about a 2D game, which is less likely to have many vertices. It depends on the usage and target platform tough.

But as a general rule, never optimize something that you haven't profiled to be a bottleneck, avoid premature optimization.


You say that you can't use a sprite sheet because the textures are different sizes. That doesn't really matter. You can use something called a texture atlas, where different sprite images are put together in a non-uniform manner. I've never used the technique myself, but here is a tool I found to put together a texture atlas.

Since you probably have too many sprites to fit on a single texture atlas, you should group together sprites that will show up with each other more commonly. You will still need to use multiple VBOs, one for each texture atlas, but it is more efficient than using one draw call per individual sprite.

  • \$\begingroup\$ I don't know which way to go, either your way or akaltar's way.. I want to the the easy route but make the game as mod-able as possible and as efficient as possible.. \$\endgroup\$ Jul 20, 2013 at 12:50
  • 1
    \$\begingroup\$ The easy route is akaltar's method, but as long as the sprite boxes are defined somewhere in data texture atlases are just as mod-friendly as other methods. This method will be more performant, however, which may or may not be important to you. \$\endgroup\$
    – jmegaffin
    Jul 20, 2013 at 12:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .