-no-srgb option
authorJohn Tsiombikas <nuclear@mutantstargoat.com>
Wed, 27 Jul 2016 02:24:18 +0000 (05:24 +0300)
committerJohn Tsiombikas <nuclear@mutantstargoat.com>
Wed, 27 Jul 2016 02:24:18 +0000 (05:24 +0300)
src/app.cc
src/backdrop.cc
src/color.cc [new file with mode: 0644]
src/color.h [new file with mode: 0644]
src/texture.cc

index e9e4cbb..81325f6 100644 (file)
@@ -42,10 +42,8 @@ bool app_init(int argc, char **argv)
 
        glEnable(GL_CULL_FACE);
        glEnable(GL_DEPTH_TEST);
-       //glEnable(GL_LIGHTING);
-       glEnable(GL_LIGHT0);
 
-       if(GLEW_ARB_framebuffer_sRGB) {
+       if(opt.srgb && GLEW_ARB_framebuffer_sRGB) {
                printf("enabling sRGB framebuffer\n");
                glEnable(GL_FRAMEBUFFER_SRGB);
        }
index b81a04a..91c709a 100644 (file)
@@ -6,6 +6,7 @@
 #include "meshgen.h"
 #include "backdrop.h"
 #include "app.h"
+#include "color.h"
 
 static unsigned int sdr_grid;
 static Texture *tex_grid;
@@ -13,14 +14,15 @@ static Texture *tex_grid;
 static Mesh *mesh_skydome;
 static unsigned int sdr_skydome;
 
-static const Vec3 grid_color = Vec3(1.0, 0.07, 1.0);
-static const Vec3 mid_color = Vec3(0.133, 0.006, 0.612);
-static const Vec3 horiz_color = Vec3(0.612, 0.006, 1.0);
-static const Vec3 zenith_color = Vec3(0.029, 0.029, 0.029);
-static const Vec3 fog_color = Vec3(0.01, 0.01, 0.01);
 
 bool init_backdrop()
 {
+       Vec3 grid_color = color(1.0, 0.07, 1.0);
+       Vec3 mid_color = color(0.133, 0.006, 0.612);
+       Vec3 horiz_color = color(0.612, 0.006, 1.0);
+       Vec3 zenith_color = color(0.029, 0.029, 0.029);
+       Vec3 fog_color = color(0.01, 0.01, 0.01);
+
        if(!(sdr_grid = create_program_load("sdr/grid.v.glsl", "sdr/grid.p.glsl"))) {
                return false;
        }
diff --git a/src/color.cc b/src/color.cc
new file mode 100644 (file)
index 0000000..ae27f89
--- /dev/null
@@ -0,0 +1,19 @@
+#include "color.h"
+#include "opt.h"
+
+Color color(float r, float g, float b)
+{
+       return opt.srgb ? Color(r, g, b) : linear_to_srgb(Color(r, g, b));
+}
+
+Color linear_to_srgb(const Color &c)
+{
+       const float inv_gamma = 1.0f / 2.2f;
+       return Color(pow(c.x, inv_gamma), pow(c.y, inv_gamma), pow(c.z, inv_gamma));
+}
+
+Color srgb_to_linear(const Color &c)
+{
+       const float gamma = 2.2f;
+       return Color(pow(c.x, gamma), pow(c.y, gamma), pow(c.z, gamma));
+}
diff --git a/src/color.h b/src/color.h
new file mode 100644 (file)
index 0000000..2fe4db4
--- /dev/null
@@ -0,0 +1,12 @@
+#ifndef COLOR_H_
+#define COLOR_H_
+
+#include "gmath/gmath.h"
+
+typedef Vec3 Color;
+
+Color color(float r, float g, float b);
+Color linear_to_srgb(const Color &c);
+Color srgb_to_linear(const Color &c);
+
+#endif // COLOR_H_
index f332efa..49f3aab 100644 (file)
@@ -3,6 +3,7 @@
 #include "image.h"
 #include "opengl.h"
 #include "imago2.h"
+#include "opt.h"
 
 #if defined(GL_ES_VERSION_2_0) || defined(GL_VERSION_3_0)
 #define USE_GL_GENERATE_MIPMAP
@@ -394,21 +395,23 @@ static int gltype_from_ifmt(unsigned int ifmt)
 
 static int glifmt_from_imgfmt(Image::Format fmt)
 {
+       bool use_srgb = GLEW_EXT_texture_sRGB && opt.srgb;
+
        switch(fmt) {
        case Image::FMT_GREY:
-               return GLEW_EXT_texture_sRGB ? GL_SLUMINANCE : GL_LUMINANCE;
+               return use_srgb ? GL_SLUMINANCE : GL_LUMINANCE;
 
        case Image::FMT_GREY_FLOAT:
                return GL_LUMINANCE16F;
 
        case Image::FMT_RGB:
-               return GLEW_EXT_texture_sRGB ? GL_SRGB : GL_RGB;
+               return use_srgb ? GL_SRGB : GL_RGB;
 
        case Image::FMT_RGB_FLOAT:
                return GL_RGB16F;
 
        case Image::FMT_RGBA:
-               return GLEW_EXT_texture_sRGB ? GL_SRGB_ALPHA : GL_RGBA;
+               return use_srgb ? GL_SRGB_ALPHA : GL_RGBA;
 
        case Image::FMT_RGBA_FLOAT:
                return GL_RGBA16F;