• Advertisement
Sign in to follow this  

OpenGL and Spritesheets (2D game)

This topic is 1576 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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!

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement