Summary
GameFontLib is a tool and small collection of source files that implement Chris Green's "Improved Alpha-Tested Magification for Vector Textures and Special Effects" for bitmapped fonts. This allows for fonts to scale freely, have outlines and shadows and remain hardware-renderer friendly. As the name implies, this library is designed for use in games.
Why?
There are two common ways to draw fonts in games, draw the font into a texture cache that's uploaded at run-time to the card and pre-render fonts into textures to draw from. The texture cache allows for any sized fonts and any symbols but texture updates are slow. A bitmapped font is very fast to draw but cannot be scaled, you're stuck with what was pre-drawn.
GameFontLib pre-draws the font into a texture in a way that allows for scaling the font while keeping its outline linear. The nature of the stored texture also allows for rendering outlines and blurred shadows at runtime without changing the texture or the vertex buffer. The string's vertex buffer is created once and with that and a few shader constants you can draw it at any size with any effect without changing the data on the video card.
What's the drawback? Memory. 255 glyphs take approximately 1MB of video RAM and 20KB of CPU RAM. I believe this compares favorably with the other methods, you can use less texture space for both the cache and bitmapped method because the linear font can be scaled to any size (8 pixels to 128 pixels, higher with loss in accuracy).
Status
95% complete and currently Beta, the following features are complete (not a full list):
- The tool can create linear font data files and textures.
- Supports common command line options (font name, output name, character ranges, characters from text file).
- Demo implemented with sample OpenGL renderer.
- Antialiasing, borders, shadows for linear fonts.
Tasks still open:
- Fix fonts with more than one texture - tool properly exports them, demo does not correctly implement the renderer.
- Port to Windows/DirectX - verify endian issues have been addressed, give sample D3D implementation.
- Support spaces in between glyphs in texture - not required for linear glyphs, necessary for bitmap glyphs.
- Add bitmap font rendering to demo - tool exports them, just need to verify output via the demo.
- Track down empty glyphs in texture - Some empty glyphs are being exported into the font texture, they need to be removed.
- Code review - Do all files have MIT license? Is everything documented enough? Is there any crufty code leftover?
- Finish this web page - Yeah, this is pretty bare bones.
I expect this project to be Final by mid-April at the earliest, end of May at the latest.
Samples
Samples of the rendering output are available. Once GameFontLib is complete a compiled version of the demo will be available for Windows and Mac OS X.
Source Code
You can download the current source code and try it out for yourself. Warning: I have not tried to compile it on any other machine yet, I cannot guarantee that it will work for you.
Feedback
Please contact me at ian.c.bullard@gmail.com with any feedback you have. Thank you.