From 5e3ef4220185781d31190723a149d42c30aac492 Mon Sep 17 00:00:00 2001 From: gulrak Date: Thu, 9 Jun 2022 21:00:04 +0200 Subject: [PATCH] GetMonitorWidth()/GetMonitorHeight(): return current video resolution instead max available (#2514) * GetMonitorWidth()/GetMonitorHeight(): current video resolution instead max available * adapt header comment to reflect change --- src/raylib.h | 4 ++-- src/rcore.c | 20 +++++++------------- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/src/raylib.h b/src/raylib.h index b6037eda2..472181299 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -939,8 +939,8 @@ RLAPI int GetRenderHeight(void); // Get current RLAPI int GetMonitorCount(void); // Get number of connected monitors RLAPI int GetCurrentMonitor(void); // Get current connected monitor RLAPI Vector2 GetMonitorPosition(int monitor); // Get specified monitor position -RLAPI int GetMonitorWidth(int monitor); // Get specified monitor width (max available by monitor) -RLAPI int GetMonitorHeight(int monitor); // Get specified monitor height (max available by monitor) +RLAPI int GetMonitorWidth(int monitor); // Get specified monitor width (current video mode used by monitor) +RLAPI int GetMonitorHeight(int monitor); // Get specified monitor height (current video mode used by monitor) RLAPI int GetMonitorPhysicalWidth(int monitor); // Get specified monitor physical width in millimetres RLAPI int GetMonitorPhysicalHeight(int monitor); // Get specified monitor physical height in millimetres RLAPI int GetMonitorRefreshRate(int monitor); // Get specified monitor refresh rate diff --git a/src/rcore.c b/src/rcore.c index fa9fdf932..6dca7ddc8 100644 --- a/src/rcore.c +++ b/src/rcore.c @@ -1723,7 +1723,7 @@ int GetCurrentMonitor(void) #endif } -// Get selected monitor width +// Get selected monitor position Vector2 GetMonitorPosition(int monitor) { #if defined(PLATFORM_DESKTOP) @@ -1742,7 +1742,7 @@ Vector2 GetMonitorPosition(int monitor) return (Vector2){ 0, 0 }; } -// Get selected monitor width (max available by monitor) +// Get selected monitor width (currently used by monitor) int GetMonitorWidth(int monitor) { #if defined(PLATFORM_DESKTOP) @@ -1751,11 +1751,8 @@ int GetMonitorWidth(int monitor) if ((monitor >= 0) && (monitor < monitorCount)) { - int count = 0; - const GLFWvidmode *modes = glfwGetVideoModes(monitors[monitor], &count); - - // We return the maximum resolution available, the last one in the modes array - if (count > 0) return modes[count - 1].width; + const GLFWvidmode *mode = glfwGetVideoMode(monitors[monitor]); + if(mode) return mode->width; else TRACELOG(LOG_WARNING, "GLFW: Failed to find video mode for selected monitor"); } else TRACELOG(LOG_WARNING, "GLFW: Failed to find selected monitor"); @@ -1763,7 +1760,7 @@ int GetMonitorWidth(int monitor) return 0; } -// Get selected monitor width (max available by monitor) +// Get selected monitor height (currently used by monitor) int GetMonitorHeight(int monitor) { #if defined(PLATFORM_DESKTOP) @@ -1772,11 +1769,8 @@ int GetMonitorHeight(int monitor) if ((monitor >= 0) && (monitor < monitorCount)) { - int count = 0; - const GLFWvidmode *modes = glfwGetVideoModes(monitors[monitor], &count); - - // We return the maximum resolution available, the last one in the modes array - if (count > 0) return modes[count - 1].height; + const GLFWvidmode *mode = glfwGetVideoMode(monitors[monitor]); + if(mode) return mode->height; else TRACELOG(LOG_WARNING, "GLFW: Failed to find video mode for selected monitor"); } else TRACELOG(LOG_WARNING, "GLFW: Failed to find selected monitor");