Skip to content

pygame does not scale a fullscreen display correctly on a high DPI Windows machine. (1680) #931

@GalacticEmperor1

Description

@GalacticEmperor1

Issue №1680 opened by gitpicard at 2020-04-27 23:14:33

Hello,

I'm running a pygame project in fullscreen on a computer that has a high DPI display. SDL is old
enough that it does not scale the window at all accordingly. This is not great but Windows scales
the program automatically which can sometimes result in pixel graphics that are not super crisp
but it is better then an unscaled display.

The issue is when calling set_mode with pygame.FULLSCREEN as the display will be larger than the size of the monitor and only the top left of the screen surface will be visible. From a quick glance it looks like pygame.display.Info() and pygame.display.list_modes return the correct sizes but the display is made larger than those sizes. This issue has appeared on Stack Overflow before and Stack Overflow has some hacky fixes that involve calling the Win32 API from Python. This is not a nice thing for pygame users as it breaks the cross-platformness of the library.

I tested once with pygame 2 a while back and still had the issue. The use of the pygame.SCALED flag did not help.

Here are the fixes that a user can do to get around this pygame issue:

#  This solution turns off Window's automatic scaling which is bad because it makes
#  the display really small. Even if the user can resize the screen, the amount of pixels
#  is so large that it is impossible to run smoothly. A blank screen runs at 18 FPS on
#  my computer at fullscreen with this fix. Running it with scaling results in the FPS
#  hitting the high hundreds. On my display, fullscreen is 3840 by 2160 which is
#  about 8 million pixels...
ctypes.windll.user32.SetProcessDPIAware()
#  When getting the size of the monitor to set the display size, use the values returned
#  by this function call instead of pygame's built in functions.
return ctypes.windll.user32.GetSystemMetrics(0), ctypes.windll.user32.GetSystemMetrics(1)

Related docs: https://www.pygame.org/docs/ref/display.html# pygame.display.set_mode

To Do:

  • Find someone with a massive monitor willing to test this.

Comments

# # nthykier commented at 2020-04-29 15:57:54

There is a (semi-)related bug in the SDL bug tracker, where games are allegedly recommended to call SetProcessDPIAware on Windows: https://bugzilla.libsdl.org/show_bug.cgi?id=2713# c1

DPI awareness with SDL (from 2016): https://nlguillemot.wordpress.com/2016/12/11/high-dpi-rendering/

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions