Linux provides the KMS (Kernel Mode Setting) API to let applications query and configure display settings. It's used by Wayland compositors and other programs that need to configure the hardware directly. I found the C API a little verbose and hard to follow so I made libdrm-ocaml, which lets us run commands interactively in a REPL.
We'll start by discovering what hardware is available and how it's currently configured, then configure a monitor to display a simple bitmap, and then finally render a 3D animation. The post should be a useful introduction to KMS even if you don't know OCaml.
( this post also appeared on Hacker News )
Table of Contents
Running it yourself
If you want to follow along, you'll need to install libdrm-ocaml and an interactive REPL like utop. With Nix, you can set everything up like this:
git clone https://github.com/talex5/libdrm-ocaml cd libdrm-ocaml nix develop dune utop
You should see a utop # prompt, where you can enter OCaml expressions. Use ;; to tell the REPL you've finished typing and it's time to evaluate, e.g.
1 2 utop # 1 + 1 ;; - : int = 2
Alternatively, you can install things using opam (OCaml's package manager):
... continue reading