mouse speed
[laserbrain_demo] / src / main.cc
index 45b5632..4efca60 100644 (file)
@@ -5,7 +5,7 @@
 #include <SDL2/SDL.h>
 #include "app.h"
 
-static bool init();
+static bool init(int argc, char **argv);
 static void process_event(SDL_Event *ev);
 static void proc_modkeys();
 
@@ -41,7 +41,11 @@ int main(int argc, char **argv)
                        SDL_Quit();
                        return 1;
                }
+               fprintf(stderr, "failed to get an sRGB framebuffer.\n");
        }
+       int val;
+       SDL_GL_GetAttribute(SDL_GL_FRAMEBUFFER_SRGB_CAPABLE, &val);
+       printf("SDL says we %s an sRGB framebuffer\n", val ? "got" : "didn't get");
 
        if(!(ctx = SDL_GL_CreateContext(win))) {
                fprintf(stderr, "failed to create OpenGL context\n");
@@ -51,7 +55,7 @@ int main(int argc, char **argv)
        SDL_GL_GetDrawableSize(win, &win_width, &win_height);
        win_aspect = (float)win_width / (float)win_height;
 
-       if(!init()) {
+       if(!init(argc, argv)) {
                SDL_Quit();
                return 1;
        }
@@ -90,11 +94,54 @@ unsigned int app_get_modifiers()
        return modkeys;
 }
 
-static bool init()
+void app_resize(int x, int y)
+{
+       SDL_SetWindowSize(win, x, y);
+}
+
+void app_fullscreen(bool fs)
+{
+       SDL_SetWindowFullscreen(win, fs ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0);
+       fullscreen = fs;
+}
+
+void app_toggle_fullscreen()
+{
+       app_fullscreen(!fullscreen);
+}
+
+bool app_is_fullscreen()
+{
+       return fullscreen;
+}
+
+void app_grab_mouse(bool grab)
+{
+       if(grab) {
+               SDL_WarpMouseInWindow(win, win_width / 2, win_height / 2);
+       }
+       //SDL_SetWindowGrab(win, grab ? SDL_TRUE : SDL_FALSE);
+       //SDL_ShowCursor(grab ? 1 : 0);
+       SDL_SetRelativeMouseMode(grab ? SDL_TRUE : SDL_FALSE);
+       mouse_grabbed = grab;
+}
+
+void app_toggle_grab_mouse()
+{
+       app_grab_mouse(!mouse_grabbed);
+}
+
+bool app_is_mouse_grabbed()
+{
+       return mouse_grabbed;
+}
+
+
+static bool init(int argc, char **argv)
 {
        glewInit();
 
-       if(!app_init()) {
+       if(!app_init(argc, argv)) {
                return false;
        }
 
@@ -124,7 +171,8 @@ static void process_event(SDL_Event *ev)
 
        case SDL_MOUSEMOTION:
                if(mouse_grabbed) {
-                       app_mouse_delta(ev->motion.xrel, ev->motion.yrel);
+                       // XXX xrel/yrel seems faster by default
+                       app_mouse_delta(ev->motion.xrel * 0.75, ev->motion.yrel * 0.75);
                } else {
                        app_mouse_motion(ev->motion.x * scale_factor, ev->motion.y * scale_factor);
                }