From a422e394925e68ab687ef70527c3e207234d8bd7 Mon Sep 17 00:00:00 2001 From: raysan5 Date: Tue, 26 Jul 2016 16:55:46 +0200 Subject: [PATCH] Corrected issue on OSX with High DPI display Many thanks to Marcelo Paez (paezao) --- README.md | 1 + src/core.c | 21 +++++++++++---------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 71052a0f..64cfcc53 100644 --- a/README.md +++ b/README.md @@ -249,6 +249,7 @@ contributing (in some way or another) to make raylib project better. Huge thanks - [Chris Hemingway](https://github.com/cHemingway) for improving raylib on OSX build system. - [Emanuele Petriglia](https://github.com/LelixSuper) for working on multiple GNU/Linux improvements and developing [TicTacToe](https://github.com/LelixSuper/TicTacToe) raylib game. - [Joshua Reisenauer](https://github.com/kd7tck) for adding audio modules support (XM, MOD) and reviewing audio system. + - Marcelo Paez (paezao) for his help on OSX to solve High DPI display issue. Thanks Marcelo! [raysan5]: mailto:raysan5@gmail.com "Ramon Santamaria - Ray San" diff --git a/src/core.c b/src/core.c index 022fbfe9..0008ef2f 100644 --- a/src/core.c +++ b/src/core.c @@ -1612,16 +1612,7 @@ static void InitGraphicsDevice(int width, int height) { glfwSwapInterval(1); TraceLog(INFO, "Trying to enable VSYNC"); - } - -#ifdef __APPLE__ - // Get framebuffer size of current window - // NOTE: Required to handle HighDPI display correctly - // TODO: Probably should be added for other systems too or managed - // internally by GLFW3 callback: glfwSetFramebufferSizeCallback() - glfwGetFramebufferSize(window, &renderWidth, &renderHeight); -#endif - + } #endif // defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB) #if defined(PLATFORM_ANDROID) || defined(PLATFORM_RPI) @@ -1775,9 +1766,19 @@ static void InitGraphicsDevice(int width, int height) // NOTE: screenWidth and screenHeight not used, just stored as globals rlglInit(screenWidth, screenHeight); +#ifdef __APPLE__ + // Get framebuffer size of current window + // NOTE: Required to handle HighDPI display correctly on OSX because framebuffer + // is automatically reasized to adapt to new DPI. + // When OS does that, it can be detected using GLFW3 callback: glfwSetFramebufferSizeCallback() + int fbWidth, fbHeight; + glfwGetFramebufferSize(window, &fbWidth, &fbHeight); + rlViewport(renderOffsetX/2, renderOffsetY/2, fbWidth - renderOffsetX, fbHeight - renderOffsetY); +#else // Initialize screen viewport (area of the screen that you will actually draw to) // NOTE: Viewport must be recalculated if screen is resized rlViewport(renderOffsetX/2, renderOffsetY/2, renderWidth - renderOffsetX, renderHeight - renderOffsetY); +#endif // Initialize internal projection and modelview matrices // NOTE: Default to orthographic projection mode with top-left corner at (0,0)