Archive for July, 2024

Papercut: Bump Caps in VSCodium

Monday, July 29th, 2024

A large portion of my game is written in TypeScript. For these portions of the game, I often use VSCodium to write it. However, there’s one aspect of auto-completion that is not working very well, and that is… bump-caps.

For some reason I can’t find any references of it by this name though I have a strong association of this feature with that name in my mind, but the idea of bump-caps is that when you’ve typed an upper-case letter, any candidate must also have an upper-case letter there. For example, ArrayList would be an OK candidate for AL, but Arraylist would be unacceptable because it does not have an upper-case L. Of course, you can have lower-case letters too – they are handy for disambiguation. For example, ArL would keep ArrayList in consideration while excluding e.g. ActiveLayer.

(more…)

Sort Out Your PODs

Monday, July 22nd, 2024

Some time ago I was helping a friend debug a crash in an application they were working on. It worked fine in production, but when running it on a smaller test file, it kept crashing. However, the crash was always on exit – the application itself seemed to run without issue. The crash was from a free, complaining about the pointer:

free(): invalid pointer
Aborted

GDB showed the offending free was from compiler-generated code, with no user code on the stack:

(more…)

Cross-compiling for Steam Deck from Apple Silicon Mac

Monday, July 15th, 2024

Most of the development of my game has been happening on my M2 MacBook Air. One of the main places I’d like to play the game, though, is on my Steam Deck. In order to play the game on my Steam Deck, I need to compile it for the Steam Deck. There’s a number of ways I could do this, but I wanted a solution that would let me compile on my Mac directly with minimal infrastructure fuss (no VMs, network access, user mode emulation, etc).

SteamOS SDK

Poking around, games can run in one of a number of runtimes, each with a standardized set of libraries available. We’ll be going with the latest, “sniper”. You can find information about it on Valve’s web site.

The file we’re interested in is the developer sysroot (latest version as of writing). This has all the libraries that would be needed at runtime, plus all the header files, library symlinks, static archives, and other files we’d need for development. It also contains a compiler ready for use, except that the compiler is compiled for x86_64, while we’re on AArch64, so we can’t run the compiler directly. Also, it’s compiled for Linux, but we’re on macOS.

(more…)

Color Space Correctness in Alpha Blending

Monday, July 8th, 2024

Take a look at these three grayscale images:

Solid grayscale image with value 128Grayscale checkerboard with values 64 and 192Solid grayscale image with value 146

The left image has a solid luminance of 128. The middle image is a checkerboard alternating between luminances of 64 and 192. The right image has a solid luminance of 146. Squint your eyes. Does the luminance in the middle look closer to the luminance on the left, or on the right?

As a checkerboard, the center image is 50% 64 and 50% 192, so mathematically, it should average out to 128, but instead, there’s a substantial difference in luminance, and 146 is much closer. The reason for this discrepancy: All values in these images are sRGB values. When colors mix in the real world, the absolute amount of light is what’s mixed, but sRGB is a non-linear mapping, so attempting to mix sRGB values directly yields nonphysical results. You can read more about this in Eric Brasseur’s blog post, “Gamma error in picture scaling”.

Eric’s post is all about image scaling, where this definitely matters. But this is far from the only place this matters. Near and dear to our hearts from the previous post, blending in OpenGL also has to mix colors in a way that could be affected by use of the wrong color space for computations. Indeed, the blend formula says nothing about the relatively complicated conversions needed for sRGB. So what happens?

(more…)

Take Care with your Blend Function

Monday, July 1st, 2024

“Everyone” knows that the usual “over” composition operation is as such:

glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

However, this can in some cases lead to artifacting:

Correct Incorrect
Properly blended black text on orange background Improperly blended black text with white halo on orange background

Observe the halo effect in the “incorrect” image. I observed this effect when using WebGL on a web page, so in this case, the white color of the halo was the white background color of the web page peeking through. But why was the background peeking through?

(more…)