I searched through the net and forum and I still can’t get it.
So, I was going to create my own 2D game based on OpenTK (OpenGL binding for C#, I tried ask there and i got no answer…)
My game is heavily depend on performance, it’s a musical game, the music will stay synchronize even the fps is stutter, however it require good and stable fps to make it playable, to accomplish this, I decide to create simple 2D Engine with VBO implementation.
However, it’s seems I doing it wrong, everything just works but it doesn’t so fast, the game consist with a lot of moving objects with some backgrounds (fyi, the game resolution is only 800x600), no 3D, just 2D objects.
I’m trying to handle 2D Rendering with VBO and avoid Shader for some reasons…
And here the classes that i created:
- VertexBufferObject, it has functions to create the buffer handle, uploading vertices and render them.
- Sprite, each instance of it has VertexBufferObject and Texture, the texcoord, position and transform of sprite may changed often during gameplay.
- Texture, it can be Texture Map/Atlas (Texture that contains lot of objects / animation of specific object) or Single Texture Object.
And here my questions:
What is best practice to initialize the VBO? Currently in my engine, when an instance of VBO is created, it create buffer handle, uploading empty data with amount of size of current Vertices, and upload the vertices data before it render (via glBufferSubData). if the vertices size is changed, it will upload whole vertices.
Is it good to have single instance VBO per sprite instance? or should i create single VBO instance with bunch of vertices to handle multiple sprites and update (update = modify the vertices when required and upload it to memory) the vertices before render each instance of sprite? or create VBO per unique texture?
When / Should I destroy and recreate VBO instance in certain situations? e.g: switching between scenes that need to load and drop some game contents.
What common errors when implementing VBO implementation? (especially 2D case)
Finally, can someone provide step by step the best way to implement this?
Sorry for my bad English
and thanks in advance!