Skip to content

cvcGL: sharp windows on scaled Windows displays (per-monitor DPI aware) - #1514

Merged
transfix merged 1 commit into
masterfrom
fix/win-per-monitor-dpi
Nov 24, 2026
Merged

transfix merged 1 commit into
masterfrom
fix/win-per-monitor-dpi

Conversation

@transfix

@transfix transfix commented Nov 24, 2026 •

Copy link
Copy Markdown
Owner

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 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. Seen on CoPH demo 2a (CVC-Lab/GRL-SNAM#205) on a 1920x1200 display at 125%.

What changes (Windows only)

  • SDL's video makes the process per-monitor DPI aware (v2) (SDL_WINDOWS_DPI_AWARENESS=permonitorv2 as a default hint). A process that already declared its awareness keeps it, and SDL_WINDOWS_DPI_AWARENESS=unaware (app hint or environment) brings the old stretched window back.
  • The window keeps its apparent size. The size a host asks for stays in the display's logical pixels: the window opens at that size times the monitor's scale (1600x900 becomes 2000x1125 pixels at 125%), and unless the app placed it, it is centred again at the new size. ViewportManager::resize() / SceneRenderer::resize() also take logical pixels (SdlGLRenderWindow::SetLogicalSize). frameWidth()/frameHeight() and GetSize() report the pixels the window actually got, so GetSize/SetSize stay in pixels as VTK expects.
  • The UI follows the monitor. 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's ui_px scales with it, and moving the window to a monitor with a different scale rescales the UI and its open windows.
  • VTK's DPI follows the scale (90 at 125%, updated on 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, where displayScale() 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) on bindings/pycvc/demo.ari, measured from a per-monitor-aware caller:

before (master) after
window's DPI awareness / GetDpiForWindow unaware / 96 per-monitor / 120
framebuffer (frameWidth x frameHeight) 1600x900 2000x1125
client area in physical pixels 2000x1125 (stretched 1.25x) 2000x1125 (= framebuffer)
GetWindowRect (physical) 2020x1174 at (-50,-1) 2018x1172 at (-49,-1)
UI pixel ratio 1.000 1.250

GRL-SNAM's coph crossing at --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:

before/after, the Headline panel

before/after, 2x zoom

Full window, after: coph-crossing-after-1800x1013.jpg (before, stretched: jpg). Captures were taken with Win32 PrintWindow by window handle. The images are on the pr-assets/win-per-monitor-dpi branch, which holds only these files and is not for merging; delete it after this PR merges.

Tests

  • cvcgl_sdl_attach gains 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.
  • Local, Release, Windows (VS 2022): ctest -R "cvcgl|pycvc|ari" gives 347 of 352 passed, cvcgl_sdl_attach included. The 5 failures are this box's, not this change's: cvcgl_ari_golden (offscreen goldens; contour_tiler, skeleton and molecule_skeleton need cvc::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_lab and pycvc_volume_grid_contours ("libcvc was built without cvc::planar"), and pycvc_net ("a taken port raises", pycvc core, no GL). The three cvcGL ones fail identically, with the same pixel counts, with master's SdlWindow/ViewportManager/ImGuiOverlay in the same build tree.

Notes

  • 1600x900 logical (GRL-SNAM's default window) is wider than this display's 1536x960 logical desktop, before and after; it hangs 40 px off each side either way.
  • Drag-orbit and pan measure motion in window pixels, so at 125% a drag turns the camera 1.25x as far for the same hand movement as the stretched window did. Pointer-captured mouse look uses SDL's raw deltas and is unchanged. macOS Retina already behaves this way. Left as is.
  • Not checked here: a second monitor with a different scale (this box has one display). That path is SDL3's WM_DPICHANGED handling plus the per-frame pixel-ratio read and DISPLAY_SCALE_CHANGED.

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
transfix merged commit 3f63d24 into master Nov 24, 2026
32 checks passed
@transfix
transfix deleted the fix/win-per-monitor-dpi branch November 24, 2026 12:07
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant