default "font" in Allegro5
anto80

Hello all,
I'm trying to convert an Allegro 4.2 program into Allegro 5.
Is the default font (called 'font') still existing?
Thank you in advance.

Arthur Kalliokoski

Pretty sure there isn't, but using ttf fonts isn't hard.

#SelectExpand
1#include <allegro5/allegro_ttf.h> //true type font handling 2 3char ttf_filename[] = "DejaVuSans.ttf"; 4 5int main(int argc, char **argv) 6{ 7 yadda 8 yadda 9ALLEGRO_FONT *myfont; //Pointer to our True Type font 10ALLEGRO_COLOR white; //a color for text output 11 yadda 12 yadda 13 al_init_font_addon(); 14 al_init_ttf_addon(); 15 yadda 16 yadda 17 white = al_map_rgb(255,255,255); //set color values to match the names 18 19 myfont = al_load_font(ttf_filename,-28,0); //the negative sign means use 28 pixels high rather than 28 points (supposedly 72'nds of an inch) 20 if(!myfont) 21 { 22 error stuff 23 } 24 25//in render loop 26al_draw_textf(myfont,white,20.0,70.0,0,"cumulative frames %8u",frames);

Thomas Fjellstrom

It's not built in, but allegro distributes the old a4 font with the examples.

Look for 'examples/data/a4_font.tga'.

I wouldn't choose that font for anything these days. If you need a small fixed width font, there are many better ones to choose from.

anto80

I agree with you all:
- Using TTF is not hard (and well documented)
- It is possible to load the old a4 font (which is distributed as a bitmap)
but the thing I was trying to do was to display text without the need to use an external file (even if it is ugly)
Thanks anyway.

Arthur Kalliokoski
anto80 said:

display text without the need to use an external file

You might be able to include it into the executable as binary and use some sort of memfile function, but it's more work than I want to try.

Thomas Fjellstrom

You can convert the file to a C array, and feed that into a memfile as Arthur hinted at, then use the al_load_bitmap_f to "load" the image.

Arthur Kalliokoski

If you're using gcc, you could use this, for other compilers I don't know, but then you could use the NASM assembler with the %incbin directive along with the object format command line option needed so you can link it in like any other object file.

SiegeLord
Arthur Kalliokoski

A great big ODARN echos through the trailer park! I was searching for "default font" etc.

OTOH, 8x8 is too small to be reasonably legible for modern screen pitches.

SiegeLord

You could always scale it up using transformations, but in principle it's only meant to be used for debugging.

Thomas Fjellstrom

whups. I thought it wasn't there for some reason :(

anto80

Thanks again for all new replies.

Thread #613729. Printed from Allegro.cc