Fix viewport scaling for high DPI displays - geometry now properly fitted and centered#55
Draft
Fix viewport scaling for high DPI displays - geometry now properly fitted and centered#55
Conversation
Changed viewport to use logical dimensions (Width/Height) instead of physical pixels (RenderWidth/RenderHeight) throughout: - Draw() orthographic projection now uses logical size - zoomExtents() zoom calculation uses logical size - WorldToScreen and ScreenToWorld conversions use logical size - Grid and axes rendering use logical size - Mouse coordinate handling no longer scales by LogicalPixelSize This ensures geometry is properly fitted and centered regardless of DPI scaling. Co-authored-by: philstopford <1983851+philstopford@users.noreply.github.com>
Co-authored-by: philstopford <1983851+philstopford@users.noreply.github.com>
Co-authored-by: philstopford <1983851+philstopford@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix viewport scaling issues on high DPI displays
Fix viewport scaling for high DPI displays - geometry now properly fitted and centered
Oct 13, 2025
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.
Problem
On high DPI displays (1.5x, 2x scaling, etc.), the viewport was not correctly fitting or centering geometry. Objects would appear smaller than expected, and zoom-to-extents would fail to properly frame the content. This made the viewport difficult to use on modern high-resolution displays.
Root Cause
The viewport code was inconsistently mixing physical pixel dimensions (
RenderWidth/RenderHeight) with logical dimensions (Width/Height). On high DPI displays, these differ significantly:Width/Height): Control size in logical pixels (e.g., 800×600)RenderWidth/RenderHeight): Actual framebuffer size scaled by DPI (e.g., 1600×1200 on 2×)The orthographic projection, zoom calculations, and coordinate conversions were using physical dimensions, causing:
Solution
Changed the viewport to consistently use logical dimensions throughout the rendering pipeline:
Files Modified
Width/HeightzoomExtents()zoom calculation now uses logical dimensionsWorldToScreen()andScreenToWorld()conversions use logical dimensionsLogicalPixelSizeMathematical Example
For world space geometry with bounds 0-1000 units:
Before (2× DPI):
After (2× DPI):
Key Insight
The framebuffer size should only be used when creating GPU resources (swapchain, buffers). For all viewport calculations—projection matrix, zoom levels, coordinate transformations—we must use logical dimensions to maintain consistent behavior across different DPI settings.
Testing
Documentation
Added comprehensive documentation:
This fix ensures geometry is properly fitted and centered regardless of display DPI scaling, making the viewport usable on modern high-resolution displays.
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
invalid.nonexistent.host/usr/share/dotnet/dotnet exec --runtimeconfig /home/REDACTED/work/DesignLibs_GPL/DesignLibs_GPL/artifacts/bin/UnitTests/Debug/net8.0/UnitTests.runtimeconfig.json --depsfile /home/REDACTED/work/DesignLibs_GPL/DesignLibs_GPL/artifacts/bin/UnitTests/Debug/net8.0/UnitTests.deps.json /home/REDACTED/work/DesignLibs_GPL/DesignLibs_GPL/artifacts/bin/UnitTests/Debug/net8.0/testhost.dll --port 45589 --endpoint 127.0.0.1:045589 --role client --parentprocessid 4026 --telemetryoptedin false(dns block)/usr/share/dotnet/dotnet exec --runtimeconfig /home/REDACTED/work/DesignLibs_GPL/DesignLibs_GPL/artifacts/bin/UnitTests/Debug/net8.0/UnitTests.runtimeconfig.json --depsfile /home/REDACTED/work/DesignLibs_GPL/DesignLibs_GPL/artifacts/bin/UnitTests/Debug/net8.0/UnitTests.deps.json /home/REDACTED/work/DesignLibs_GPL/DesignLibs_GPL/artifacts/bin/UnitTests/Debug/net8.0/testhost.dll --port 36073 --endpoint 127.0.0.1:036073 --role client --parentprocessid 5001 --telemetryoptedin false(dns block)t1.symcb.comdotnet restore(dns block)t2.symcb.comdotnet restore(dns block)tl.symcb.comdotnet restore(dns block)tl.symcd.comdotnet restore(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.