diff options
author | Erik Faye-Lund <erik.faye-lund@collabora.com> | 2020-07-01 18:41:32 +0200 |
---|---|---|
committer | Erik Faye-Lund <erik.faye-lund@collabora.com> | 2020-07-06 14:04:41 +0200 |
commit | 8c73555b4dd55c26510b5792599083cf8d802745 (patch) | |
tree | 75e0a00bbc61b81dba15e4d35d7869c96c9f7c8d | |
parent | 3260f665cb275f72d5f66879a99b4eb254b46d5b (diff) |
glxgears / wglgears: adjust colors for sRGB
Without this, the colors have a very different look, making the red more
orange. This adjust the colors to give the same appearance.
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
-rw-r--r-- | src/wgl/wglgears.c | 13 | ||||
-rw-r--r-- | src/xdemos/glxgears.c | 12 |
2 files changed, 25 insertions, 0 deletions
diff --git a/src/wgl/wglgears.c b/src/wgl/wglgears.c index 9efebea9..377d5b53 100644 --- a/src/wgl/wglgears.c +++ b/src/wgl/wglgears.c @@ -277,6 +277,14 @@ reshape(int width, int height) } +static GLfloat +srgb_to_linear(GLfloat c) +{ + if (c <= 0.04045f) + return c / 12.92f; + return powf((c + 0.055f) / 1.055f, 2.4f); +} + static void init(void) { @@ -291,6 +299,11 @@ init(void) glEnable(GL_LIGHT0); glEnable(GL_DEPTH_TEST); if (use_srgb) { + for (int i = 0; i < 3; ++i) { + red[i] = srgb_to_linear(red[i]); + green[i] = srgb_to_linear(green[i]); + blue[i] = srgb_to_linear(blue[i]); + } glEnable(GL_FRAMEBUFFER_SRGB); } diff --git a/src/xdemos/glxgears.c b/src/xdemos/glxgears.c index fbc492d5..dd6f95e9 100644 --- a/src/xdemos/glxgears.c +++ b/src/xdemos/glxgears.c @@ -387,6 +387,13 @@ reshape(int width, int height) } +static GLfloat +srgb_to_linear(GLfloat c) +{ + if (c <= 0.04045f) + return c / 12.92f; + return powf((c + 0.055f) / 1.055f, 2.4f); +} static void init(void) @@ -402,6 +409,11 @@ init(void) glEnable(GL_LIGHT0); glEnable(GL_DEPTH_TEST); if (use_srgb) { + for (int i = 0; i < 3; ++i) { + red[i] = srgb_to_linear(red[i]); + green[i] = srgb_to_linear(green[i]); + blue[i] = srgb_to_linear(blue[i]); + } glEnable(GL_FRAMEBUFFER_SRGB); } |