Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong viewport size on Windows - good on Ubuntu #3813

Open
Magnesus opened this issue Feb 1, 2016 · 6 comments
Open

Wrong viewport size on Windows - good on Ubuntu #3813

Magnesus opened this issue Feb 1, 2016 · 6 comments

Comments

@Magnesus
Copy link

@Magnesus Magnesus commented Feb 1, 2016

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).

@Magnesus
Copy link
Author

@Magnesus Magnesus commented Feb 1, 2016

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?

@Magnesus
Copy link
Author

@Magnesus Magnesus commented Feb 1, 2016

(forget this comment, I was wrong)

@xoppa
Copy link
Member

@xoppa xoppa commented May 5, 2016

@xoppa xoppa added the need more info label May 5, 2016
@BenMcLean
Copy link
Contributor

@BenMcLean BenMcLean commented Nov 21, 2016

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:

  1. In full screen mode, we only see the upper left portion of the viewport zoomed in according to the degree of the UI scaling.

  2. Nearest Neighbor pixel rendering screws up and shows blurry pixels instead of sharp edges. (this becomes easier to see with Windows Magnifier, but it's happening and it's nasty)

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.

@BenMcLean
Copy link
Contributor

@BenMcLean BenMcLean commented Nov 21, 2016

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

@voxelv
Copy link

@voxelv voxelv commented Jul 15, 2017

I'm seeing this issue on my high dpi laptop.
There's a "barebones" example at https://github.com/voxelv/bitcorfab/blob/master/core/src/com/derelictech/bitcorfab/Screen1.java

The following post tries to meet most of the "More Information Needed" criteria.
http://www.badlogicgames.com/forum/viewtopic.php?f=11&t=26659&p=105000#p105000

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.