AL_GRAB_FONT_FROM_BITMAP(3)
β¨ NAME β¨
okay so bestie, this is al_grab_font_from_bitmap β the Allegro 5 API one, hanging out in the Library Functions Manual. It's giving "make a font out of a bitmap," and honestly? iconic. π
π¦ SYNOPSIS π¦
#include <allegro5/allegro_font.h>
ALLEGRO_FONT *al_grab_font_from_bitmap(ALLEGRO_BITMAP *bmp,
int ranges_n, const int ranges[])
π DESCRIPTION π
So this function creates a new font from an Allegro bitmap. And the bestie-coded part? You can delete the bitmap after the function returns, because the font will contain a copy for itself. No cap, it keeps its own little stash. π
π Parameters π
bmpβ the bitmap with the glyphs drawn onto it. That's the canvas, bestie.nβ number of unicode ranges in the bitmap. Yes, the signature saysranges_n, and the parameter list calls itnβ not me noticing the name switch-up, but that's literally what's written. πrangesβnpairs of first and last unicode point to map glyphs to for each range. So each range gets a first point and a last point, periodt.
πΈ Bitmap format πΈ
The bitmap format is as in the following example, which contains three glyphs for 1, 2 and 3. Obsessed with a visual aid.
.............
. 1 .222.333.
. 1 . 2. 3.
. 1 .222.333.
. 1 .2 . 3.
. 1 .222.333.
.............
In the above illustration, the dot is for pixels having the background color. It is determined by the color of the top left pixel in the bitmap. There should be a border of at least 1 pixel with this color to the bitmap edge and between all glyphs. So: top-left pixel is the background vibe-setter, and you need that at least 1-pixel border around the edge and between every glyph. π
Each glyph is inside a rectangle of pixels not containing the background color. The height of all glyph rectangles should be the same, but the width can vary. Slay for flexible widths, but the heights have to match.
The placement of the rectangles does not matter, except that glyphs are scanned from left to right and top to bottom to match them to the specified unicode codepoints. So don't stress the exact placement, but do respect the scan order β left to right, top to bottom. That's the main character energy of this whole matching process. β¨
The glyphs will simply be drawn using al_draw_bitmap(3), so usually you will want the rectangles filled with full transparency and the glyphs drawn in opaque white. Lowkey important: transparent rectangle, opaque white glyphs. That's the look.
β¨ Examples β¨
int ranges[] = {32, 126};
al_grab_font_from_bitmap(bitmap, 1, ranges)
int ranges[] = {
0x0020, 0x007F, /* ASCII */
0x00A1, 0x00FF, /* Latin 1 */
0x0100, 0x017F, /* Extended-A */
0x20AC, 0x20AC}; /* Euro */
al_grab_font_from_bitmap(bitmap, 4, ranges)
The first example will grab glyphs for the 95 standard printable ASCII characters, beginning with the space character (32) and ending with the tilde character (126). The second example will map the first 96 glyphs found in the bitmap to ASCII range, the next 95 glyphs to Latin 1, the next 128 glyphs to Extended-A, and the last glyph to the Euro character. (This is just the characters found in the Allegro 4 font.) Fr fr, those numbers are doing a lot of work, so keep them exactly as they are. π«Ά
π₯ SEE ALSO π₯
Cute little sign-off: this page is from the Allegro reference manual, and the footer is stamped al_grab_font_from_bitmap(3) β no date line is printed, so that's the whole footer vibe. Bye bestie, go make fonts ππ
π¦ where this page comes from
- arch rolling: allegro 5.2.11.3-2 Β· Zlib AND BSD-3-Clause AND OFL-1.1 AND LicenseRef-Custom
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms