# TTF-DOOM – A raycaster running inside TrueType font hinting

TrueType fonts have a hinting VM that grid-fits glyphs. It has a stack, storage area, conditionals, function calls, and it turns out it's Turing-complete. So I built a raycasting engine in the hinting bytecode. The glyph "A" in the font has 16 vertical bar contours. The hinting program reads player…

- **Page:** https://magpie.gallery/i/ttf-doom-a-raycaster-running-inside-truetype-font-lj36
- **Type:** Link to an idea elsewhere
- **Category:** Games
- **Tags:** raycasting, truetype, fonts, doom, hacking

## Source

Web · 4RH1T3CT0R: TTF-DOOM – A raycaster running inside TrueType font hinting

- **Original:** https://news.ycombinator.com/item?id=47665685

> TrueType fonts have a hinting VM that grid-fits glyphs. It has a stack, storage area, conditionals, function calls, and it turns out it's Turing-complete. So I built a raycasting engine in the hinting bytecode. The glyph "A" in the font has 16 vertical bar contours. The hinting program reads player coordinates from font variation axes via GETVARIATION, does DDA ray marching against a tile map in the storage area, and repositions bar heights with SCFS. It ends up looking like a crude Wolfenstein-style view. Small visuzlization: https://github.com/4RH1T3CT0R7/ttf-doom/blob/main/docs/media... About 6.5 KB of bytecode total - 13 functions, 795 storage slots, sin/cos lookup tables. JS handles movement, enemies, and shooting, then passes the coordinates to the font through CSS font-variation-settings. The font is basically a weird GPU. The weirdest parts: - TrueType MUL does (ab)/64, not ab. So 1*4=0. The DIV instruction is equally cursed. - No WHILE loops. Everything compiles to recursive FDEFs. FreeType limits call depth to ~64 frames. - SVTCA[0] is Y, SVTCA[1] is X. Of course. There's a small compiler behind this - lexer, parser, codegen - that turns a C-like DSL into TT assembly. Demo GIF: https://github.com/4RH1T3CT0R7/ttf-doom/blob/main/docs/media... Live demo: https://4rh1t3ct0r7.github.io/ttf-doom/ (Chrome/Edge, WASD+arrows, Space to shoot, Tab for debug overlay) This is a DOOM-style raycaster, not a port of the original engine - similar to DOOMQL and the Excel DOOM. The wall rendering does happen in the font's hinting VM though. Press Tab in the demo to watch the font variation axes change as you move. https://github.com/4RH1T3CT0R7/ttf-doom

## GitHub projects

- https://github.com/4RH1T3CT0R7/ttf-doom

## Rules for reuse

- Build your own version: don't copy another product's code, look, icons, colours or copy.
- The original belongs to its author; Magpie only links to it.
- The original content's copyright belongs to its creator. Magpie doesn't download or re-upload it; we only show the link and the official preview.
