Repository navigation
cvcGL: sharp windows on scaled Windows displays (per-monitor DPI aware) - #1514
Merged
Merged
Conversation
On a Windows display at 125% or 150%, a cvcGL window opened from a process that is not DPI-aware (python.exe, the C++ hosts: none has a manifest) is drawn at 96 dpi and bitmap-stretched by Windows, so its text is soft. The SDL3 window kept that on purpose: it set SDL_WINDOWS_DPI_AWARENESS to "" so SDL left the process unaware, a rule carried over from when SDL only wrapped VTK's own window. Now SDL's video makes the process per-monitor DPI aware (v2), and on Windows: - the size a host asks for stays in the display's logical pixels: the window opens at that times the monitor's scale (1600x900 is 2000x1125 pixels at 125%) and is centred again at that size unless the app placed it, so it looks exactly as big as before, drawn at the display's own pixels; ViewportManager's resize() asks in logical pixels too (SdlGLRenderWindow::SetLogicalSize), and frameWidth()/frameHeight() say the pixels it got; - ImGuiOverlay's pixel ratio is the window's display scale (SdlGLRenderWindow::displayScale), read every frame, so the UI, and Ariadne's ui_px with it, is 1.25x at 125% and follows the window to a monitor of another scale; - VTK's DPI follows the display's scale too (90 at 125%), so VTK text actors (the FPS HUD, screen text, axis captions) keep their apparent size. A process that already declared its awareness keeps it, and SDL_WINDOWS_DPI_AWARENESS=unaware brings the old stretched window back. Offscreen windows, VTK's own window ($CVCGL_SDL_WINDOW=0), the browser and every other platform are unchanged: displayScale() is 1 there. cvcgl_sdl_attach checks it on Windows: the process is per-monitor aware, a 240x160 window is 240x160 times the display's scale in pixels, its client area is the framebuffer, VTK's DPI and the UI's pixel ratio follow the scale, and resize() asks in logical pixels.
transfix
added a commit
that referenced
this pull request
Nov 24, 2026
Conflicts: src/cvcGL/CMakeLists.txt's 8 MB-stack list keeps both sides' tests; volume_grid, volume_grid_contours and volume_grid_quad take master's images (#1452 changed their documents) until CI's frames of the merge are taken.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On a Windows display at 125% or 150%, a cvcGL window opened from a process that is not DPI-aware (python.exe; the C++ hosts have no manifest either) is drawn at 96 dpi and bitmap-stretched by Windows, so its text is soft. That was on purpose in
SdlWindow.cpp: it setSDL_WINDOWS_DPI_AWARENESSto""so SDL left the process unaware, a rule carried over from when SDL only wrapped VTK's own window. Seen on CoPH demo 2a (CVC-Lab/GRL-SNAM#205) on a 1920x1200 display at 125%.What changes (Windows only)
SDL_WINDOWS_DPI_AWARENESS=permonitorv2as a default hint). A process that already declared its awareness keeps it, andSDL_WINDOWS_DPI_AWARENESS=unaware(app hint or environment) brings the old stretched window back.ViewportManager::resize()/SceneRenderer::resize()also take logical pixels (SdlGLRenderWindow::SetLogicalSize).frameWidth()/frameHeight()andGetSize()report the pixels the window actually got, soGetSize/SetSizestay in pixels as VTK expects.ImGuiOverlay's pixel ratio is the window's display scale (SdlGLRenderWindow::displayScale), read every frame. At 125% the UI scale is 1.25 (fonts are re-baked at that size), Ariadne'sui_pxscales with it, and moving the window to a monitor with a different scale rescales the UI and its open windows.SDL_EVENT_WINDOW_DISPLAY_SCALE_CHANGED), so VTK text actors (FPS HUD, screen text, axis captions) keep their apparent size.Unchanged: offscreen windows, VTK's own window (
$CVCGL_SDL_WINDOW=0), the browser build, and macOS/Linux, wheredisplayScale()is 1 and every code path is the same as before.Measured on this box (Windows 11, 1920x1200 at 125%)
Host(mode="window", width=1600, height=900)onbindings/pycvc/demo.ari, measured from a per-monitor-aware caller:GetDpiForWindowframeWidth x frameHeight)GetWindowRect(physical)GRL-SNAM's
coph crossingat--width 1440 --height 810(it fits this screen): before, 1440x810 drawn and stretched to 1800x1012; after, 1800x1013 drawn natively in the same place, with the same layout.Before (as Windows shows it: the 1440x810 capture stretched 1.25x, bilinear) and after (native), cropped at 1:1:
Full window, after: coph-crossing-after-1800x1013.jpg (before, stretched: jpg). Captures were taken with Win32
PrintWindowby window handle. The images are on thepr-assets/win-per-monitor-dpibranch, which holds only these files and is not for merging; delete it after this PR merges.Tests
cvcgl_sdl_attachgains Windows checks: the process is per-monitor aware (v2); a 240x160 window is 240x160 times the display scale in pixels (300x200 here); its client area equals the framebuffer; VTK's DPI and the UI pixel ratio follow the scale;resize(200, 120)is in logical pixels (250x150 here). At 100% (CI runners) the scale is 1 and the sizes are the requested ones.ctest -R "cvcgl|pycvc|ari"gives 347 of 352 passed,cvcgl_sdl_attachincluded. The 5 failures are this box's, not this change's:cvcgl_ari_golden(offscreen goldens; contour_tiler, skeleton and molecule_skeleton needcvc::planar, which this local prefix lacks because it has no Clipper2, and the volume goldens differ by 0.01-0.6% of pixels on this Intel Arc GPU),cvcgl_volume_grid_contours,cvcgl_contour_labandpycvc_volume_grid_contours("libcvc was built without cvc::planar"), andpycvc_net("a taken port raises", pycvc core, no GL). The three cvcGL ones fail identically, with the same pixel counts, with master'sSdlWindow/ViewportManager/ImGuiOverlayin the same build tree.Notes
WM_DPICHANGEDhandling plus the per-frame pixel-ratio read andDISPLAY_SCALE_CHANGED.