2d Animation with VBO's

Okay So I am not quite sure how to go about this.
I want to be able to create a sort of animation system where a sprite changes texture.

I am thinking it could be done if you reloaded the texture into opengl and store in a vbo everytime you change frame, but that would be horribly inefficient.

I’m not really sure how to go about this…

Dont make the sprite change texture, use an texture atlas merging all frames into one image.
changing the frame of the animation will be the fastest with shaders.

I’m not very familiar with texture atlas’s
I don’t have a shader either, All the examples of shaders have been for 3d games. My game is only 2d.

its the same thing, but without the z.

the 3 main options you have are:

  • rebuild vbo each frame (using texture atlas, setting diffrent textcoords).
  • bind diffrent texture each frame (just bind the texture of the current frame).
  • use texture atlas with shaders, so you dont need to update the data each frame.

Could you please explain texture atlas’.
I don’t understand textures well enough to know how to implement them.

A texture atlas is just a big image that is split into smaller images. So, you could have a tile spritesheet that is, say, 512x512 pixels, and then you jut draw your textures in 16x16 little squares, for instance. Then you just create a bufferedimage and loop through the atlas and to pick a texture, you get the coordinates of the texture you need and then read the rgb data in that square. To get the texture you want, loop from coordinate x to x + width and y to y + height, and get the rgb values of each pixel.

The whole point of spritesheets is to reduce the number of images loaded. With a texture atlas, you only need to load the atlas and then you’re done unless you need a different atlas.

So would I store each subimage in a seperate bytebuffer, and then just store the bytebuffers and bind them everytime that subimage is used?

No, its just one image like this:

http://cdn2.planetminecraft.com/files/resource_media/screenshot/1215/texturefasdf_1976234.jpg

then instead of setting textcoord to 0f and 1f, you set the textcoord to “(1f / atlassize) * x” and “(1f / atlassize) * width”.

Yeah, I guess you could do it that way, although I dont think loading an image would be that expensive. I guess if you constantly change textures you should store them. But if you’re just changing them every couple minutes or never, its not worth the effort. Just make sure to sort your bind calls so you only bind each texture once!

Alright thankyou :slight_smile:
I’ll look into it a bit