Skip to content

Commit d01f158

Browse files
committed
REVIEWED: Window initialization on HighDPI monitor (Windows) #5549
1 parent 180c3c1 commit d01f158

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

examples/core/core_highdpi_testbed.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ int main(void)
7878
DrawText(TextFormat("WINDOW POSITION: %ix%i", (int)windowPos.x, (int)windowPos.y), 50, 90, 20, DARKGRAY);
7979
DrawText(TextFormat("SCREEN SIZE: %ix%i", GetScreenWidth(), GetScreenHeight()), 50, 130, 20, DARKGRAY);
8080
DrawText(TextFormat("RENDER SIZE: %ix%i", GetRenderWidth(), GetRenderHeight()), 50, 170, 20, DARKGRAY);
81-
DrawText(TextFormat("SCALE FACTOR: %.1fx%.1f", scaleDpi.x, scaleDpi.y), 50, 210, 20, GRAY);
81+
DrawText(TextFormat("SCALE FACTOR: %.2fx%.2f", scaleDpi.x, scaleDpi.y), 50, 210, 20, GRAY);
8282

8383
// Draw reference rectangles, top-left and bottom-right corners
8484
DrawRectangle(0, 0, 30, 60, RED);

src/platforms/rcore_desktop_glfw.c

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1649,31 +1649,34 @@ int InitPlatform(void)
16491649
TRACELOG(LOG_INFO, "DISPLAY: Trying to enable VSYNC");
16501650
}
16511651

1652-
int fbWidth = CORE.Window.screen.width;
1653-
int fbHeight = CORE.Window.screen.height;
1654-
16551652
if (FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_HIGHDPI))
16561653
{
1654+
// Set screen size to logical pixel size, considering content scaling
1655+
Vector2 scaleDpi = GetWindowScaleDPI();
1656+
CORE.Window.render.width = (int)(CORE.Window.screen.width*scaleDpi.x);
1657+
CORE.Window.render.height = (int)(CORE.Window.screen.height*scaleDpi.y);
1658+
16571659
// NOTE: On APPLE platforms system should manage window/input scaling and also framebuffer scaling
16581660
// Framebuffer scaling is activated with: glfwWindowHint(GLFW_SCALE_FRAMEBUFFER, GLFW_TRUE);
1659-
16601661
// Get current framebuffer size, on high-dpi it could be bigger than screen size
1661-
glfwGetFramebufferSize(platform.handle, &fbWidth, &fbHeight);
1662+
//glfwGetFramebufferSize(platform.handle, &fbWidth, &fbHeight);
16621663

16631664
// Screen scaling matrix is required in case desired screen area is different from display area
1664-
CORE.Window.screenScale = MatrixScale((float)fbWidth/CORE.Window.screen.width, (float)fbHeight/CORE.Window.screen.height, 1.0f);
1665+
CORE.Window.screenScale = MatrixScale(scaleDpi.x, scaleDpi.y, 1.0f);
16651666
#if !defined(__APPLE__)
16661667
// Mouse input scaling for the new screen size
1667-
SetMouseScale((float)CORE.Window.screen.width/fbWidth, (float)CORE.Window.screen.height/fbHeight);
1668+
SetMouseScale(1.0f/scaleDpi.x, 1.0f/scaleDpi.y);
16681669
#endif
1670+
glfwSetWindowSize(platform.handle, CORE.Window.render.width, CORE.Window.render.height);
1671+
}
1672+
else
1673+
{
1674+
CORE.Window.render = CORE.Window.screen;
1675+
CORE.Window.currentFbo = CORE.Window.render;
16691676
}
16701677

1671-
CORE.Window.render.width = fbWidth;
1672-
CORE.Window.render.height = fbHeight;
1673-
CORE.Window.currentFbo.width = fbWidth;
1674-
CORE.Window.currentFbo.height = fbHeight;
1675-
1676-
TRACELOG(LOG_INFO, "DISPLAY: Device initialized successfully");
1678+
TRACELOG(LOG_INFO, "DISPLAY: Device initialized successfully %s",
1679+
FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_HIGHDPI)? "(HighDPI)" : "");
16771680
TRACELOG(LOG_INFO, " > Display size: %i x %i", CORE.Window.display.width, CORE.Window.display.height);
16781681
TRACELOG(LOG_INFO, " > Screen size: %i x %i", CORE.Window.screen.width, CORE.Window.screen.height);
16791682
TRACELOG(LOG_INFO, " > Render size: %i x %i", CORE.Window.render.width, CORE.Window.render.height);

0 commit comments

Comments
 (0)