简体   繁体   中英

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?

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.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM