From 474fb42807e855825909ed818a6d410b1b062d4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Tue, 21 Jan 2014 16:16:21 +0100 Subject: [PATCH] make it work on retina screens --- include/llmr/map/map.hpp | 2 +- include/llmr/map/transform.hpp | 4 ++++ macosx/main.mm | 18 +++++++++++------- src/map/map.cpp | 4 +++- src/renderer/painter.cpp | 2 +- 5 files changed, 20 insertions(+), 10 deletions(-) diff --git a/include/llmr/map/map.hpp b/include/llmr/map/map.hpp index 3f91c5bc0..b5eef2487 100644 --- a/include/llmr/map/map.hpp +++ b/include/llmr/map/map.hpp @@ -25,7 +25,7 @@ public: void setup(); void loadSettings(); - void resize(uint32_t width, uint32_t height); + void resize(uint32_t width, uint32_t height, uint32_t fb_width, uint32_t fb_height); /* callback */ bool render(); diff --git a/include/llmr/map/transform.hpp b/include/llmr/map/transform.hpp index b16ea5a6d..78c06e2a1 100644 --- a/include/llmr/map/transform.hpp +++ b/include/llmr/map/transform.hpp @@ -53,9 +53,13 @@ private: double pixel_y() const; public: + // logical dimensions uint32_t width; uint32_t height; + // physical (framebuffer) dimensions + uint32_t fb_width; + uint32_t fb_height; private: double x, y; // pixel values of the map center in the current scale diff --git a/macosx/main.mm b/macosx/main.mm index 3fb856444..cbf61eaf9 100644 --- a/macosx/main.mm +++ b/macosx/main.mm @@ -33,14 +33,13 @@ public: exit(1); } + glfwSetWindowUserPointer(window, this); glfwMakeContextCurrent(window); settings.load(); map.setup(); - int width, height; - glfwGetWindowSize(window, &width, &height); - map.resize(width, height); + resize(window, 0, 0); glfwSwapInterval(1); @@ -49,11 +48,10 @@ public: glfwSetCursorPosCallback(window, mousemove); glfwSetMouseButtonCallback(window, mouseclick); glfwSetWindowSizeCallback(window, resize); + glfwSetFramebufferSizeCallback(window, resize); glfwSetScrollCallback(window, scroll); glfwSetCharCallback(window, character); glfwSetKeyCallback(window, key); - - glfwSetWindowUserPointer(window, this); } static void character(GLFWwindow *window, unsigned int codepoint) { @@ -105,9 +103,15 @@ public: view->map.scaleBy(scale, view->last_x, view->last_y); } - static void resize(GLFWwindow *window, int width, int height) { + static void resize(GLFWwindow *window, int, int) { MapView *view = (MapView *)glfwGetWindowUserPointer(window); - view->map.resize(width, height); + + int width, height; + glfwGetWindowSize(window, &width, &height); + int fb_width, fb_height; + glfwGetFramebufferSize(window, &fb_width, &fb_height); + + view->map.resize(width, height, fb_width, fb_height); } static void mouseclick(GLFWwindow *window, int button, int action, int modifiers) { diff --git a/src/map/map.cpp b/src/map/map.cpp index 768a4fc16..913dd7e4a 100644 --- a/src/map/map.cpp +++ b/src/map/map.cpp @@ -32,9 +32,11 @@ void Map::loadSettings() { update(); } -void Map::resize(uint32_t width, uint32_t height) { +void Map::resize(uint32_t width, uint32_t height, uint32_t fb_width, uint32_t fb_height) { transform.width = width; transform.height = height; + transform.fb_width = fb_width; + transform.fb_height = fb_height; update(); } diff --git a/src/renderer/painter.cpp b/src/renderer/painter.cpp index c0e0ce7c9..3928a8e5f 100644 --- a/src/renderer/painter.cpp +++ b/src/renderer/painter.cpp @@ -154,7 +154,7 @@ void Painter::render(const Tile::Ptr& tile) { tile->lineVertex.bind(); glVertexAttribPointer(outlineShader->a_pos, 2, GL_SHORT, GL_FALSE, 0, BUFFER_OFFSET(0)); glUniform4f(outlineShader->u_color, 0.0f, 0.0f, 0.0f, 1.0f); - glUniform2f(outlineShader->u_world, transform.width, transform.height); + glUniform2f(outlineShader->u_world, transform.fb_width, transform.fb_height); glLineWidth(2.0f); glDrawArrays(GL_LINE_STRIP, 0, tile->lineVertex.length());