Advertisement

BMfont optimal space usage algorythm

Started by August 12, 2008 12:10 PM
2 comments, last by spookycat 16 years, 3 months ago
I want to apologize for posting this again here, i realise i sent you a email a few days ago, but i never got any answer or indication that it even reached you, so i decided to post this on the forum here: I really love your font utility, i'm using it to convert fonts for my game, but one thing has always been so amazing in it is that it uses availible space so well, it looks like a kind of efficient silhouette edge searching algorythm. I would really need something like this in my project to optimize space used by various sprites. For example my 2d actor sprites could be that way packed from 2048 * 2048 pixel grid aligned sprites to 1024*512 or even less!! The reason so much space is wasted is, because some sprites need wider area, and some need longer area, some are centered, while others are off-center. The area of each sprite is same as the biggest one.. so there really is awfully a lot of wasted space, not to mention when rendering the sprites, the GPU has to discard huge amout of transparent fragments around the actual shape in alpha test that the sprite would produce because there is so much wasted space around the sprites that are usually in use to display characters, and this is a major problem with fillrate on slower GPUs where most fragments still need to go thru alpha test just to discard them... To cut this short, i would like to consider a idea to create a utility that you could make, like your font generator, but one which takes a large TGA image separated into rows & columns, and repositons the sprites into actually used area with specified border / margins, taking into account transparency channel as well as RGB channels and generates a new optimal texture plus text output with data of sprites, such as sprite number (row major or column major numbering are availible), and in pixels: width, height, x offset in pixels relative to center, y offset in pixels relative to center, x offset in texture, y offset in texture & UV float coords. If you decide to build such a tool, i can send you images with sprites which you can use for testing, i believe this would be a really good tool that would come in real handy for a lot of people.

Projects: Top Down City: http://mathpudding.com/

Do a web search for "packing lightmaps". They use a similar concept.
Steve 'Sly' Williams  Monkey Wrangler  Krome Studios
turbo game development with Borland compilers
Advertisement
Quote: Original post by Sly
Do a web search for "packing lightmaps". They use a similar concept.


Those are usually using simple corner-stashing algorythms, bmfont has a lot more advanced algorythm.

Projects: Top Down City: http://mathpudding.com/

Quote: The algorithm is quite simple really.

1. Sort all the character images by height and width.
2. Add images to the texture from left-to-right as far to the top as possible.
3. If an image doesn't fit on the current line, move on to the next image.
4. Repeat steps 2 and 3 until no more images fit into the texture.
5. If there are more images, start a new texture and restart from step 2.


Thats how it was done.

This topic is closed to new replies.

Advertisement