Hi,
It's my first post here so sorry if this is in the wrong place. I am currently trying to make a basic 2D game in c++ and opengl, to help familiarise myself with using opengl practically (putting it into an object orientated context). My current rendering system (which I implemented yesterday, so it is very easy to remove/modify) involves a 'Sprite' class which holds a position, a texture and a texture rectangle, and whenever one of these are modified, I generate the new vertex data:
GLfloat vertices[] = {
mPosition.x, mPosition.y, (mTextureRect.x)/mTexture->getWidth(), (mTextureRect.y)/mTexture->getHeight(),
mPosition.x + mTextureRect.width, (mTextureRect.x + mTextureRect.width)/mTexture->getWidth, mTextureRect.y/mTexture->getHeight()
//And so on for all 6 points (2 triangles) that make up the texture rectangle. (first two vertices are the position, second two are the UV coordinates).
}
and stick it in a VAO which the sprite owns. Basically this means that whenever the sprites position changes, I have to update the vertex array. The renderer class then just binds the vao, draws the texture and unbinds the vao.
Now this is working fine at the moment, but in terms of performance when I've got 30+ sprites on the screen which positions are constantly being updated, then I feel this method may be too slow. Another thing I don't like about this implementation is that the sprite has a position attribute, but without this I would have to update the VAO every draw call which kinda defeats the whole point. Obviously my implementation is nowhere near optimal, and I'm not looking for insane performance, but I feel like there are methods which are just as easy to implement yet would yield lots better performance.
What I'm asking is what alternative methods are there to rendering 2D sprites efficiently, and does anyone have any examples of 2D rendering systems (or 3D ones that are fairly simple - most 3D examples that I've looked at seem very complicated and way out of the scope of my little 2d game). Sorry if this isn't formatted right, in wrong place or doesn't really make sense, just ask if you need clarification on what I'm asking.
Thanks in advance