Allegro provides text output routines that work with both monochrome and color fonts, which can contain any number of Unicode character ranges. The grabber program can create fonts from sets of characters drawn in a bitmap file (see grabber.txt for more information), and can also import GRX or BIOS format font files. The font structure contains a number of hooks that can be used to extend it with your own custom drawing code: see the definition in allegro/text.h for details.
See also: textout_ex, textprintf_ex.
Examples using this: Available Allegro examples.
/* Show unknown glyphs with an asterisk. */ allegro_404_char = '*';
See also: font.
int width = text_length(font, "I love spam"); ... bmp = create_bitmap(width, height);
See also: text_height.
Examples using this: ex12bit, exmidi, expat, exunicod.
int height = text_height(font); ... bmp = create_bitmap(width, height);
See also: text_length.
Examples using this: ex12bit, exmidi, expackf, expat, exsprite, exsyscur, exunicod.
/* Show the program's version in blue letters. */ textout_ex(screen, font, "v4.2.0-beta2", 10, 10, makecol(0, 0, 255), -1);
See also: font, textout_centre_ex, textout_right_ex, textout_justify_ex, textprintf_ex, text_height, text_length.
Examples using this: Available Allegro examples.
/* Important texts go in the middle. */ width = text_length("GAME OVER"); textout_centre_ex(screen, font, "GAME OVER", SCREEN_W / 2, SCREEN_H / 2, makecol(255, 0, 0), makecol(0, 0, 0));
See also: textout_ex, textprintf_centre_ex.
Examples using this: Available Allegro examples.
textout_right_ex(screen, font, "Look at this color!", SCREEN_W - 10, 10, my_yellow, -1);
See also: textout_ex, textprintf_right_ex.
char *lines[] = {"Draws justified text", "within the specified", "x2-x1 area. But not", "T H I S !", NULL}; /* Show the justification marker. */ vline(screen, 200, 0, SCREEN_H-1, makecol(0, 0, 0)); /* Draw all the lines until we reach a NULL entry. */ for (num = 0, y = 0; lines[num]; num++, y += text_height(font)) textout_justify_ex(screen, font, lines[num], 0, 200, y, 80, makecol(0, 0, 0), makecol(255, 255, 255));
See also: textout_ex, textprintf_justify_ex.
int player_score; ... textprintf_ex(screen, font, 10, 10, makecol(255, 100, 200), -1, "Score: %d", player_score);
See also: font, textout_ex, textprintf_centre_ex, textprintf_right_ex, textprintf_justify_ex, text_height, text_length, uszprintf.
Examples using this: Available Allegro examples.
textprintf_centre_ex(screen, font, SCREEN_W / 2, 120, makecol(0, 100, 243), -1, "Your best score so far was %d!", total_max_points);
See also: textprintf_ex, textout_centre_ex.
Examples using this: Available Allegro examples.
textprintf_right_ex(screen, font, SCREEN_W - 10, 10, makecol(200, 200, 20), -1, "%d bullets left", player_ammo);
See also: textprintf_ex, textout_right_ex.
Examples using this: exmouse.
char *lines[] = {"Line %02d: Draws justified text", "Line %02d: within the specified", "Line %02d: x2-x1 area. But not", "Line %02d: T H I S !", NULL}; /* Show the justification marker. */ vline(screen, 300, 0, SCREEN_H-1, makecol(0, 0, 0)); /* Draw all the lines until we reach a NULL entry. */ for (num = 0, y = 0; lines[num]; num++, y += text_height(font)) textprintf_justify_ex(screen, font, 0, 300, y, 180, makecol(0, 0, 0), makecol(255, 255, 255), lines[num], num);
See also: textprintf_ex, textout_justify_ex.