Creating and using fonts, ClanLib API overview
Step 1: drawing the letters in a bitmap You need to use a 256 color bitmap.
You may draw the letters in any order, but keep in mind that colors with indexes
253, 254, 255 are reserved. A typical font would look like this: color255color255color255
c c c c o * o* o* * o l * * l* l** ** l o * * o* o* * * * o r******* r* r* *
* * r 2* * 2* 2* * * 2 5* * 5* 5* * 5 4* * 4* 4* * 3 color255color255color255
c c c o ** o * o l* * l** l o* * o * o r* * r * r 2* * 2 * 2 5* * 5 * 5 4 **
4*** 4 color255colo From this, on can deduce the following rules: - color 255
is used as an "horizontal delimiter" - color 254 is used as a "vertical delimiter"
- color 253 is used as a "carriage return", when one needs to define a font
on several lines. Here's the meaning of the different fields: - "type=font"
: tells the datafile compiler we're defining a font - "x=1, y=1" : defines the
top left pixel of your font. - "tcol=0" : color for transparency - "spacelen=6"
: any letter which you have not defined will be replaced by a blank space of
"spacelen" pixels. - "letters=AIM01" : tells the datafile compiler which letters
you have defined. This is an important feature, since you don't have to redefine
224 caracters if you only need 40 of them 8-) Step 3: loading the font at runtime
To load the font in your program, you can use the following C++ code:
CL_ResourceManager *manager; CL_Font *font; manager=CL_ResourceManager::create("test.scr",true);
font=CL_Font::load("mainfont",manager); -->
|