Advertisement

OpenGL and Spritesheets (2D game)

Started by September 27, 2013 05:49 PM
3 comments, last by Dragonsoulj 11 years, 4 months ago

I have been working on a 2D game using SDL for a while now and got to a point where I felt OpenGL would be needed for rotating sprites. I have been trying to learn it to get it implemented into the game, and I am having some trouble. What I am mainly wondering right now, is the best method of using sprites. Is it still best practice to have all my sprites on one sheet for multiple objects? Or have a separate sheet for each object.

Thank you!

It's better for performance to use a single texture for multiple objects. The industry term is "texture atlas".

+---------------------------------------------------------------------+

| Game Dev video tutorials -> http://www.youtube.com/goranmilovano | +---------------------------------------------------------------------+
Advertisement

I'd suggest moving to SFML if you are concerned with rotating sprites. It's graphics API runs on top of OpenGL, and all sprite manipulations (rotations, scaling, etc.) are done in HW. Check out the Sprite class in the SFML documentation for more details.

Good Luck!

My Gamedev Journal: 2D Game Making, the Easy Way

---(Old Blog, still has good info): 2dGameMaking
-----
"No one ever posts on that message board; it's too crowded." - Yoga Berra (sorta)

The theory behind this is that switching textures has its cost.

So when you have, let's say, a sheet for every object, then first you have to switch to sheet A, draw every instance of object A, then the same with sheet/object B, C, and so on. That's one texture switch for each object.

Now, if you merge sheets A, B, C, D into one single sheet, you just switch to your merged sheet, draw *lots* of instances, and then move on.

When merging sheets, keep in mind that depending on your target audience, GPUs have a limit on maximum texture size. On modern GPUs it's 8192x8192 or bigger, as far as I know. If you want to support older cards too, using 1024x1024 sheets is a nice bet. Also, rounding texture dimensions to powers of two is another good practice ( afaik ).

If you are going the SFML route, or wish to learn a bit more about Spritesheets: http://www.gamedev.net/page/resources/_/technical/game-programming/introduction-to-spritesheets-r2985

I advise at least taking a look at the link at the beginning of the article.

This topic is closed to new replies.

Advertisement