+#include <stdio.h>
+#include <stdlib.h>
+#include <SDL2/SDL.h>
+#include "app.h"
+
+static void process_event(SDL_Event *ev);
+
+static SDL_Window *win;
+static SDL_GLContext ctx;
+static bool redraw_pending = true;
+static bool quit;
+
+int main(int argc, char **argv)
+{
+ if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) == -1) {
+ fprintf(stderr, "failed to initialize SDL\n");
+ return 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;
+ }
+
+ 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);
+ app_reshape(win_width, win_height);
+
+ while(!quit) {
+ SDL_Event ev;
+
+ if(!redraw_pending) {
+ if(!SDL_WaitEvent(0)) {
+ fprintf(stderr, "error while waiting for events\n");
+ break;
+ }
+ }
+
+ time_msec = app_get_msec();
+ while(SDL_PollEvent(&ev)) {
+ process_event(&ev);
+ if(quit) goto break_evloop;
+ }
+
+ if(redraw_pending) {
+ redraw_pending = false;
+ app_draw();
+ }
+ }
+break_evloop:
+
+ app_cleanup();
+ SDL_Quit();
+ return 0;
+}
+
+void app_redraw()
+{
+ redraw_pending = true;
+}
+
+void app_swap_buffers()
+{
+ SDL_GL_SwapWindow(win);
+}
+
+long app_get_msec()
+{
+ return SDL_GetTicks();
+}