summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRay <[email protected]>2020-10-29 19:29:59 +0100
committerRay <[email protected]>2020-10-29 19:29:59 +0100
commit60d874caf8ab32e57d4a356d1a15709cadd98de0 (patch)
treebd9d621cce73fcb6449964e000178be61bfa9777
parent37e2d993e7c690582fd941308b970639246f36c8 (diff)
downloadraylib-60d874caf8ab32e57d4a356d1a15709cadd98de0.tar.gz
raylib-60d874caf8ab32e57d4a356d1a15709cadd98de0.zip
REVIEWED: GetWindowScaleDPI() #1086
-rw-r--r--src/core.c27
1 files changed, 23 insertions, 4 deletions
diff --git a/src/core.c b/src/core.c
index 9b3cf557..a37d70f1 100644
--- a/src/core.c
+++ b/src/core.c
@@ -1352,10 +1352,29 @@ Vector2 GetWindowScaleDPI(void)
Vector2 scale = { 1.0f, 1.0f };
#if defined(PLATFORM_DESKTOP)
- GLFWmonitor *monitor = glfwGetPrimaryMonitor();
+ float xdpi = 1.0;
+ float ydpi = 1.0;
+ Vector2 windowPos = GetWindowPosition();
+
+ int monitorCount = 0;
+ GLFWmonitor **monitors = glfwGetMonitors(&monitorCount);
- if (monitor != NULL) glfwGetMonitorContentScale(monitor, &scale.x, &scale.y);
- else TRACELOG(LOG_WARNING, "GLFW: Failed to get primary monitor");
+ // Check window monitor
+ for (int i = 0; i < monitorCount; i++)
+ {
+ glfwGetMonitorContentScale(monitors[i], &xdpi, &ydpi);
+
+ int xpos, ypos, width, height;
+ glfwGetMonitorWorkarea(monitors[i], &xpos, &ypos, &width, &height);
+
+ if ((windowPos.x >= xpos) && (windowPos.x < xpos + width) &&
+ (windowPos.y >= ypos) && (windowPos.y < ypos + height))
+ {
+ scale.x = xdpi;
+ scale.y = ydpi;
+ break;
+ }
+ }
#endif
return scale;
@@ -1626,7 +1645,7 @@ void BeginTextureMode(RenderTexture2D target)
{
rlglDraw(); // Draw Buffers (Only OpenGL 3+ and ES2)
- rlEnableFramebuffer(target.id); // Enable render target
+ rlEnableFramebuffer(target.id); // Enable render target
// Set viewport to framebuffer size
rlViewport(0, 0, target.texture.width, target.texture.height);