X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=vrfileman;a=blobdiff_plain;f=src%2Fmain.cc;h=69b7efa5f644de700ac1dd5f9cd70d5c74f0dca3;hp=7e700a6ca661f8110081bda457a2e91bf6d12806;hb=20f18dc9afa4e7a9efb6253edce231f664d14215;hpb=65fa35533b5f8e26b57a31d5972a7649d71ad684 diff --git a/src/main.cc b/src/main.cc index 7e700a6..69b7efa 100644 --- a/src/main.cc +++ b/src/main.cc @@ -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))) { @@ -55,6 +68,7 @@ int main(int argc, char **argv) } time_msec = app_get_msec(); + time_sec = (double)time_msec / 1000.0; while(SDL_PollEvent(&ev)) { process_event(&ev); if(quit) goto break_evloop; @@ -72,6 +86,16 @@ break_evloop: return 0; } +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); +} + void app_quit() { quit = true;