Posts Tagged ‘OpenGL’

Tracking Down a macOS OpenGL Texture Error

Monday, August 12th, 2024

While working on my game, I received this cryptic error, along with no textures visible:

UNSUPPORTED (log once): POSSIBLE ISSUE: unit 0 GLD_TEXTURE_INDEX_2D is unloadable and bound to sampler type (Float) – using zero texture because texture unloadable

There are various mentions of this error around the web. Most of them are random peoples’ bug reports that end up being closed without resolution, but there were a few useful resources I came across.

(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…)

How to Use ANGLE in your SDL Program

Monday, May 27th, 2024

ANGLE is handy. Built to support WebGL in Chromium, it acts as a polyfill for OpenGL ES atop a plethora of other rendering APIs. Since it exposes a single graphics API you can build your application around, you might wonder about how you could use it with SDL, which provides a similarly “single API” experience for windowing and input. The answer is embarrassingly easy.

(more…)