From daf685f6e785a7b6cae559d879fa2e8bb66f63d3 Mon Sep 17 00:00:00 2001 From: John Tsiombikas Date: Mon, 15 Aug 2016 08:16:26 +0300 Subject: [PATCH] fixed hidpi on mac --- Makefile | 1 + src/main.cc | 12 +++++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index a9b2486..274986d 100644 --- a/Makefile +++ b/Makefile @@ -18,6 +18,7 @@ LDFLAGS = $(libgl) -lgmath -limago -lgoatvr -loptcfg -ldrawtext `pkg-config --li ifeq ($(shell uname -s), Darwin) + inc += -I/usr/local/include libgl = -framework OpenGL -lGLEW else libgl = -lGL -lGLEW diff --git a/src/main.cc b/src/main.cc index 69b7efa..82454fd 100644 --- a/src/main.cc +++ b/src/main.cc @@ -10,6 +10,8 @@ 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; @@ -36,7 +38,7 @@ int main(int argc, char **argv) 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))) { + if(!(win = create_window(def_opt.width, def_opt.height))) { fprintf(stderr, "failed to create window\n"); return 1; } @@ -131,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; -- 1.7.10.4