Tuesday, 25 February 2014

Allegro Fonts

The first thing you'll need to do is include the font files and the true type font (ttf) file.

#include<allegro5\allegro_ttf.h>
#include<allegro5\allegro_font.h>

Both modules need to be added to the program too.

al_init_font_addon();
al_init_ttf_addon();

Now you'll need to acquire a font file. I got mine from this website for free.
http://www.webpagepublicity.com/free-fonts.html
Once downloaded, put the ttf file in your assets folder of the program.

To load the font into the program you'll need the following a font pointer. The first argument is where you put the file location of the font file. The second argument is the size of the text and the third is for any flags.

ALLEGRO_FONT *font = al_load_font("Assets/Fonts/Airmole Shaded.ttf", 36, NULL);

To display the text on screen use the following function, using the font pointer as the first argument. Next is colour, x position and y position. Fifth is a flag to centralize the text, you could also use ALIGN_LEFT or ALIGN_RIGHT. Lastly, the message you want displayed.

al_draw_text(font, al_map_rgb(44, 117, 255), ScreenWidth / 2, ScreenHeight / 2, ALLEGRO_ALIGN_CENTRE, "HELLO");

No comments:

Post a Comment