GammaCorrectTest illustrates gamma correction and linear-to-sRGB conversion, using a GLSL shader with OpenGL. It is part of a set of programs introducing the use of Modern OpenGL, which are intended to accompany a possible second edition of the book 3D Computer Graphics: A mathematical approach with OpenGL, Cambridge University Press, 2003.

GammaCorrectTest draws a color at five different intensity (from black to fully saturated). On the righthand side of the screen, the color is drawn by setting RGB values to 0.0, 0.25, 0.5, 0.75 and 1.0 in five retangular blocks. On the lefthand side of the screen, the approximately the same colors are rendered by dithering colors, namely, by lighting up some the pixels to full intensity and leaving other pixels turned off.

In an ideal world, the overall brightness of the colors on the left should match the brightness of the colors on the right. But, due to non-linearities in color rendering and perception, there will be some discrepancy. The purpose of gamma correction or of the use of sRGB colors is to minimize these discrepancies.

The program can be downloaded from:

How to run the program:

  1. The goal is to make the rectangles on the left have the same overall color and brightness as the rectangles on the right.
  2. The most important keyboard/mouse inputs are:
    • Press 'R', 'G', 'B', 'C', 'M', 'Y' or 'W' to select one of the colors red, green, blue, cyan, magenta, yellow or white. (You may wish to squint a little to hide the pixelation on the left; the color Blue may be the easiest to view.)
    • Press 'S' to toggle sRGB off and on.
    • Click and hold the left mouse button, and drag left or right to change the gamma (γ). Dragging left decreases gamma; dragging right increases gamma. When the mouse button is released, the value of gamma is printed in the console text window. You may find that a gamma value somewhere the range 0.4 to 0.65 gives the best results.
    • The value of gamma is initially 1, and you can type 'L' (for "linear") to reset gamma to equal to 1.
    • When sRGB mode is turned on, the sRGB calculation is used for colors on the left (instead of gamma correction). If your monitor is well-designed and well-calibrated, it should give better effects that what can be achieved with any gamma value.
    • The black borders can be toggled by pressing 'U'.
  3. See the more detailed description of the program's functionality and how it uses a fragment shader with gl_FragCoord to dither colors..

Version 0.2 of GammaCorrectTest, April 2, 2019.