cybergrid
[vrfileman] / src / main.cc
index 66e8e98..942db47 100644 (file)
@@ -17,6 +17,10 @@ int main(int argc, char **argv)
                return 1;
        }
 
+       SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
+       SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 1);
+       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;
@@ -27,17 +31,17 @@ int main(int argc, char **argv)
                return 1;
        }
 
-       SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
-       SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
-       SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
-       SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
-       SDL_GL_SetAttribute(SDL_GL_FRAMEBUFFER_SRGB_CAPABLE, 1);
-
        if(!(ctx = SDL_GL_CreateContext(win))) {
                fprintf(stderr, "failed to create OpenGL context\n");
                return 1;
        }
        SDL_GL_GetDrawableSize(win, &win_width, &win_height);
+       win_aspect = (float)win_width / (float)win_height;
+
+       if(!app_init(argc, argv)) {
+               SDL_Quit();
+               return 1;
+       }
        app_reshape(win_width, win_height);
 
        while(!quit) {
@@ -68,6 +72,11 @@ break_evloop:
        return 0;
 }
 
+void app_quit()
+{
+       quit = true;
+}
+
 void app_redraw()
 {
        redraw_pending = true;
@@ -82,3 +91,36 @@ long app_get_msec()
 {
        return SDL_GetTicks();
 }
+
+static void process_event(SDL_Event *ev)
+{
+       switch(ev->type) {
+       case SDL_QUIT:
+               quit = true;
+               break;
+
+       case SDL_KEYDOWN:
+       case SDL_KEYUP:
+               app_keyboard(ev->key.keysym.sym, ev->key.state == SDL_PRESSED);
+               break;
+
+       case SDL_MOUSEBUTTONDOWN:
+       case SDL_MOUSEBUTTONUP:
+               app_mouse_button(ev->button.button - SDL_BUTTON_LEFT, ev->button.state == SDL_PRESSED,
+                               ev->button.x, ev->button.y);
+               break;
+
+       case SDL_MOUSEMOTION:
+               app_mouse_motion(ev->motion.x, ev->motion.y);
+               break;
+
+       case SDL_WINDOWEVENT:
+               if(ev->window.event == SDL_WINDOWEVENT_RESIZED) {
+                       win_width = ev->window.data1;
+                       win_height = ev->window.data2;
+                       win_aspect = (float)win_width / (float)win_height;
+                       app_reshape(win_width, win_height);
+               }
+               break;
+       }
+}