From e274d8614de9c3af94f373d675e9a317be1a7e34 Mon Sep 17 00:00:00 2001 From: Luke Krasnoff Date: Sat, 13 Nov 2021 20:39:07 +1030 Subject: [PATCH] Set window high DPI flag in InitWindow. Fix rlScissor call, for Scissor mode, for high DPI screens. --- src/rcore.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/rcore.c b/src/rcore.c index ecdee345a..e53b36dc6 100644 --- a/src/rcore.c +++ b/src/rcore.c @@ -601,6 +601,8 @@ static bool InitGraphicsDevice(int width, int height); // Initialize graphics d static void SetupFramebuffer(int width, int height); // Setup main framebuffer static void SetupViewport(int width, int height); // Set viewport for a provided width and height +static void SetHighDPIFromWindowScale(void); // Helper function to set window high DPI flag from window scale + #if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB) static void ErrorCallback(int error, const char *description); // GLFW3 Error Callback, runs on GLFW3 error // Window callbacks events @@ -805,6 +807,7 @@ void InitWindow(int width, int height, const char *title) SetShapesTexture(texture, (Rectangle){ 0.0f, 0.0f, 1.0f, 1.0f }); #endif #if defined(PLATFORM_DESKTOP) + SetHighDPIFromWindowScale(); if ((CORE.Window.flags & FLAG_WINDOW_HIGHDPI) > 0) { // Set default font texture filter for HighDPI (blurry) @@ -1454,6 +1457,13 @@ void ClearWindowState(unsigned int flags) #endif } +// Helper function to set window high DPI flag from window scale +void SetHighDPIFromWindowScale() +{ + Vector2 scale = GetWindowScaleDPI(); + if (scale.x > 1 || scale.y > 1) SetConfigFlags(FLAG_WINDOW_HIGHDPI); +} + // Set icon for window (only PLATFORM_DESKTOP) // NOTE: Image must be in RGBA format, 8bit per channel void SetWindowIcon(Image image) @@ -2188,7 +2198,8 @@ void BeginScissorMode(int x, int y, int width, int height) { Vector2 scale = GetWindowScaleDPI(); - rlScissor((int)(x*scale.x), (int)(CORE.Window.currentFbo.height - (y + height)*scale.y), (int)(width*scale.x), (int)(height*scale.y)); + rlScissor((int)(x*scale.x), (int)(CORE.Window.currentFbo.height - y*scale.y - height/scale.y), + (int)(width*scale.x), (int)(height*scale.y)); } else {