Table of Contents
- Initializing Allegro
- Keyboard Input
- Drawing Graphics
- Playing Sound
- Drawing Text
- Regulating FPS
- Enumerations and Random Numbers
- Bounding Box Collision Detection
- Planning the Game
- Super Basic Game Structure
- Wrapping up
Part 6 – Drawing Text
In Allegro, drawing text to the screen is very easy. All you have to do is call one function and it draws it out for you. However, in SDL, you have to render text to a surface on your own.
Allegro textprintf functions
From the Allegro Quick Reference…
textprintf_ex(bmp, font, x, y, color, -1, string, …); textprintf_centre_ex(bmp, font, x, y, color, -1, string, ...); textprintf_right_ex(bmp, font, x, y, color, -1, string, ...);
Each of these aligns a little different. Centre will draw the center of your string of text at your x, y coordinates. In your string, you can have a %f, %i, or %s placeholder, and then include a variable name as another parameter, like this:
textprintf_ex(buffer, font, 0, 0, makecol( 255, 255, 255 ), -1, “%s score: %i, %f mph”, player.name, player.score, (float)(player.score/totalGameTime) );
If you want to use the default font, keep “font” as the font parameter. This outputs an 8x8px font.
For the color parameter, you’ll use the function:
Where r, g, and b are from 0 to 255.
The -1 parameter is the background color. Keep this as -1 if you want it to be transparent.
© Rachel J. Morris, 2009