when you want to load a font in Allegro where does he look for the file?
And what's the difference between registering and loading a font?
when you want to load a font in Allegro where does he look for the file?
Wherever you tell it to look.
And what's the difference between registering and loading a font?
What do you mean by registering a font?
I don't know about registering fonts or anything, but here's something we've used in a few games that seems to work:
| 1 | BITMAP *font6x6; |
| 2 | |
| 3 | int fontHeight = 6; |
| 4 | int fontWidth = 6; |
| 5 | |
| 6 | int numLetters = 91; |
| 7 | |
| 8 | static unsigned char font6[numLetters * (fontHeight * fontWidth)] = { |
| 9 | /* Space */ |
| 10 | 0,0,0,0,0,0, |
| 11 | 0,0,0,0,0,0, |
| 12 | 0,0,0,0,0,0, |
| 13 | 0,0,0,0,0,0, |
| 14 | 0,0,0,0,0,0, |
| 15 | 0,0,0,0,0,0, |
| 16 | |
| 17 | /* Exclamation Point */ |
| 18 | 0,0,1,0,0,0, |
| 19 | 0,0,1,0,0,0, |
| 20 | 0,0,1,0,0,0, |
| 21 | 0,0,0,0,0,0, |
| 22 | 0,0,1,0,0,0, |
| 23 | 0,0,0,0,0,0, |
| 24 | |
| 25 | /* Quotation Mark */ |
| 26 | 0,1,0,1,0,0, |
| 27 | 0,1,0,1,0,0, |
| 28 | 0,0,0,0,0,0, |
| 29 | 0,0,0,0,0,0, |
| 30 | 0,0,0,0,0,0, |
| 31 | 0,0,0,0,0,0, |
| 32 | |
| 33 | ... |
| 34 | |
| 35 | /* Uppercase A */ |
| 36 | 0,1,1,1,0,0, |
| 37 | 1,0,0,0,1,0, |
| 38 | 1,0,0,0,1,0, |
| 39 | 1,1,1,1,1,0, |
| 40 | 1,0,0,0,1,0, |
| 41 | 0,0,0,0,0,0, |
| 42 | /* Uppercase B */ |
| 43 | 1,1,1,1,0,0, |
| 44 | 1,0,0,0,1,0, |
| 45 | 1,1,1,1,0,0, |
| 46 | 1,0,0,0,1,0, |
| 47 | 1,1,1,1,0,0, |
| 48 | 0,0,0,0,0,0, |
| 49 | |
| 50 | ... |
| 51 | }; |
| 52 | |
| 53 | |
| 54 | void getfont(void) |
| 55 | { |
| 56 | int currentLetter; |
| 57 | int letterWidth; |
| 58 | |
| 59 | unsigned char *ptr = font6; |
| 60 | |
| 61 | /* Set the color of this font to medium-gray */ |
| 62 | int color_gray[] = { 0, 9, 15 }; |
| 63 | |
| 64 | for (currentLetter = 0; currentLetter < (numLetters * fontHeight); currentLetter++) |
| 65 | for (letterWidth = 0; letterWidth < fontWidth; letterWidth++) |
| 66 | putpixel(font6x6, letterWidth, currentLetter, color_gray[(int) *ptr++]); |
| 67 | |
| 68 | } |
Here, the actual font that you'll use is the bitmap font6x6. Then you would simply use a function like this to actually write the letters onto the screen somewhere:
| 1 | void write(BITMAP *target, BITMAP *source, int x, int y, string text) |
| 2 | { |
| 3 | int currentLetter; |
| 4 | int temp; |
| 5 | |
| 6 | for (currentLetter = 0; currentLetter < text.length(); currentLetter++) |
| 7 | { |
| 8 | temp = text[currentLetter] - 32; |
| 9 | if (temp < 0) |
| 10 | temp = 0; |
| 11 | if (temp > numLetters) |
| 12 | temp = numLetters; |
| 13 | masked_blit(source, target, 0, temp * 6, currentLetter * 6 + x, y, |
| 14 | source->width, source->height); |
| 15 | } |
| 16 | } |
You call this with a simple writeFont(double_buffer, font6x6, x, y, some_string);
It's ugly, I know, but this is ONE way of creating your own custom font. You could take the same data, store it into a DAT file and save a lot more space, but this is just one example.
-TeamTerradactyl
"What do you mean by registering a font?"
register font file type :
void register_font_file_type(const char *ext, FONT *(*load)(const char
*filename, RGB *pal, void *param));
Another question were can I find fonts of the correct type?
Here, the actual font that you'll use is the bitmap font6x6. Then you would simply use a function like this to actually write the letters onto the screen somewhere:
Bloody hell. Next time, check the manual before you try to reinvent the wheel.
And what's the difference between registering and loading a font?
What the manual says it is:
FONT *load_font(const char *filename, RGB *pal, void *param);
Loads a font from a file.
void register_font_file_type(const char *ext, FONT *(*load)(const char *filename, RGB *pal, void *param));
Informs the load_font() functions of a new file type, providing a routine to read fonts in this format.
After registering the FONT type, you can use Allegro's normal load_font() function to load it.