pyglet
pyglet copied to clipboard
Supporting for HiDPI screens?
On a HiDPI screen, the scale of the window is big and the resolution of the window is low. How to display a window on a HiDPI screen normally?
window.get_pixel_ratio()
should help you in this case. The viewport size should be multiplied by this factor.
pyglet 2: I wonder if this could be solved internally in pyglet so hidpi will not become a problem. Basically just by applying the pixel ratio to the viewport when set. This makes sense unless somone have a reason to specifically use the extra space a hidpi screen provides, but I don't think this is very common.
I have a separate branch I've messed with with bringing DPI aware windows to Windows. It works but the problem is Windows handles it differently than other OS's I believe. We would need a good way to make sure it's fairly consistent between platforms.
Needs more testing on various OS's, but this is my initial implementation if anyone wants to test: https://github.com/caffeinepills/pyglet/tree/dpi_windows
As a workaround on modern Windows you can try:
PROCESS_DPI_UNAWARE = 0,
PROCESS_SYSTEM_DPI_AWARE = 1,
PROCESS_PER_MONITOR_DPI_AWARE=2
system = platform.system()
if system == "Windows":
# Set DPI awareness for HiDPI support on Windows
try:
ctypes.windll.shcore.SetProcessDpiAwareness(PROCESS_PER_MONITOR_DPI_AWARE)
except AttributeError:
pass # Handle the case where SetProcessDpiAwareness is not available (pre-Windows 8.1)
As a workaround on modern Windows you can try:
PROCESS_DPI_UNAWARE = 0, PROCESS_SYSTEM_DPI_AWARE = 1, PROCESS_PER_MONITOR_DPI_AWARE=2 system = platform.system() if system == "Windows": # Set DPI awareness for HiDPI support on Windows try: ctypes.windll.shcore.SetProcessDpiAwareness(PROCESS_PER_MONITOR_DPI_AWARE) except AttributeError: pass # Handle the case where SetProcessDpiAwareness is not available (pre-Windows 8.1)
Wow, it works well. Thank you.