Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Most efficient way to use OpenGL for 2d games?

I've got a game engine I've written for the iPhone that uses OpenGL for drawing 2d sprites, backgrounds etc. I could have used Cocos2d, but I thought I'd learn more by writing my own. It works and seems to be fairly efficient, but running my game through the Instruments OpenGL profiler, it comes back with a lot of pointers for how to do things better, talking about VBO's and things like that.

Assuming my game just draws many 2d quads with different textures applied, what is the most efficient way to do this? Is it quicker to draw 2 triangles or a single quad? Aren't VBO's overkill for this or would they actually bring a performance improvement?

like image 630
GoatInTheMachine Avatar asked Jan 27 '26 18:01

GoatInTheMachine


1 Answers

Ok, I don't know about the real performance gain for simple quads. But if your "geometry" is static you get most out of display lists. They are quite simple to use and require almost no code change.

It is important to note that the most expensive operation are context switches. That is anything from binding a texture (very expensive) to changing the color (not so expensive). So the best thing you probably can do is render all sprites using one texture in one go.

If you have one big static level, you can draw the entire thing into a display list and only call that. There is to note that you still should try to optimize for context switches.

You should also invest some time in code that prevents trying to render things that are not visible. (Check that against the DL solution for the entire level.)

like image 59
rioki Avatar answered Jan 29 '26 09:01

rioki



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!