Next: Blending and Depth Testing, Previous: Lines and Shapes, Up: Graphics [Contents][Index]
Unlike the traditional TrueType font format that many are accustomed to, Chickadee loads and renders bitmap fonts in the Angel Code format. But why use this seemingly obscure format? It’s easy to find TTFs but not easy to find FNTs (the canonical file extension used for Angel Code fonts) and bitmap fonts don’t scale well. The reason is efficiency.
If all of the glyphs of a font are pre-rendered and packed into an image file then it becomes possible to use a texture atlas (see Textures) and a sprite batch (see Sprites) when rendering, which is a more efficient way to render fonts than using, say, SDL_ttf or other solutions that involve using the FreeType library directly.
Now what about scaling? In libraries that use TTF fonts, one must
choose the size that the glyphs will be rasterized at up front. To
use n
sizes of the same font, one must load n
variants
of that font. If the size of the text is dynamic, some kind of
texture scaling algorithm must be used and the text will inevitably
look blurry. At first glance, using bitmap fonts seem to have an even
worse issue. Instead of just loading the same font n
times at
different sizes, one would need to generate n
image files for
each font size needed. This is where the “signed distance field”
rendering technique comes in. Introduced by
Valve in 2007, signed distance field fonts can be efficiently stored
in a bitmap and be rendered at arbitrary scale factors with good
results.
While Chickadee does not yet offer a tool for converting TTF fonts into FNT fonts, tools such as Hiero may be used in the meantime.
The following procedures can be found in the (chickadee render
font)
module.
Load the Angel Code formatted XML document in file and return a new font object.
Return #t
if obj is a font object.
Return the name of font.
Return the line height of font.
Return the line height of font.
Return #t
if font is a bold font.
Return #t
if font is an italicized font.
[#:origin] [#:scale] [#:rotation] [#:blend-mode]
[#:start 0] [#:end (string-length text)
]
Draw the string text with the first character starting at position using font.
(draw-text font "Hello, world!" (vec2 128.0 128.0))
To render a substring of text, use the start and end arguments.
Refer to draw-sprite
(see Sprites) for information about
the other arguments.
Next: Blending and Depth Testing, Previous: Lines and Shapes, Up: Graphics [Contents][Index]