Today I Learned - Rocky Kev

TIL how fonts draw greyscale

POSTED ON:

TAGS:

This may be super esoteric knowledge and could have incredibly limited usecases beyond this post.

But TIL sometimes doesn't have actionable steps -- but just fascinating tidbits.

Via https://github.com/mmulet/code-relay/blob/main/markdown/HowIDidIt.md#a-you-dont

How do you get color?

A: You don't!

All the color is "fake" in that there is nothing telling the renderer to draw a gray pixel, it all relies on undefined behavior and suggestion. Basically we are trying to "trick" the renderer into drawing shades of gray by drawing "pixels" of smaller and smaller sizes:

Pixels To draw a gray pixel we draw our pixels at a size smaller than an actual physical pixel, then the renderer will "average" the total color of the pixel together, so if we make our pixel half-white, half-black we end up with a gray pixel. Take a look at this example:

The first cloud on the left has a perfect dark gray, while the cloud on the right, failed. It to doesn't work all the time, but when it fails, it looks like scan-lines which gamers (at least, retro-gamers) are used to.


Related TILs

Tagged:

TIL how fonts draw greyscale

This may be super esoteric knowledge and could have incredibly limited usecases beyond this post.

TIL how fonts draw greyscale

This may be super esoteric knowledge and could have incredibly limited usecases beyond this post.

TIL how fonts draw greyscale

This may be super esoteric knowledge and could have incredibly limited usecases beyond this post.