Last active
March 8, 2024 03:11
-
-
Save skeeto/44bdf48bbc934d3e99ae10efe346a83f to your computer and use it in GitHub Desktop.
Font rendering demo in SDL2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Font rendering demo | |
// $ cc -o demo demo.c $(sdl2-config --cflags --libs) | |
// Ref: https://old.reddit.com/r/C_Programming/comments/13ga82a | |
// This is free and unencumbered software released into the public domain. | |
#include "SDL.h" | |
// https://itch.io/jam/lowrezjam2016/topic/19413/minimal-sprite-font-with-upperlower-cases-cleanreadable | |
#define FONTW 72 | |
#define FONTH 143 | |
#define CHARW 9 | |
#define CHARH 11 | |
static Uint8 fontqoi[] = { | |
0x71, 0x6f, 0x69, 0x66, 0x00, 0x00, 0x00, 0x48, 0x00, 0x00, 0x00, 0x8f, | |
0x04, 0x00, 0xff, 0xff, 0x00, 0xff, 0x00, 0xfd, 0xfd, 0xd2, 0xff, 0xff, | |
0xff, 0xff, 0xff, 0xc1, 0x36, 0xc4, 0x26, 0xc0, 0x36, 0xc5, 0x26, 0xc1, | |
0x36, 0xc4, 0x26, 0xc0, 0x36, 0xc5, 0x26, 0xc1, 0x36, 0xc4, 0x26, 0xc1, | |
0x36, 0xc4, 0x26, 0xc1, 0x36, 0xc4, 0x26, 0x36, 0x26, 0x36, 0xc4, 0x26, | |
0x36, 0x26, 0x36, 0xc4, 0x26, 0x36, 0x26, 0x36, 0xc4, 0x26, 0x36, 0xc6, | |
0x26, 0x36, 0x26, 0x36, 0xc4, 0x26, 0x36, 0xc6, 0x26, 0x36, 0xc6, 0x26, | |
0x36, 0xc6, 0x26, 0x36, 0x26, 0x36, 0xc4, 0x26, 0x36, 0x26, 0x36, 0xc4, | |
0x26, 0x36, 0x26, 0x36, 0xc4, 0x26, 0x36, 0xc6, 0x26, 0x36, 0x26, 0x36, | |
0xc4, 0x26, 0x36, 0xc6, 0x26, 0x36, 0xc6, 0x26, 0x36, 0xc6, 0x26, 0x36, | |
0x26, 0x36, 0xc4, 0x26, 0xc1, 0x36, 0xc4, 0x26, 0xc0, 0x36, 0xc5, 0x26, | |
0x36, 0xc6, 0x26, 0x36, 0x26, 0x36, 0xc4, 0x26, 0xc0, 0x36, 0xc5, 0x26, | |
0xc0, 0x36, 0xc5, 0x26, 0x36, 0x26, 0x36, 0xc4, 0x26, 0xc1, 0x36, 0xc4, | |
0x26, 0x36, 0x26, 0x36, 0xc4, 0x26, 0x36, 0x26, 0x36, 0xc4, 0x26, 0x36, | |
0xc6, 0x26, 0x36, 0x26, 0x36, 0xc4, 0x26, 0x36, 0xc6, 0x26, 0x36, 0xc6, | |
0x26, 0x36, 0x26, 0x36, 0xc4, 0x26, 0x36, 0x26, 0x36, 0xc4, 0x26, 0x36, | |
0x26, 0x36, 0xc4, 0x26, 0x36, 0x26, 0x36, 0xc4, 0x26, 0x36, 0xc6, 0x26, | |
0x36, 0x26, 0x36, 0xc4, 0x26, 0x36, 0xc6, 0x26, 0x36, 0xc6, 0x26, 0x36, | |
0x26, 0x36, 0xc4, 0x26, 0x36, 0x26, 0x36, 0xc4, 0x26, 0x36, 0x26, 0x36, | |
0xc4, 0x26, 0xc0, 0x36, 0xc5, 0x26, 0xc1, 0x36, 0xc4, 0x26, 0xc0, 0x36, | |
0xc5, 0x26, 0xc1, 0x36, 0xc4, 0x26, 0x36, 0xc6, 0x26, 0xc1, 0x36, 0xc4, | |
0x26, 0x36, 0x26, 0x36, 0xfd, 0xfd, 0xfd, 0xfd, 0xec, 0x26, 0x36, 0xc7, | |
0x26, 0x36, 0xc5, 0x26, 0x36, 0x26, 0x36, 0xc4, 0x26, 0x36, 0xc6, 0x26, | |
0xc2, 0x36, 0xc3, 0x26, 0xc0, 0x36, 0xc5, 0x26, 0xc1, 0x36, 0xc4, 0x26, | |
0xc1, 0x36, 0xc4, 0x26, 0x36, 0xc7, 0x26, 0x36, 0xc5, 0x26, 0x36, 0x26, | |
0x36, 0xc4, 0x26, 0x36, 0xc6, 0x26, 0x36, 0x26, 0x36, 0x26, 0x36, 0xc2, | |
0x26, 0x36, 0x26, 0x36, 0xc4, 0x26, 0x36, 0x26, 0x36, 0xc4, 0x26, 0x36, | |
0x26, 0x36, 0xc4, 0x26, 0x36, 0xc7, 0x26, 0x36, 0xc5, 0x26, 0x36, 0x26, | |
0x36, 0xc4, 0x26, 0x36, 0xc6, 0x26, 0x36, 0x26, 0x36, 0x26, 0x36, 0xc2, | |
0x26, 0x36, 0x26, 0x36, 0xc4, 0x26, 0x36, 0x26, 0x36, 0xc4, 0x26, 0x36, | |
0x26, 0x36, 0xc4, 0x26, 0x36, 0xc7, 0x26, 0x36, 0xc5, 0x26, 0xc0, 0x36, | |
0xc5, 0x26, 0x36, 0xc6, 0x26, 0x36, 0x26, 0x36, 0x26, 0x36, 0xc2, 0x26, | |
0x36, 0x26, 0x36, 0xc4, 0x26, 0x36, 0x26, 0x36, 0xc4, 0x26, 0xc1, 0x36, | |
0xc4, 0x26, 0x36, 0xc7, 0x26, 0x36, 0xc5, 0x26, 0x36, 0x26, 0x36, 0xc4, | |
0x26, 0x36, 0xc6, 0x26, 0x36, 0x26, 0x36, 0x26, 0x36, 0xc2, 0x26, 0x36, | |
0x26, 0x36, 0xc4, 0x26, 0x36, 0x26, 0x36, 0xc4, 0x26, 0x36, 0xc6, 0x26, | |
0x36, 0xc7, 0x26, 0x36, 0xc5, 0x26, 0x36, 0x26, 0x36, 0xc4, 0x26, 0x36, | |
0xc6, 0x26, 0x36, 0x26, 0x36, 0x26, 0x36, 0xc2, 0x26, 0x36, 0x26, 0x36, | |
0xc4, 0x26, 0x36, 0x26, 0x36, 0xc4, 0x26, 0x36, 0xc6, 0x26, 0x36, 0xc6, | |
0x26, 0x36, 0xc6, 0x26, 0x36, 0x26, 0x36, 0xc4, 0x26, 0xc0, 0x36, 0xc5, | |
0x26, 0x36, 0x26, 0x36, 0x26, 0x36, 0xc2, 0x26, 0x36, 0x26, 0x36, 0xc4, | |
0x26, 0xc1, 0x36, 0xc4, 0x26, 0x36, 0xfd, 0xfd, 0xfd, 0xfd, 0xee, 0x26, | |
0xc1, 0x36, 0xc4, 0x26, 0xc0, 0x36, 0xc5, 0x26, 0xc1, 0x36, 0xc4, 0x26, | |
0xc1, 0x36, 0xc4, 0x26, 0x36, 0x26, 0x36, 0xc4, 0x26, 0x36, 0x26, 0x36, | |
0xc4, 0x26, 0x36, 0x26, 0x36, 0x26, 0x36, 0xc2, 0x26, 0x36, 0x26, 0x36, | |
0xc4, 0x26, 0x36, 0x26, 0x36, 0xc4, 0x26, 0x36, 0x26, 0x36, 0xc4, 0x26, | |
0x36, 0xc7, 0x26, 0x36, 0xc5, 0x26, 0x36, 0x26, 0x36, 0xc4, 0x26, 0x36, | |
0x26, 0x36, 0xc4, 0x26, 0x36, 0x26, 0x36, 0x26, 0x36, 0xc2, 0x26, 0x36, | |
0x26, 0x36, 0xc4, 0x26, 0x36, 0x26, 0x36, 0xc4, 0x26, 0x36, 0x26, 0x36, | |
0xc4, 0x26, 0x36, 0xc7, 0x26, 0x36, 0xc5, 0x26, 0x36, 0x26, 0x36, 0xc4, | |
0x26, 0x36, 0x26, 0x36, 0xc4, 0x26, 0x36, 0x26, 0x36, 0x26, 0x36, 0xc2, | |
0x26, 0x36, 0x26, 0x36, 0xc4, 0x26, 0x36, 0x26, 0x36, 0xc4, 0x26, 0xc0, | |
0x36, 0xc5, 0x26, 0xc1, 0x36, 0xc5, 0x26, 0x36, 0xc5, 0x26, 0x36, 0x26, | |
0x36, 0xc4, 0x26, 0x36, 0x26, 0x36, 0xc4, 0x26, 0x36, 0x26, 0x36, 0x26, | |
0x36, 0xc3, 0x26, 0x36, 0xc5, 0x26, 0x36, 0x26, 0x36, 0xc4, 0x26, 0x36, | |
0x26, 0x36, 0xc6, 0x26, 0x36, 0xc5, 0x26, 0x36, 0xc5, 0x26, 0x36, 0x26, | |
0x36, 0xc4, 0x26, 0x36, 0x26, 0x36, 0xc4, 0x26, 0x36, 0x26, 0x36, 0x26, | |
0x36, 0xc2, 0x26, 0x36, 0x26, 0x36, 0xc4, 0x26, 0x36, 0x26, 0x36, 0xc4, | |
0x26, 0x36, 0x26, 0x36, 0xc6, 0x26, 0x36, 0xc5, 0x26, 0x36, 0xc5, 0x26, | |
0x36, 0x26, 0x36, 0xc4, 0x26, 0x36, 0x26, 0x36, 0xc4, 0x26, 0x36, 0x26, | |
0x36, 0x26, 0x36, 0xc2, 0x26, 0x36, 0x26, 0x36, 0xc4, 0x26, 0xc0, 0x36, | |
0xc5, 0x26, 0x36, 0x26, 0x36, 0xc4, 0x26, 0xc1, 0x36, 0xc5, 0x26, 0x36, | |
0xc5, 0x26, 0xc1, 0x36, 0xc5, 0x26, 0x36, 0xc5, 0x26, 0xc3, 0x36, 0xc2, | |
0x26, 0x36, 0x26, 0x36, 0xc6, 0x26, 0x36, 0xfd, 0xfd, 0xfd, 0xfd, 0xe3, | |
0x26, 0x36, 0x26, 0x36, 0xc4, 0x26, 0xc1, 0x36, 0xcd, 0x26, 0x36, 0xd1, | |
0x26, 0x36, 0xce, 0x26, 0xc0, 0x36, 0xc4, 0x26, 0x36, 0x26, 0x36, 0xc6, | |
0x26, 0x36, 0xcd, 0x26, 0x36, 0xd1, 0x26, 0x36, 0xce, 0x26, 0x36, 0xc5, | |
0x26, 0x36, 0x26, 0x36, 0xc6, 0x26, 0x36, 0xc4, 0x26, 0xc1, 0x36, 0xc4, | |
0x26, 0xc1, 0x36, 0xc4, 0x26, 0xc1, 0x36, 0xc4, 0x26, 0xc1, 0x36, 0xc4, | |
0x26, 0xc1, 0x36, 0xc4, 0x26, 0xc1, 0x36, 0xc4, 0x26, 0xc1, 0x36, 0xc5, | |
0x26, 0x36, 0xc7, 0x26, 0x36, 0xc4, 0x26, 0x36, 0x26, 0x36, 0xc4, 0x26, | |
0x36, 0xc6, 0x26, 0x36, 0x26, 0x36, 0xc4, 0x26, 0x36, 0x26, 0x36, 0xc5, | |
0x26, 0x36, 0xc6, 0x26, 0x36, 0xc5, 0x26, 0x36, 0xc6, 0x26, 0xc1, 0x36, | |
0xc4, 0x26, 0x36, 0x26, 0x36, 0xc4, 0x26, 0x36, 0xc6, 0x26, 0x36, 0x26, | |
0x36, 0xc4, 0x26, 0xc1, 0x36, 0xc5, 0x26, 0x36, 0xc6, 0x26, 0x36, 0xc5, | |
0x26, 0x36, 0xc6, 0x26, 0x36, 0x26, 0x36, 0xc4, 0x26, 0x36, 0x26, 0x36, | |
0xc4, 0x26, 0x36, 0xc6, 0x26, 0x36, 0x26, 0x36, 0xc4, 0x26, 0x36, 0xc7, | |
0x26, 0x36, 0xc6, 0x26, 0x36, 0xc5, 0x26, 0xc1, 0x36, 0xc4, 0x26, 0xc1, | |
0x36, 0xc4, 0x26, 0xc1, 0x36, 0xc4, 0x26, 0xc1, 0x36, 0xc4, 0x26, 0xc1, | |
0x36, 0xc4, 0x26, 0xc1, 0x36, 0xc5, 0x26, 0x36, 0xfd, 0xfd, 0xfd, 0xfd, | |
0xed, 0x26, 0xc1, 0x36, 0xc4, 0x26, 0x36, 0xc6, 0x26, 0x36, 0xc7, 0x26, | |
0x36, 0xc5, 0x26, 0x36, 0xc6, 0x26, 0x36, 0xd8, 0x26, 0x36, 0x26, 0x36, | |
0xc4, 0x26, 0x36, 0xd8, 0x26, 0x36, 0xc6, 0x26, 0x36, 0xd8, 0x26, 0x36, | |
0x26, 0x36, 0xc4, 0x26, 0xc1, 0x36, 0xc4, 0x26, 0x36, 0xc7, 0x26, 0x36, | |
0xc5, 0x26, 0x36, 0x26, 0x36, 0xc4, 0x26, 0x36, 0xc6, 0x26, 0xc3, 0x36, | |
0xc2, 0x26, 0xc1, 0x36, 0xc4, 0x26, 0x36, 0x26, 0x36, 0xc4, 0x26, 0x36, | |
0x26, 0x36, 0xc4, 0x26, 0x36, 0xc7, 0x26, 0x36, 0xc5, 0x26, 0x36, 0x26, | |
0x36, 0xc4, 0x26, 0x36, 0xc6, 0x26, 0x36, 0x26, 0x36, 0x26, 0x36, 0xc2, | |
0x26, 0x36, 0x26, 0x36, 0xc4, 0x26, 0xc1, 0x36, 0xc4, 0x26, 0x36, 0x26, | |
0x36, 0xc4, 0x26, 0x36, 0xc7, 0x26, 0x36, 0xc5, 0x26, 0xc0, 0x36, 0xc5, | |
0x26, 0x36, 0xc6, 0x26, 0x36, 0x26, 0x36, 0x26, 0x36, 0xc2, 0x26, 0x36, | |
0x26, 0x36, 0xc6, 0x26, 0x36, 0xc4, 0x26, 0x36, 0x26, 0x36, 0xc4, 0x26, | |
0x36, 0xc7, 0x26, 0x36, 0xc5, 0x26, 0x36, 0x26, 0x36, 0xc4, 0x26, 0x36, | |
0xc6, 0x26, 0x36, 0x26, 0x36, 0x26, 0x36, 0xc2, 0x26, 0x36, 0x26, 0x36, | |
0xc4, 0x26, 0xc1, 0x36, 0xc4, 0x26, 0x36, 0x26, 0x36, 0xc4, 0x26, 0x36, | |
0xc7, 0x26, 0x36, 0xc5, 0x26, 0x36, 0x26, 0x36, 0xc4, 0x26, 0x36, 0xc6, | |
0x26, 0x36, 0x26, 0x36, 0x26, 0x36, 0xc2, 0x26, 0x36, 0x26, 0x36, 0xe0, | |
0x26, 0x36, 0xfd, 0xc6, 0x26, 0xc0, 0x36, 0xfd, 0xfd, 0xfd, 0xfd, 0xf7, | |
0x26, 0x36, 0xd7, 0x26, 0xc1, 0x36, 0xc4, 0x26, 0xc1, 0x36, 0xc4, 0x26, | |
0xc1, 0x36, 0xc4, 0x26, 0xc0, 0x36, 0xc5, 0x26, 0xc1, 0x36, 0xc4, 0x26, | |
0xc1, 0x36, 0xc4, 0x26, 0x36, 0x26, 0x36, 0xc4, 0x26, 0x36, 0x26, 0x36, | |
0xc4, 0x26, 0x36, 0x26, 0x36, 0xc4, 0x26, 0x36, 0x26, 0x36, 0xc4, 0x26, | |
0x36, 0x26, 0x36, 0xc4, 0x26, 0x36, 0xc6, 0x26, 0x36, 0xc7, 0x26, 0x36, | |
0xc5, 0x26, 0x36, 0x26, 0x36, 0xc4, 0x26, 0x36, 0x26, 0x36, 0xc4, 0x26, | |
0x36, 0x26, 0x36, 0xc4, 0x26, 0x36, 0x26, 0x36, 0xc4, 0x26, 0x36, 0x26, | |
0x36, 0xc4, 0x26, 0x36, 0xc6, 0x26, 0xc1, 0x36, 0xc5, 0x26, 0x36, 0xc5, | |
0x26, 0x36, 0x26, 0x36, 0xc4, 0x26, 0x36, 0x26, 0x36, 0xc4, 0x26, 0x36, | |
0x26, 0x36, 0xc4, 0x26, 0x36, 0x26, 0x36, 0xc4, 0x26, 0x36, 0x26, 0x36, | |
0xc4, 0x26, 0x36, 0xc8, 0x26, 0x36, 0xc5, 0x26, 0x36, 0xc5, 0x26, 0x36, | |
0x26, 0x36, 0xc4, 0x26, 0x36, 0x26, 0x36, 0xc4, 0x26, 0xc1, 0x36, 0xc4, | |
0x26, 0xc1, 0x36, 0xc4, 0x26, 0xc1, 0x36, 0xc4, 0x26, 0x36, 0xc6, 0x26, | |
0xc1, 0x36, 0xc5, 0x26, 0xc0, 0x36, 0xc4, 0x26, 0xc1, 0x36, 0xc5, 0x26, | |
0x36, 0xce, 0x26, 0x36, 0xc8, 0x26, 0x36, 0xfa, 0x26, 0x36, 0xc8, 0x26, | |
0x36, 0xfd, 0xfd, 0xfd, 0xeb, 0x26, 0xc1, 0x36, 0xc5, 0x26, 0x36, 0xc5, | |
0x26, 0xc1, 0x36, 0xc4, 0x26, 0xc1, 0x36, 0xe8, 0x26, 0x36, 0x26, 0x36, | |
0xc4, 0x26, 0xc0, 0x36, 0xc7, 0x26, 0x36, 0xc6, 0x26, 0x36, 0xc4, 0x26, | |
0x36, 0x26, 0x36, 0x26, 0x36, 0xc2, 0x26, 0x36, 0x26, 0x36, 0xc4, 0x26, | |
0x36, 0x26, 0x36, 0xc4, 0x26, 0xc1, 0x36, 0xc4, 0x26, 0x36, 0x26, 0x36, | |
0xc5, 0x26, 0x36, 0xc7, 0x26, 0x36, 0xc6, 0x26, 0x36, 0xc4, 0x26, 0x36, | |
0x26, 0x36, 0x26, 0x36, 0xc2, 0x26, 0x36, 0x26, 0x36, 0xc4, 0x26, 0x36, | |
0x26, 0x36, 0xc6, 0x26, 0x36, 0xc4, 0x26, 0x36, 0x26, 0x36, 0xc5, 0x26, | |
0x36, 0xc5, 0x26, 0xc1, 0x36, 0xc5, 0x26, 0xc0, 0x36, 0xc4, 0x26, 0x36, | |
0x26, 0x36, 0x26, 0x36, 0xc3, 0x26, 0x36, 0xc5, 0x26, 0x36, 0x26, 0x36, | |
0xc5, 0x26, 0x36, 0xc5, 0x26, 0x36, 0x26, 0x36, 0xc5, 0x26, 0x36, 0xc5, | |
0x26, 0x36, 0xc8, 0x26, 0x36, 0xc4, 0x26, 0x36, 0x26, 0x36, 0x26, 0x36, | |
0xc2, 0x26, 0x36, 0x26, 0x36, 0xc4, 0x26, 0x36, 0x26, 0x36, 0xc4, 0x26, | |
0x36, 0xc6, 0x26, 0x36, 0x26, 0x36, 0xc5, 0x26, 0x36, 0xc5, 0x26, 0x36, | |
0xc8, 0x26, 0x36, 0xc4, 0x26, 0xc3, 0x36, 0xc2, 0x26, 0x36, 0x26, 0x36, | |
0xc4, 0x26, 0xc1, 0x36, 0xc4, 0x26, 0xc1, 0x36, 0xc4, 0x26, 0xc1, 0x36, | |
0xc5, 0x26, 0x36, 0xc5, 0x26, 0xc1, 0x36, 0xc4, 0x26, 0xc1, 0x36, 0xd8, | |
0x26, 0x36, 0xfd, 0xc5, 0x26, 0xc1, 0x36, 0xfd, 0xfd, 0xfd, 0xc7, 0x26, | |
0x36, 0x26, 0x36, 0xc4, 0x26, 0xc1, 0x36, 0xc4, 0x26, 0xc1, 0x36, 0xc4, | |
0x26, 0xc1, 0x36, 0xc4, 0x26, 0xc1, 0x36, 0xc4, 0x26, 0xc1, 0x36, 0xd6, | |
0x26, 0x36, 0x26, 0x36, 0xc4, 0x26, 0x36, 0xc6, 0x26, 0x36, 0xc8, 0x26, | |
0x36, 0xc4, 0x26, 0x36, 0x26, 0x36, 0xc4, 0x26, 0x36, 0x26, 0x36, 0xd6, | |
0x26, 0x36, 0x26, 0x36, 0xc4, 0x26, 0x36, 0xc6, 0x26, 0x36, 0xc8, 0x26, | |
0x36, 0xc4, 0x26, 0x36, 0x26, 0x36, 0xc4, 0x26, 0x36, 0x26, 0x36, 0xd6, | |
0x26, 0x36, 0x26, 0x36, 0xc4, 0x26, 0xc1, 0x36, 0xc4, 0x26, 0xc1, 0x36, | |
0xc5, 0x26, 0x36, 0xc5, 0x26, 0xc1, 0x36, 0xc4, 0x26, 0xc1, 0x36, 0xd6, | |
0x26, 0xc1, 0x36, 0xc6, 0x26, 0x36, 0xc4, 0x26, 0x36, 0x26, 0x36, 0xc5, | |
0x26, 0x36, 0xc5, 0x26, 0x36, 0x26, 0x36, 0xc6, 0x26, 0x36, 0xd8, 0x26, | |
0x36, 0xc6, 0x26, 0x36, 0xc4, 0x26, 0x36, 0x26, 0x36, 0xc4, 0x26, 0x36, | |
0xc6, 0x26, 0x36, 0x26, 0x36, 0xc6, 0x26, 0x36, 0xd8, 0x26, 0x36, 0xc4, | |
0x26, 0xc1, 0x36, 0xc4, 0x26, 0xc1, 0x36, 0xc4, 0x26, 0x36, 0xc6, 0x26, | |
0xc1, 0x36, 0xc4, 0x26, 0xc1, 0x36, 0xc4, 0x26, 0x36, 0xc7, 0x26, 0x36, | |
0xfd, 0xc6, 0x26, 0x36, 0xfd, 0xfd, 0xfd, 0xf6, 0x26, 0xc0, 0x36, 0xc5, | |
0x26, 0x36, 0xd9, 0x26, 0x36, 0x26, 0x36, 0xc4, 0x26, 0x36, 0x26, 0x36, | |
0xd7, 0x26, 0x36, 0xc4, 0x26, 0x36, 0xd8, 0x26, 0x36, 0x26, 0x36, 0xc5, | |
0x26, 0x36, 0x26, 0x36, 0xc4, 0x26, 0x36, 0xc5, 0x26, 0x36, 0xc8, 0x26, | |
0x36, 0xc4, 0x26, 0x36, 0xe1, 0x26, 0xc3, 0x36, 0xd5, 0x26, 0x36, 0xc5, | |
0x26, 0x36, 0xe2, 0x26, 0x36, 0x26, 0x36, 0xd6, 0x26, 0x36, 0xc5, 0x26, | |
0x36, 0xc6, 0x26, 0xc1, 0x36, 0xd6, 0x26, 0xc3, 0x36, 0xfd, 0xc4, 0x26, | |
0x36, 0x26, 0x36, 0xc4, 0x26, 0x36, 0xc5, 0x26, 0x36, 0xc7, 0x26, 0x36, | |
0xc5, 0x26, 0x36, 0xcf, 0x26, 0xc1, 0x36, 0xce, 0x26, 0x36, 0x26, 0x36, | |
0xc3, 0x26, 0x36, 0xfd, 0xfd, 0xfd, 0xf7, 0x26, 0x36, 0xc5, 0x26, 0x36, | |
0xc6, 0x26, 0xc0, 0x36, 0xc5, 0x26, 0xc0, 0x36, 0xc5, 0x26, 0x36, 0xc6, | |
0x26, 0x36, 0x26, 0x36, 0xc4, 0x26, 0x36, 0xc7, 0x26, 0xc0, 0x36, 0xc4, | |
0x26, 0x36, 0xc7, 0x26, 0x36, 0xc5, 0x26, 0x36, 0xc7, 0x26, 0x36, 0xc5, | |
0x26, 0x36, 0xc6, 0x26, 0x36, 0x26, 0x36, 0xc4, 0x26, 0x36, 0xc6, 0x26, | |
0x36, 0xc6, 0x26, 0x36, 0xc7, 0x26, 0x36, 0xc5, 0x26, 0x36, 0xc7, 0x26, | |
0x36, 0xc5, 0x26, 0x36, 0xd8, 0x26, 0x36, 0xc6, 0x26, 0x36, 0xc7, 0x26, | |
0x36, 0xc5, 0x26, 0x36, 0xc7, 0x26, 0x36, 0xc5, 0x26, 0x36, 0xd9, 0x26, | |
0x36, 0x26, 0x36, 0xc3, 0x26, 0x36, 0xc7, 0x26, 0x36, 0xc5, 0x26, 0x36, | |
0xc7, 0x26, 0x36, 0xc5, 0x26, 0x36, 0xd8, 0x26, 0x36, 0x26, 0x36, 0xc4, | |
0x26, 0x36, 0xc7, 0x26, 0x36, 0xc5, 0x26, 0x36, 0xc7, 0x26, 0x36, 0xc5, | |
0x26, 0x36, 0xd8, 0x26, 0x36, 0x26, 0x36, 0xc4, 0x26, 0x36, 0xc7, 0x26, | |
0x36, 0xc5, 0x26, 0x36, 0xc7, 0x26, 0x36, 0xc5, 0x26, 0x36, 0xd9, 0x26, | |
0x36, 0x26, 0x36, 0xc3, 0x26, 0x36, 0xc7, 0x26, 0x36, 0xc5, 0x26, 0x36, | |
0xc7, 0x26, 0x36, 0xc5, 0x26, 0x36, 0xe2, 0x26, 0x36, 0xc5, 0x26, 0x36, | |
0xc6, 0x26, 0xc0, 0x36, 0xc5, 0x26, 0xc0, 0x36, 0xc5, 0x26, 0x36, 0xfd, | |
0xd0, 0x26, 0x36, 0xfd, 0xc8, 0x26, 0x36, 0xc5, 0x26, 0x36, 0xc9, 0x26, | |
0x36, 0xc5, 0x26, 0xc1, 0x36, 0xef, 0x26, 0x36, 0xc9, 0x26, 0x36, 0xc4, | |
0x26, 0x36, 0xc1, 0x26, 0x36, 0xc2, 0x26, 0x36, 0xea, 0x26, 0x36, 0xc7, | |
0x26, 0x36, 0xc4, 0x26, 0x36, 0xc0, 0x26, 0x36, 0xc0, 0x26, 0x36, 0xc0, | |
0x26, 0x36, 0x26, 0x36, 0xc6, 0x26, 0x36, 0xcf, 0x26, 0x36, 0xce, 0x26, | |
0x36, 0xc7, 0x26, 0x36, 0xc4, 0x26, 0x36, 0xc1, 0x26, 0x36, 0x26, 0x36, | |
0xc1, 0x26, 0x36, 0xc7, 0x26, 0x36, 0xc4, 0x26, 0xc1, 0x36, 0xc4, 0x26, | |
0x36, 0x26, 0x36, 0x26, 0x36, 0xcd, 0x26, 0x36, 0xc5, 0x26, 0x36, 0xc5, | |
0x26, 0x36, 0xc0, 0x26, 0xc0, 0x36, 0x26, 0x36, 0xc9, 0x26, 0xc3, 0x36, | |
0xcc, 0x26, 0xc1, 0x36, 0xce, 0x26, 0x36, 0xc5, 0x26, 0x36, 0xc5, 0x26, | |
0x36, 0x26, 0x36, 0x26, 0x36, 0x26, 0x36, 0xcb, 0x26, 0x36, 0xc4, 0x26, | |
0xc1, 0x36, 0xc4, 0x26, 0x36, 0x26, 0x36, 0x26, 0x36, 0xce, 0x26, 0x36, | |
0xc3, 0x26, 0x36, 0xc6, 0x26, 0x36, 0xc0, 0x26, 0xc2, 0x36, 0xcb, 0x26, | |
0x36, 0xcf, 0x26, 0x36, 0xd0, 0x26, 0x36, 0xc3, 0x26, 0x36, 0xc7, 0x26, | |
0x36, 0xfd, 0xc8, 0x26, 0xc2, 0x36, 0xfd, 0xfd, 0xfa, 0x26, 0x36, 0xea, | |
0x26, 0x36, 0xc1, 0x26, 0x36, 0xc3, 0x26, 0x36, 0xc6, 0x26, 0x36, 0xc5, | |
0x26, 0xc0, 0x36, 0xc5, 0x26, 0xc0, 0x36, 0xc5, 0x26, 0xc0, 0x36, 0xd6, | |
0x26, 0x36, 0x26, 0x36, 0x26, 0x36, 0xc3, 0x26, 0x36, 0xc6, 0x26, 0x36, | |
0xc5, 0x26, 0x36, 0xc6, 0x26, 0x36, 0xc6, 0x26, 0x36, 0xc8, 0x26, 0x36, | |
0xc4, 0x26, 0x36, 0xc7, 0x26, 0x36, 0xc0, 0x26, 0x36, 0xd4, 0x26, 0x36, | |
0xc6, 0x26, 0x36, 0xc6, 0x26, 0xc0, 0x36, 0xc6, 0x26, 0x36, 0xc6, 0x26, | |
0x36, 0xc8, 0x26, 0x36, 0xc3, 0x26, 0xc1, 0x36, 0xc4, 0x26, 0xc1, 0x36, | |
0xc5, 0x26, 0x36, 0xc5, 0x26, 0xc0, 0x36, 0xc5, 0x26, 0x36, 0xc6, 0x26, | |
0x36, 0xc8, 0x26, 0x36, 0xc7, 0x26, 0x36, 0xc5, 0x26, 0x36, 0xc4, 0x26, | |
0x36, 0x26, 0x36, 0xc6, 0x26, 0x36, 0xc4, 0x26, 0x36, 0xc6, 0x26, 0xc0, | |
0x36, 0xc6, 0x26, 0x36, 0xc6, 0x26, 0x36, 0xc7, 0x26, 0x36, 0xc0, 0x26, | |
0x36, 0xc1, 0x26, 0xc1, 0x36, 0xc4, 0x26, 0xc1, 0x36, 0xc6, 0x26, 0x36, | |
0xc4, 0x26, 0x36, 0xc6, 0x26, 0x36, 0xc8, 0x26, 0x36, 0xc4, 0x26, 0x36, | |
0xc8, 0x26, 0x36, 0x26, 0x36, 0x26, 0x36, 0xc0, 0x26, 0x36, 0x26, 0x36, | |
0xc4, 0x26, 0x36, 0xc6, 0x26, 0xc0, 0x36, 0xc5, 0x26, 0xc1, 0x36, 0xc5, | |
0x26, 0xc0, 0x36, 0xd7, 0x26, 0x36, 0xc1, 0x26, 0x36, 0xc1, 0x26, 0xc1, | |
0x36, 0xc4, 0x26, 0xc1, 0x36, 0xc5, 0x26, 0x36, 0xfd, 0xfd, 0xfd, 0xdb, | |
0x26, 0x36, 0xc7, 0x26, 0x36, 0xc6, 0x26, 0x36, 0xf1, 0x26, 0x36, 0xc7, | |
0x26, 0x36, 0xc6, 0x26, 0x36, 0xfd, 0xfc, 0x26, 0x36, 0xc6, 0x26, 0xc1, | |
0x36, 0xc4, 0x26, 0x36, 0x26, 0x36, 0xf1, 0x26, 0x36, 0xc6, 0x26, 0x36, | |
0x26, 0x36, 0xc4, 0x26, 0x36, 0x26, 0x36, 0xf1, 0x26, 0x36, 0xc6, 0x26, | |
0x36, 0x26, 0x36, 0xc4, 0x26, 0x36, 0x26, 0x36, 0xf1, 0x26, 0x36, 0xc6, | |
0x26, 0x36, 0x26, 0x36, 0xc4, 0x26, 0x36, 0x26, 0x36, 0xf1, 0x26, 0x36, | |
0xc6, 0x26, 0xc1, 0x36, 0xc4, 0x26, 0xc1, 0x36, 0xfd, 0xfd, 0xfd, 0xc7, | |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 | |
}; | |
static Uint8 fontmap[256] = { | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
0, 68, 73, 72, 89, 94, 75, 74, 76, 77, 88, 86, 64, 69, 63, 83, | |
53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 66, 65, 92, 87, 93, 67, | |
84, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, | |
16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 78, 82, 79, 0, 70, | |
81, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, | |
42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 0, 80, 0, 71, 0, | |
}; | |
static Uint32 font[FONTH*FONTW]; | |
typedef struct { | |
int width, height, alpha, srgb; | |
Uint8 *p, *end; | |
int last, run; | |
Uint32 c, table[64]; | |
} Qoi; | |
static Qoi newqoi(Uint8 *p, int len) | |
{ | |
Qoi q = {0}; | |
q.p = p + 14; | |
q.end = p + len; | |
q.width = (Uint32)p[ 4]<<24 | p[ 5]<<16 | p[ 6]<< 8 | p[ 7]; | |
q.height = (Uint32)p[ 8]<<24 | p[ 9]<<16 | p[10]<< 8 | p[11]; | |
q.last = -1; | |
q.alpha = p[12]==4; | |
q.srgb = p[13]==1; | |
q.c = 0xff000000; | |
return q; | |
} | |
static Uint32 qoidecode(Qoi *q) | |
{ | |
if (q->run) { | |
q->run--; | |
} else { | |
int n, v=*q->p++; | |
Uint8 *p=q->p, r, g, b, a; | |
switch (v&0xc0) { | |
case 0x00: // INDEX | |
q->c = q->table[v]; | |
goto skiptable; | |
case 0x40: // DIFF | |
r=q->c, g=q->c>>8, b=q->c>>16, a=q->c>>24; | |
r += (v>>4 & 3) - 2; | |
g += (v>>2 & 3) - 2; | |
b += (v>>0 & 3) - 2; | |
q->c = r | g<<8 | b<<16 | (Uint32)a<<24; | |
break; | |
case 0x80: // LUMA | |
n = v - (0x80 + 32); | |
r=q->c, g=q->c>>8, b=q->c>>16, a=q->c>>24; | |
r += n + (*p>>4) - 8; | |
g += n; | |
b += n + (*p&15) - 8; | |
q->c = r | g<<8 | b<<16 | (Uint32)a<<24; | |
q->p += 1; | |
break; | |
case 0xc0: | |
switch ((n = v&63)) { | |
case 63: // RGBA | |
q->c = p[0] | p[1]<<8 | p[2]<<16 | (Uint32)p[3]<<24; | |
q->p += 4; | |
break; | |
case 62: // RGB | |
r=p[0], g=p[1], b=p[2], a=q->c>>24; | |
q->c = r | g<<8 | b<<16 | (Uint32)a<<24; | |
q->p += 3; | |
break; | |
default: // RUN | |
q->run = n; | |
break; | |
} | |
} | |
r=q->c, g=q->c>>8, b=q->c>>16, a=q->c>>24; | |
q->table[(r*3 + g*5 + b*7 + a*11)&63] = q->c; | |
skiptable: q->last = v; | |
} | |
return q->c; | |
} | |
static SDL_Texture *newfont(SDL_Renderer *r) | |
{ | |
Qoi q = newqoi(fontqoi, sizeof(fontqoi)); | |
for (int i = 0; i < FONTW*FONTH; i++) { | |
font[i] = qoidecode(&q); | |
} | |
SDL_Texture *t = SDL_CreateTexture( | |
r, SDL_PIXELFORMAT_ABGR8888, SDL_TEXTUREACCESS_STATIC, | |
FONTW, FONTH | |
); | |
SDL_SetTextureBlendMode(t, SDL_BLENDMODE_BLEND); | |
SDL_UpdateTexture(t, 0, font, FONTW*4); | |
return t; | |
} | |
static void drawtext( | |
SDL_Renderer *r, SDL_Texture *t, int x, int y, int size, char *msg) | |
{ | |
for (int i = 0; msg[i]; i++) { | |
int c = fontmap[msg[i]&255]; | |
if (c--) { | |
SDL_Rect src = {c%8*CHARW, c/8*CHARH+1, CHARW, CHARH}; | |
SDL_Rect dst = {x+i*CHARW*size, y, CHARW*size, CHARH*size}; | |
SDL_RenderCopy(r, t, &src, &dst); | |
} | |
} | |
} | |
int main(int argc, char **argv) | |
{ | |
int width = 800; | |
int height = 600; | |
SDL_Init(SDL_INIT_VIDEO); | |
SDL_Window *w = SDL_CreateWindow( | |
"Text Demo", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, | |
width, height, 0 | |
); | |
SDL_Renderer *r = SDL_CreateRenderer(w, -1, SDL_RENDERER_PRESENTVSYNC); | |
SDL_Texture *fonttx = newfont(r); | |
Uint64 rng = 1; | |
SDL_Color bg = {127, 63, 63, 255}; | |
char msg[] = "onfrqpunq21 vf n ivetva"; | |
int msglen = sizeof(msg) - 1; | |
for (;;) { | |
SDL_Event e; | |
while (SDL_PollEvent(&e)) { | |
rng += e.common.timestamp; | |
switch (e.type) { | |
case SDL_QUIT: | |
return 0; | |
} | |
} | |
// Randomly purturb the rectangle color | |
rng = rng*0x3243f6a8885a308d + 1; | |
bg.r = SDL_clamp(bg.r + (int)((rng>>34 & 1023)%5 - 2), 0, 192); | |
bg.g = SDL_clamp(bg.g + (int)((rng>>44 & 1023)%5 - 2), 0, 192); | |
bg.b = SDL_clamp(bg.b + (int)((rng>>54 & 1023)%5 - 2), 0, 192); | |
SDL_SetRenderDrawColor(r, 50, 50, 50, 255); | |
SDL_RenderClear(r); | |
SDL_SetRenderDrawColor(r, bg.r, bg.g, bg.b, bg.a); | |
int padx = 12; | |
int pady = 4; | |
SDL_Rect rect = { | |
width/padx, height/pady, | |
width*(padx-2)/padx, height*(pady-2)/pady | |
}; | |
SDL_RenderFillRect(r, &rect); | |
char decoded[sizeof(msg)] = {0}; | |
for (int i = 0; msg[i]; i++) { // decode the secret | |
decoded[i] = msg[i]; | |
rng = rng*0x3243f6a8885a308d + 1; | |
int flip = !((rng >> 58) & 63); | |
if (msg[i]>='a' && msg[i]<='z') { | |
decoded[i] = (msg[i]-'a' + 13)%26 + 'a'; | |
if (flip) msg[i] += 'A' - 'a'; | |
} else if (msg[i]>='A' && msg[i]<='Z') { | |
decoded[i] = (msg[i]-'A' + 13)%26 + 'A'; | |
if (flip) msg[i] -= 'A' - 'a'; | |
} | |
} | |
int size = 3; | |
int x = (width - CHARW*size*msglen)/2; | |
int y = (height - CHARH*size)/2; | |
drawtext(r, fonttx, x, y, size, decoded); | |
SDL_RenderPresent(r); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment