the Fiddler.'s picture

Progress: TexturePacker

The TexturePacker is a nice little tool that can pack small 2d textures inside a larger one. OpenTK will use this to pack font glyphs into video memory (see attached screenshot), but I'm considering to make it available in the public API as it can be useful in a lot of situations, like packing lightmaps, sprites or other 2d items.

The algorithm is simple (and not optimal - AFAIK packing is a NP-complete problem): it just uses a binary tree to partition the 2d texture into regions equal to the bounding box of the 2d item you want to place. If a region is too large, it splits it up. If it's too small it tries again somewhere else (or fails). All in all, this gives O(logn) insertion and access, but a simple dictionary can improve access to O(1). I still have to look for a way to replace existing glyphs (a simple LRU strategy should work well enough), but otherwise it works well enough.

On a sidenote, I've fixed the build issues in SVN, so check it out if you want to try the new GLControl and GameWindow code. Be warned that I haven't tested the change under Linux yet, so drop a line if it doesn't work.

Till next time!

GlyphTest.png75.91 KB