Reputation: 33
I am trying to pack font glyph images into a single texture. The bitmaps are 1 byte per pixel monochromatic and I wish to pack them all together onto 1 texture. I am able to calculate the minimum texture size required but I am unable to manage an algorithm to packing them all together.
I currently have the bitmaps stored as char pointers and I am able to get the dimensions of each.
Upvotes: 2
Views: 1455
Reputation: 14467
Simple packing algorithm can be found here: http://www.blackpawn.com/texts/lightmaps/
It is called "Guillotine pack" in Jukka Jylänki's paper "A Thousand Ways To Pack the Bin".
The pseudo-code at blackpawn.com is really simple.
There are also related answers for similar questions: Piece together several images into one big image
Upvotes: 1
Reputation: 29199
I'm not an expert in bin packing, but here's a simple algorithm you may try.
This is known as Next-Fit Decreasing Height (NFDH) algorithm. An interactive demo can be seen here.
Since your glyphs are more or less the same height, I think this simple algorithm should give you good results.
Check out this survey for more algorithms.
Upvotes: 3