Merge branch 'master' of goat:git/vrfileman
authorJohn Tsiombikas <nuclear@mutantstargoat.com>
Wed, 3 Aug 2016 06:22:07 +0000 (09:22 +0300)
committerJohn Tsiombikas <nuclear@mutantstargoat.com>
Wed, 3 Aug 2016 06:22:07 +0000 (09:22 +0300)
src/app.h
src/main.cc
src/opt.cc
src/opt.h

index 0030a9d..c3d5f03 100644 (file)
--- a/src/app.h
+++ b/src/app.h
@@ -2,6 +2,7 @@
 #define APP_H_
 
 #include "gmath/gmath.h"
+#include "opt.h"
 
 extern int win_width, win_height;
 extern float win_aspect;
index 04f8523..69b7efa 100644 (file)
@@ -10,6 +10,18 @@ static SDL_GLContext ctx;
 static bool redraw_pending = true;
 static bool quit;
 
+static SDL_Window *create_window(int width, int height)
+{
+       SDL_Window *win;
+       int x = SDL_WINDOWPOS_UNDEFINED;
+       int y = SDL_WINDOWPOS_UNDEFINED;
+       unsigned int flags = SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI;
+       if(!(win = SDL_CreateWindow("vrfileman", x, y, width, height, flags))) {
+               return 0;
+       }
+       return win;
+}
+
 int main(int argc, char **argv)
 {
        if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) == -1) {
@@ -18,17 +30,18 @@ int main(int argc, char **argv)
        }
 
        SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
-       SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 4);
+       SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 8);
        SDL_GL_SetAttribute(SDL_GL_FRAMEBUFFER_SRGB_CAPABLE, 1);
 
-       int x = SDL_WINDOWPOS_UNDEFINED;
-       int y = SDL_WINDOWPOS_UNDEFINED;
-       unsigned int flags = SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI;
-       win_width = 1280;
-       win_height = 800;
-       if(!(win = SDL_CreateWindow("vrfileman", x, y, win_width, win_height, flags))) {
-               fprintf(stderr, "failed to create window\n");
-               return 1;
+       if(!(win = create_window(def_opt.width, def_opt.height))) {
+               // try again without the SRGB capability
+               SDL_GL_SetAttribute(SDL_GL_FRAMEBUFFER_SRGB_CAPABLE, 0);
+               if(!(win = create_window(win_width, win_height))) {
+                       fprintf(stderr, "failed to create window\n");
+                       return 1;
+               }
+               fprintf(stderr, "failed to create sRGB-capable window, defaulting to non-linear color space\n");
+               def_opt.srgb = false;
        }
 
        if(!(ctx = SDL_GL_CreateContext(win))) {
index 6698f8c..6e22113 100644 (file)
@@ -6,6 +6,14 @@
 
 Options opt;
 
+Options def_opt = {
+       1280, 800,
+       false,  // vr
+       true,   // srgb
+       false,  // fullscreen
+       0               // path
+};
+
 enum {
        OPT_SIZE,
        OPT_VR,
@@ -32,10 +40,7 @@ static int arg_handler(optcfg *oc, const char *arg, void *cls);
 bool init_options(int argc, char **argv, const char *cfgfile)
 {
        // default options
-       memset(&opt, 0, sizeof opt);
-       opt.width = 1280;
-       opt.height = 800;
-       opt.srgb = true;
+       opt = def_opt;
 
        optcfg *oc = optcfg_init(options);
        optcfg_set_opt_callback(oc, opt_handler, 0);
index d47d8e3..8f7d964 100644 (file)
--- a/src/opt.h
+++ b/src/opt.h
@@ -9,7 +9,7 @@ struct Options {
        const char *path;
 };
 
-extern Options opt;
+extern Options opt, def_opt;
 
 bool init_options(int argc, char **argv, const char *cfgfile);