Wednesday, March 25, 2026
Generated font in C
/* ── draw a simple bitmap title string (3×5 pixel font, ASCII 32-90) ────────
This tiny font avoids the SDL_ttf dependency entirely. */
static const Uint8 FONT3x5[][5] = {
{0x00,0x00,0x00,0x00,0x00}, /* ' ' */
{0x40,0x40,0x40,0x00,0x40}, /* '!' */
{0xA0,0xA0,0x00,0x00,0x00}, /* '"' */
{0xA0,0xE0,0xA0,0xE0,0xA0}, /* '#' */
{0x60,0xC0,0x60,0xC0,0x60}, /* '$' – placeholder */
{0x80,0x20,0x40,0x80,0x20}, /* '%' – placeholder */
{0x40,0xA0,0x40,0xA0,0xC0}, /* '&' – placeholder */
{0x40,0x40,0x00,0x00,0x00}, /* '\'' */
{0x20,0x40,0x40,0x40,0x20}, /* '(' */
{0x80,0x40,0x40,0x40,0x80}, /* ')' */
{0xA0,0x40,0xE0,0x40,0xA0}, /* '*' */
{0x00,0x40,0xE0,0x40,0x00}, /* '+' */
{0x00,0x00,0x00,0x40,0x80}, /* ',' */
{0x00,0x00,0xE0,0x00,0x00}, /* '-' */
{0x00,0x00,0x00,0x00,0x40}, /* '.' */
{0x20,0x20,0x40,0x80,0x80}, /* '/' */
{0x60,0xA0,0xA0,0xA0,0x60}, /* '0' */
{0x40,0xC0,0x40,0x40,0xE0}, /* '1' */
{0xC0,0x20,0x40,0x80,0xE0}, /* '2' */
{0xC0,0x20,0x40,0x20,0xC0}, /* '3' */
{0xA0,0xA0,0xE0,0x20,0x20}, /* '4' */
{0xE0,0x80,0xC0,0x20,0xC0}, /* '5' */
{0x60,0x80,0xE0,0xA0,0x60}, /* '6' */
{0xE0,0x20,0x40,0x80,0x80}, /* '7' */
{0x60,0xA0,0x60,0xA0,0x60}, /* '8' */
{0x60,0xA0,0x60,0x20,0x60}, /* '9' */
{0x00,0x40,0x00,0x40,0x00}, /* ':' */
{0x00,0x40,0x00,0x40,0x80}, /* ';' */
{0x20,0x40,0x80,0x40,0x20}, /* '<' */
{0x00,0xE0,0x00,0xE0,0x00}, /* '=' */
{0x80,0x40,0x20,0x40,0x80}, /* '>' */
{0xC0,0x20,0x40,0x00,0x40}, /* '?' */
{0x60,0xA0,0xE0,0x80,0x60}, /* '@' – placeholder */
{0x40,0xA0,0xE0,0xA0,0xA0}, /* 'A' */
{0xC0,0xA0,0xC0,0xA0,0xC0}, /* 'B' */
{0x60,0x80,0x80,0x80,0x60}, /* 'C' */
{0xC0,0xA0,0xA0,0xA0,0xC0}, /* 'D' */
{0xE0,0x80,0xC0,0x80,0xE0}, /* 'E' */
{0xE0,0x80,0xC0,0x80,0x80}, /* 'F' */
{0x60,0x80,0xA0,0xA0,0x60}, /* 'G' */
{0xA0,0xA0,0xE0,0xA0,0xA0}, /* 'H' */
{0xE0,0x40,0x40,0x40,0xE0}, /* 'I' */
{0x20,0x20,0x20,0xA0,0x40}, /* 'J' */
{0xA0,0xA0,0xC0,0xA0,0xA0}, /* 'K' */
{0x80,0x80,0x80,0x80,0xE0}, /* 'L' */
{0xA0,0xE0,0xE0,0xA0,0xA0}, /* 'M' */
{0xA0,0xE0,0xE0,0xC0,0xA0}, /* 'N' */
{0x40,0xA0,0xA0,0xA0,0x40}, /* 'O' */
{0xC0,0xA0,0xC0,0x80,0x80}, /* 'P' */
{0x40,0xA0,0xA0,0xC0,0x60}, /* 'Q' */
{0xC0,0xA0,0xC0,0xA0,0xA0}, /* 'R' */
{0x60,0x80,0x40,0x20,0xC0}, /* 'S' */
{0xE0,0x40,0x40,0x40,0x40}, /* 'T' */
{0xA0,0xA0,0xA0,0xA0,0x60}, /* 'U' */
{0xA0,0xA0,0xA0,0x40,0x40}, /* 'V' */
{0xA0,0xA0,0xE0,0xE0,0xA0}, /* 'W' */
{0xA0,0xA0,0x40,0xA0,0xA0}, /* 'X' */
{0xA0,0xA0,0x40,0x40,0x40}, /* 'Y' */
{0xE0,0x20,0x40,0x80,0xE0}, /* 'Z' */
};
This is a tiny 3×5 pixel bitmap font used in games or demos.
It's a very compact way to draw text on screen without using any real font library. Perfect for retro-style games, small tools, or when you want to keep dependencies minimal.
How it works:
• Each character is 3 pixels wide and 5 pixels tall.
• The font covers ASCII characters from space (32) to 'Z' (90).
• Every character is stored as 5 bytes (one byte per row).
• Each byte uses its top 3 bits to represent the 3 pixels of that row (1 = pixel on, 0 = pixel off).
Example for the letter 'A':
{0x40,0xA0,0xE0,0xA0,0xA0}, /* 'A' */
Let's break it down row by row (binary):
Row 0: 0100 0000 → . # . (only middle pixel)
Row 1: 1010 0000 → # . #
Row 2: 1110 0000 → # # #
Row 3: 1010 0000 → # . #
Row 4: 1010 0000 → # . #
ASCII Art Explanation of the whole font concept
Here's a visual of how the 3×5 font renders some common characters:
Space 'A' 'B' 'C' '1' '8'
. . . . # . # # . # # # . # . # # # ← row 0
. . . # . # # . # # . . # # . # . # ← row 1
. . . # # # # # . # . . . # . # # # ← row 2
. . . # . # # . # # . . . # . # . # ← row 3
. . . # . # # # . # # # # # # # # # ← row 4
SDL2 example function
static void draw_char(SDL_Renderer *r, int cx, int cy, char ch, int scale)
{
int idx = (int)ch - 32;
if (idx < 0 || idx >= (int)(sizeof FONT3x5 / sizeof FONT3x5[0])) return;
const Uint8 *glyph = FONT3x5[idx];
for (int row = 0; row < 5; row++) {
for (int col = 0; col < 3; col++) {
if (glyph[row] & (0x80 >> col)) {
SDL_Rect px = { cx + col*scale, cy + row*scale, scale, scale };
SDL_RenderFillRect(r, &px);
}
}
}
}
draw_char(renderer, x, y, 'A', 4);