Skip to content
Tech News
← Back to articles

Show HN: TTF-DOOM – A raycaster running inside TrueType font hinting

read original get Retro Gaming Font Kit → more articles
Why This Matters

This innovative project demonstrates that TrueType font hinting, traditionally used for glyph rendering, can be repurposed to run complex 3D raycasting engines, blurring the lines between font technology and graphics rendering. It highlights the Turing-complete nature of font hinting and opens new avenues for creative coding within constrained environments, inspiring developers to rethink the potential of font files beyond typography.

Key Takeaways

A DOOM-style raycaster that runs inside a TrueType font's hinting program.

What is this?

TrueType fonts have a built-in virtual machine for grid-fitting glyphs. It's got a stack, storage slots, arithmetic, conditionals, function calls - and it turns out it's Turing-complete. I wanted to see if I could get it to render 3D graphics.

The font file contains a DDA raycasting engine written in TrueType bytecode. The glyph "A" has 16 vertical bar contours, and the hinting program raycasts against a 16x16 tile map and repositions those bars using SCFS instructions to form a 3D perspective view. The whole thing is 6.5 KB.

JS handles movement, enemies, and shooting, then passes coordinates to the font through font-variation-settings . The font does the raycasting and wall rendering. Canvas overlay draws enemies, weapon, and HUD on top.

How it works

I wrote a small compiler that takes a custom DSL and outputs TrueType hinting assembly. The DSL looks like a stripped-down C:

func raycast(col: int) -> int: var ra: int = player_angle + col * 3 - FOV_HALF var dx: int = get_cos(ra) var dy: int = get_sin(ra) ...

This compiles to TT bytecode - FDEF , CALL , RS , WS , SCFS , etc. - and gets injected into a .ttf file along with sin/cos lookup tables and the map data. The compiler handles variable allocation (everything goes into TT storage slots), function definitions (FDEF/ENDF), and a few other things like fixed-point math.

The pipeline: doom.doom -> lexer -> parser -> codegen -> doom.ttf

... continue reading