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 :
glBufferSubData
glDrawArrays
The second is the similar with sprite position. Must I :
glBufferSubData
glTranslate
before glDrawArrays(GL_QUADS, sprite_start_position, 1)
I'm relatively new to OpenGL and I still feel a little lost in this API...
You really shouldn't have to worry about performance for simple sprite based 2D game. Your graphics card is capable of rendering tens or hundreds of thousands of triangles per second (or more!) which is way more than you are likely to need.
Thus, it really doesn't matter much which method you choose to use for updating sprites. If you want to have animated sprites though, I recommend you look into 3D textures. They allow you to interpolate between animation frames, which makes your animations look even better!
As a side note, you mentioned using glTranslate
which is a function from OpenGL 1.x/2.x that has been removed from later versions of the API. I recommend that you try to use "modern OpenGL" (ie OpenGL 3.x/4.x). You can find plenty of information about the differences online. That said, it is still OK to use the older versions of the API if you have a specific reason for doing so, and if you do functions like glTranslate
will continue to work.