Panda3D Manual: Text Fonts
<<prev | top | next>> |
Panda3D can render text using a variety of fonts. If your version of Panda3D has been compiled with support for the FreeType library (the default distribution of Panda3D has been), then you can load any TTF file, or any other font file type that is supported by FreeType, directly:
    font = loader.loadFont('arial.ttf')
The named file is searched for along the model-path, just like a regular egg file. You can also give the full path to the font file if you prefer (but remember to observe the Panda Filename Syntax). It is also possible to pre-generate a font with the egg-mkfont command-line utility:
    egg-mkfont -o arial.egg arial.ttf
This will generate an egg file (arial.egg in the above example) and an associated texture file that can then be loaded as if it were a font:
    font = loader.loadFont('arial.egg')
There are several options you can specify to the egg-mkfont utility; use "egg-mkfont -h" to give a list. The advantages to pre-generating a font are (a) the resulting egg file can be used by a version of Panda that does not include support for FreeType, and (b) you can apply some painterly effects to the generated texture image using Photoshop or a similar program. On the other hand, you have to decide ahead of time which characters you will want to use from the font; the default is the set of ASCII characters. There are three default font files supplied with the default distribution of Panda3D in the models subdirectory; these are "cmr12.egg", a Roman font, "cmss12.egg", a Sans-Serif font, and "cmtt12.egg", a Teletypewriter-style fixed-width font. These three fonts were generated from free fonts provided with the Metafont utility (which is not a part of Panda3D). There is also a default font image which is compiled into Panda if you do not load any other font.
<<prev | top | next>> |