X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=vrfileman;a=blobdiff_plain;f=src%2Fmain.cc;h=82454fd9c389c985e99a6ffe59c9a6900737110e;hp=04f85236714a049353d92b91d8b1ae0473a404ed;hb=daf685f6e785a7b6cae559d879fa2e8bb66f63d3;hpb=8afeabf06c79c755e5aaffa224e06c4abc92d833 diff --git a/src/main.cc b/src/main.cc index 04f8523..82454fd 100644 --- a/src/main.cc +++ b/src/main.cc @@ -10,6 +10,20 @@ static SDL_GLContext ctx; static bool redraw_pending = true; static bool quit; +static int scale_factor = 1; + +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 +32,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(def_opt.width, def_opt.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))) { @@ -118,18 +133,18 @@ static void process_event(SDL_Event *ev) 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); + ev->button.x * scale_factor, ev->button.y * scale_factor); break; case SDL_MOUSEMOTION: - app_mouse_motion(ev->motion.x, ev->motion.y); + app_mouse_motion(ev->motion.x * scale_factor, ev->motion.y * scale_factor); break; case SDL_WINDOWEVENT: if(ev->window.event == SDL_WINDOWEVENT_RESIZED) { - win_width = ev->window.data1; - win_height = ev->window.data2; + SDL_GL_GetDrawableSize(win, &win_width, &win_height); win_aspect = (float)win_width / (float)win_height; + scale_factor = win_width / ev->window.data1; app_reshape(win_width, win_height); } break;