How the Milton Renderer Works

Sergio González  —  8 months ago
I posted a devlog on Milton's renderer.
This is an excerpt of the post on my hugo site.


After a long time in development, Milton has a brand new renderer. Before now, Milton did all of its rendering on the CPU. The new renderer uses OpenGL to take advantage of the GPU.

I didn’t expect to release OpenGL without problems. I had tested Milton on my machine, which has an Nvidia card. I did some testing with the Intel integrated graphics on this same machine, but I did not do testing with ATI before release.

In the past couple weeks, Milton has gotten some testing from people that aren’t me. At the time of this writing, I am about to ship a new version that corrects some problems with anti-aliasing on non-Nvidia cards.

If Milton works on your machine, then you’ll see how it can handle much more complex paintings now. And for people who use it as a blackboard, which AFAIK is many of Milton’s users thanks to Handmade Hero, it will feel much smoother.

So how does Milton work? Let’s take it step by step

But first, let me say something!

I tried a million things and failed a million times. This is the second renderer for Milton, and for every part of the new renderer that works there were two or three things that didn’t. Perhaps it would have been better to write a chronological document about the development of the renderer, but it would have been way too long. I am only writing a description of the working result, not the months of work that I spent hitting my head against the wall!

With that said, let us begin.

Creating a new stroke

The main loop polls the mouse or (hopefully) the wacom tablet. The mouse gets polled at the Vsync frequency, which is 60hz for most people. This looks really bad. Drawing a circle quickly with the mouse is a great way to create a crappy looking drawing. I will get around to fixing that now that the new renderer is done.

The Wacom is polled at 200hz, or less for lower-end Wacom tablets. The Wacom driver has a limited sample rate. One thing that Milton needs is to do interpolation on the input points.

Milton does some simple smoothing for tablet input. As a stroke is being drawn, every new input point is averaged with the last couple of points. It’s a form of moving average. It’s simple and it works.

Once the stroke is processed, Milton needs to send its information to the GPU, aka “cook it”, so that it can be rendered. A stroke might be cooked several times. If a stroke is within the bounds of the screen and it hasn’t been cooked yet, it gets cooked. If it ever gets within some threshold away from the screen, it gets freed from the GPU.

continues here...

Log in to comment