Ray Tracing in One Weekend is a free online book that takes you through the process of programming a ray tracer from scratch.
It starts by writing support code to do math with 3-element vectors, building up a 3D scene with spheres and adding materials, and finishing by rendering a large scene of spheres of various sizes and materials.
The book provides source code in C++, which I followed directly my first time through.
Having done that, I decided to get a little bolder and repeat the experiment with Rust.
This went well enough that I went even further and added multi-threading to speed it up;
the picture above is the result of letting this multi-threaded renderer run for a while.
Anyway, this ended up being interesting enough to do a write-up about, so here it is;
read on!
Edit: Updated for Zig 0.14.0 and a version of raylib that works with it.
I picked up some Zig recently and figured I'd take the chance to learn its build system using raylib.
raylib already has pretty good community-maintained idiomatic Zig bindings, but we want to learn, so we're going to do it the "hard" way instead.
raylib has a build.zig, which means that it can be used directly with Zig's package manager.
Its C headers can also be translated into a Zig module that can be @imported, thanks to Zig's built-in C translator.
Note: We will not be using @cImport, since it seems like it'll be removed in future versions of Zig.
So here's the game I've been working on the the last six months: Coric's Quest!
It's a free and open source RPG that fits about two hours of game play into a single 9 MB file.
There are native builds for Windows and Linux, and a WebAssembly build that can be played in a web browser.
You can play it right now at itch.io and on its homepage.
The source code can be found on GitHub.
There's also a project page here on this site.
I wanted to try my hand at making interactive graphical applications with C, WebAssemnbly and the Sokol header-only libraries when I stumbled across the CHIP-8.
Creating a CHIP-8 interpreter ("emulator") was as good an excuse as any to scratch my itch, and a little while later I ended up with chip8run, which you can try online right now.
I recently worked my way through Robert Nystrom's Crafting Interpreters, which guides you through the process of making an interpreter for a scripting language.
The book is made up of three parts: a short part describing Lox (the scripting language made for the book), a tree-walk interpreter written in Java and a bytecode virtual machine interpreter written in C.
This post is about how I approached the last part.
The book doesn't recommend any specific setup or workflow, so you're free to go with whatever you like.
The rest of this post describes what I went with; all of the code can be found here: https://github.com/tung/clox