As OpenGL requires that all textures put loaded by it need to be at a power of two this meant that the majority of our images needed to be stretched or squashed into a power of two texture which OpenGL would then resize to the correct size when drawing.
- An example of the stretched plug animation
That was when we came to Atlas Textures. I'd known about using atlas textures for a while but it was always the same thing of choosing between spending time going back and rewriting a bunch of code that worked already (for the most part) or writing new code for features of the game. The latter choice always won out but now that there were some real issues to be resolved we decided to spend the time to make it work properly.
If you don't know about atlas texturing the basic concept is to have one big texture that you put all of your various sprites and animations in, fitting them like a puzzle, and whenever you need to draw a specific sprite you only draw that section of the atlas texture.
The benefits of using this technique are twofold.
Firstly, you don't need to resize any of your sprites into textures of power of two as you can fit them into the atlas texture in their original form.
Secondly, the way OpenGL works is that it loads in each texture to the memory when it needs to draw it so therefore the more textures you have the more time OpenGL will spend swapping and loading in new textures each time the game draws. But if you use one atlas texture OpenGL just needs to load that one big texture at the start of the draw call and each sprite in the game will just draw it's own subsection from that texture. This can be a big performance boost in a sprite heavy game.
- Here is the (unfinished) atlas texture we are using for Call Connect
Whilst the static sprites made the change quite easily the animations required a bit more mathematical rejiggering and after a few "WTF why isn't this working!" moments I managed to get it working as smoothly as it was before. The visual improvement on the static sprites was noticable straight away and the animations looked better too. This blog post is being written after when the atlas texture was implemented and before all the textures have been swapped over to their atlas texture version (I was keen to write this down!) so we shall the overall improvement when that process is complete.
And even though we probably won't see a performance boost in Call Connect due to it's relatively simple nature - in terms of processing and sprite drawing - we have set ourselves up to be able to create much more system intensive games in the future.
So I guess what I'm saying is: Use atlas textures, they'll be worth it in the long run.
Oh and there's some handy tools out there like this flash Atlas Texture creation thingy which you can also download: http://zwoptexapp.com/