From 52e90bf55da282f5da201b210a0fb33c96a71fc3 Mon Sep 17 00:00:00 2001 From: Yuval Tassa Date: Wed, 29 Apr 2026 07:47:29 -0700 Subject: [PATCH] Fix high-DPI window size in Studio. PiperOrigin-RevId: 907585586 Change-Id: Ie7db20f5242d89926a4a34ffed3a6e39698defd3 --- src/experimental/platform/hal/window.cc | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/experimental/platform/hal/window.cc b/src/experimental/platform/hal/window.cc index 961e9ab9..054fcb88 100644 --- a/src/experimental/platform/hal/window.cc +++ b/src/experimental/platform/hal/window.cc @@ -16,8 +16,6 @@ #include #include -#include -#include #include #include @@ -121,10 +119,13 @@ Window::Window(std::string_view title, int width, int height, Config config) mju_error("Unsupported window config: %d", config_.gfx_mode); } - const float content_scale = ImGui_ImplSDL2_GetContentScaleForDisplay(0); + const float content_scale = + std::max(1.0f, ImGui_ImplSDL2_GetContentScaleForDisplay(0)); + width_ = width * content_scale; + height_ = height * content_scale; sdl_window_ = SDL_CreateWindow(title.data(), SDL_WINDOWPOS_UNDEFINED, - SDL_WINDOWPOS_UNDEFINED, width, height, window_flags); + SDL_WINDOWPOS_UNDEFINED, width_, height_, window_flags); if (!sdl_window_) { mju_error("Error creating window: %s", SDL_GetError()); } @@ -160,8 +161,8 @@ Window::Window(std::string_view title, int width, int height, Config config) #endif } - int drawable_width = width; - int drawable_height = height; + int drawable_width = width_; + int drawable_height = height_; SDL_GL_GetDrawableSize(sdl_window_, &drawable_width, &drawable_height); scale_ = (float)drawable_width / (float)width_; }