🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Code for building packed textures/texture sheets?

Started by
3 comments, last by hplus0603 2 years, 10 months ago

Does anyone know of some code (preferably C# although I will take C or C++) that can take a bunch of textures (which can have any width and height) and figure out the most efficient way to pack those textures into 1 or more larger textures? (which need to be a power of two in width/height). The textures (input and output) will be 32bpp RGBA data and I am flexible with what texture formats are being used.

Google hasn't found anything that is useful, NVIDIA has some stuff but it relies on the input textures being a power of 2 in width/height already.

Advertisement

Allow me to reference this SO post. What you're describing is also known as a texture atlas (or sprite bank)… Might help you in your searches.

@jonwil I have C# code that performs packing on sprites. I don't know how fast it is (I don't use it in a real time capacity). But you're welcome to take it and adapt it.

Gorgon/Gorgon/Gorgon.Renderers/Gorgon2D/Services at main · Tape-Worm/Gorgon (github.com)

There's a header only packing implementation in the nothings/stb library (made famous for stb_image):

https://github.com/nothings/stb/blob/master/stb_rect_pack.h

This library is nice, because you can just take a single header file, and drop it into your project, and it will work.

Well, one of the files that includes the header, needs to define the magic symbol, too, or you will get link errors. But still, very convenient! No installation, no link libraries, no platform specific files, …

enum Bool { True, False, FileNotFound };

This topic is closed to new replies.

Advertisement