Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upWrong viewport size on Windows - good on Ubuntu #3813
Comments
|
I have found the reason - scaling of elements in Windows was by default set to a larger value to compensate for the screen size. Is there a way to detect such setting and compensate? |
|
(forget this comment, I was wrong) |
|
I am having the same issue. On Windows 10, there is a feature called UI Scaling described in this article: https://www.thurrott.com/windows/windows-10/4597/windows-10-feature-focus-display-scaling This is a good feature for people with vision problems to make the text and GUI elements bigger in most Windows programs. However, when this feature is enabled, two very bad things happen for libGDX:
I have confirmed this by running my program with UI scaling turned off (it works perfect) then turning UI scaling on. (these bad effects happen) This feature first started on Windows XP but programmers only started having to worry about it when Windows 7 started trying to scale up apps that didn't tell the newer Windows API that they were DPI-aware. I believe that is what the problem is for libGDX. As InfoWorld says, "For apps that aren't high-DPI aware, Microsoft has a quick and dirty fix called DPI virtualization. Windows deliberately reports the wrong DPI resolution to such apps, so their elements render as if they were on a lower-resolution display. The results are then zoomed to fit the current display." http://www.infoworld.com/article/2952506/microsoft-windows/high-resolution-displays-reveal-windows-10-blind-spot.html What needs to be done to fix this is to make Windows builds of libGDX apps DPI-aware, as discussed in this article from Microsoft https://msdn.microsoft.com/en-us/library/windows/desktop/dn469266(v=vs.85).aspx and explained in this tutorial. https://msdn.microsoft.com/en-us/library/windows/desktop/dd464659(v=vs.85).aspx Here is a really good blog post about the issue: http://www.hanselman.com/blog/LivingAHighDPIDesktopLifestyleCanBePainful.aspx If you'd like to see my code, here is the commit I tested this effect on: BenMcLean/badroguelike@31afc8f As a temporary workaround, libGDX game developers can turn off UI scaling before running the libGDX apps, then turn it back on afterwards to write code, and players can check the "Disable display scaling on high DPI settings" check box under "Compatibility" in the Properties for the app. But that is a real pain to deal with and DPI-awareness is a necessity for Windows apps now. |
|
Discussion on IRC has revealed that this may be a LWJGL issue. Their wiki (may be out of date) says they only have a high DPI mode implemented for OSX. http://wiki.lwjgl.org/wiki/Using_High_DPI_Mode.html |
|
I'm seeing this issue on my high dpi laptop. The following post tries to meet most of the "More Information Needed" criteria. |
When I run my game on Windows it looks as if the viewport is about 1.25x the size of the screen (photo attached) while on Ubuntu it is just fine (the same screen, the same laptop).
Here is how I turn on full screen:
DisplayMode mode = LwjglApplicationConfiguration.getDesktopDisplayMode();
config.fullscreen = true;
config.vSyncEnabled = true;
config.resizable = true;
Here is how I create stage:
stage = new Stage(new ExtendViewport(1280, 800), new SpriteBatch());
Here is how I react to resize:
screen.stage.getViewport().update(width, height, true);
screen.stage.getCamera().translate(MaApp.px, MaApp.py, 0);
// although centering doesn't seem to work, I have to manually translate the camera by gutter sizes (px, py are just negative gutter size).
How it looks on Ubuntu: https://www.dropbox.com/s/yns8va8t4rro9x8/20160201_144202.jpg?dl=0
How it looks on Windows: https://www.dropbox.com/s/udk09gvwnh3epbu/2016-02-01%2014.41.33.jpg?dl=0
PS. The laptop screen I am testing on is 1920x1080, the resulting screen is about 2400x1300, when started in window mode the window is also larger than I specify as size (by the same margin).