Sunday, 29 September 2013

Fastest way to implement a sprite

Fastest way to implement a sprite

I'm using PyOpenGL to implement a small 2D game engine. I'm hesitating on
the way I implement a Sprite class.
I'm already keeping all the scene (tiled map) in a VBO, and all textures
are kept in the same big texture. All the sprite's images are also in this
texture. So I suppose that, for performance, I should include the sprite
in the VBO, let say from position sprite_start_position.
The first question is : since a sprite can have several stances (images),
is it better to :
setting only one entry in the VBO for the sprite, and modifying the
texture coords in this entry accordingly to the stance, using
glBufferSubData
setting as many entries in the VBO as there are stances, but drawing only
the current one with glDrawArrays
other ?
The second is the similar with sprite position. Must I :
change the position of the right entry in the VBO with glBufferSubData
use some glTranslate before glDrawArrays(GL_QUADS, sprite_start_position, 1)
other ?
I'm relatively new to OpenGL and I still feel a little lost in this API...

No comments:

Post a Comment