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.
You are (or I suspect your LLM is) not correct about Doom using a raycasting engine. Wolfenstein fits that description, yes. Doom rather famously introduced BSP for level data and it draws sorted polygons front-to-back without ray-marching.
technically yes, most constrained-platform ports (as I remember) do the same though (DOOMQL, the TI-84 version, the Excel one) since BSP is hard to fit into a limited VM. "DOOM-style" here is more about the genre than the rendering technique
It's not really a "DOOM-style raycaster" then, it's a Wolfenstein 3D-style raycaster.
Pretty cool though!
Thanks!
> TrueType MUL does (ab)/64, not ab
This is how fixed-point arithmetic works. For multiplication of Q26.6 numbers you clear the squared scaling factors (2^6) by dividing/shifting one of them away.
I tried playing the demo, and it was just green bars for me. The walls didn't scale up or shrink, it was just a bunch of solid static green bars.
The enemies did scale up and shrink as I got closer, and the minimap worked.
Tried with Brave on Linux, and Google Chrome on macOS.
This is a FreeType issue - it uses auto-hinter by default on Linux and doesn't run the TT bytecode. No fix from CSS side unfortunately. Works on Windows/macOS where DirectWrite/CoreText run the bytecode
It didn't work on macOS either.
Yeah. Sorry - on MacOS in Chrome / Safari only green vertical bars.
Then only windows :(
Ok the MUL workaround got me. MUL does (ab)/64 so you have to DIV first to get a64, then MUL finally gives you a*b. And recursive FDEFs because there's no WHILE? All in 6.5KB? What kind of frame rate do you actually get out of this?
Frame rate depends on the browser - Chrome gives around 30-60fps on my machine, but the bottleneck is actually Chrome deciding whether to re-run hinting at all (had to add axis jitter to force it). The TT bytecode itself executes fast, it's maybe a few thousand instructions per frame