#17391 closed defect (fixed)
OpenGL cube sample doesn't look right with DPI scaling under GTK
Reported by: | vadz | Owned by: | Vadim Zeitlin <vadim@…> |
---|---|---|---|
Priority: | low | Milestone: | 3.1.4 |
Component: | wxGTK | Version: | dev-latest |
Keywords: | OpenGL HiDPI | Cc: | mmarsan@…, john.j.beard@…, swt@…, stoffball@… |
Blocked By: | Blocking: | ||
Patch: | yes |
Description
When using wxGTK3 on high DPI (scale factor 2) screen, the cube appears in the lower left window quadrant only.
I'm not sure if it's a bug in the sample or wxGLCanvas itself but it would be nice to fix this.
Attachments (4)
Change History (16)
Changed 23 months ago by jjbeard
Changed 23 months ago by jjbeard
comment:1 Changed 23 months ago by jjbeard
- Cc john.j.beard@… added
comment:2 Changed 23 months ago by jjbeard
- Cc john.j.beard@… removed
It looks like this is the issue (adapted from cube.cpp:352):
const wxSize ClientSize = GetClientSize(); <snip> glViewport(0, 0, ClientSize.x, ClientSize.y);
Changing this to:
const wxSize ClientSize = GetClientSize() * GetContentScaleFactor(); glViewport(0, 0, ClientSize.x, ClientSize.y);
Fixes both GDK_SCALE=2 and GDK_SCALE=1 remains the same.
Is this the correct approach here?
comment:3 Changed 23 months ago by mmarsan
- Cc mmarsan@… added
OpenGL driver normally uses DRI (Direct Rendering Infrastructure). This means glViewPort uses physical sizes of the window and is unaware of OS scaling stuff, just because OS scaling is not used by OGL.
While VZ's solution works, and likely is the way to go, I think some clarifications are needed in the wx docs about physical/scaled/logical/virtual and units used by all window size functions. I'm thinking right now about GetClient|Virtual|Max|Best|...|Size(), GetContentScaleFactor(), From|ToDPI(). And wxDialog units (this is mostly clear).
Perhaps a new function, say GetPhysicalSize may be useful.
comment:4 Changed 22 months ago by jjbeard
- Cc john.j.beard@… added
comment:5 Changed 18 months ago by swt2c
- Cc swt@… added
Proposed PR: https://github.com/wxWidgets/wxWidgets/pull/1470
comment:6 Changed 16 months ago by Vadim Zeitlin <vadim@…>
- Owner set to Vadim Zeitlin <vadim@…>
- Resolution set to fixed
- Status changed from new to closed
comment:7 Changed 14 months ago by tm
- Resolution fixed deleted
- Status changed from closed to reopened
With the applied patch the OpenGL samples now look cropped on a HiDPI display and Windows. (Tested with wxWidgets git version, compiler MSVC 2017 64 bit and Windows 10).
According to docs/Changes.txt the multiplication with GetContentScaleFactor() should only be done for wxGTK3 and wxOSX.
I've uploaded a patch with these changes.
comment:8 Changed 14 months ago by vadz
- Milestone set to 3.1.4
Thanks for reporting the problem, but I don't think it's the right solution, we don't want to tell people to use platform checks in their code.
I'm not sure what do we want to do here, however. Add some GetOpenGLScaleFactor() that would be implemented differently depending on the platform?
comment:9 Changed 14 months ago by tm
- Cc stoffball@… added
I'm attaching a patch which implements the proposed GetOpenGLScaleFactor() version. The samples have been updated accordingly.
(I tested only on Windows, but tried to add the code for GTK3 and OSX.)
comment:10 Changed 7 months ago by vadz
- Patch set
Thanks for your patch! I've finally made this PR with it and will merge it once it passes.
BTW, please let me know (here or via private email) if you'd like to be credited for this (and your previous) contributions using your real name/email rather than just tm <tm@trac.wxwidgets.org>.
comment:11 Changed 6 months ago by Vadim Zeitlin <vadim@…>
- Resolution set to fixed
- Status changed from reopened to closed
I can still produce this on WX head on GTK+3 (v3.1.2-567-gcfded96627), even without a hiDPI monitor, by manipulating the GDK_SCALE environment variable.
Running the cube demo with GDK_SCALE=1 works fine, using GDK_SCALE=2 produces the cube in only the lower left quarter.
This affects KiCAD on hiDPI displays, as the OpenGL drawing canvas is subject to the same bug (https://bugs.launchpad.net/kicad/+bug/1797308).