Skip to content

Commit 6e86607

Browse files
authored
Enable HiDPI scaling in windows and linux (#2361)
* Enable scaling by default * Add scaling mode * Draw offscreen texture using window projection * HDPI options from pyglet2.1 dev7 * Adjust to pyglet 2.0dev7 * Disable scaling during unit tests
1 parent 95fa66f commit 6e86607

File tree

4 files changed

+17
-11
lines changed

4 files changed

+17
-11
lines changed

arcade/__init__.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ def configure_logging(level: int | None = None):
5959

6060
import pyglet
6161

62+
# Enable HiDPI support
63+
if os.environ.get("ARCADE_TEST"):
64+
pyglet.options.dpi_scaling = "real"
65+
else:
66+
pyglet.options.dpi_scaling = "stretch"
6267

6368
# Env variable shortcut for headless mode
6469
headless: Final[bool] = bool(os.environ.get("ARCADE_HEADLESS"))
@@ -72,9 +77,6 @@ def configure_logging(level: int | None = None):
7277
if sys.platform == "darwin" or os.environ.get("ARCADE_HEADLESS") or utils.is_raspberry_pi():
7378
pyglet.options.shadow_window = False # type: ignore # pending https://github.com/pyglet/pyglet/issues/1164
7479

75-
# Use the old gdi fonts on windows until directwrite is fast/stable
76-
# pyglet.options.win32_gdi_font = True
77-
7880
# Imports from modules that don't do anything circular
7981

8082
# Complex imports with potential circularity

arcade/application.py

+5-7
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ def __init__(
195195
alpha_size=8,
196196
)
197197
display = pyglet.display.get_display()
198-
screen = display.get_default_screen() # type: ignore # pending: resolve upstream type tricks
198+
screen = screen or display.get_default_screen()
199199
if screen:
200200
config = screen.get_best_config(config)
201201
except pyglet.window.NoSuchConfigException:
@@ -260,11 +260,9 @@ def __init__(
260260

261261
self.set_vsync(vsync)
262262

263-
super().set_fullscreen(fullscreen, screen)
264-
# This used to be necessary on Linux, but no longer appears to be.
265-
# With Pyglet 2.0+, setting this to false will not allow the screen to
266-
# update. It does, however, cause flickering if creating a window that
267-
# isn't derived from the Window class.
263+
if fullscreen is True:
264+
super().set_fullscreen(True, screen)
265+
268266
set_window(self)
269267

270268
self.push_handlers(on_resize=self._on_resize)
@@ -472,7 +470,7 @@ def center_window(self) -> None:
472470
# Get the display screen using pyglet
473471
screen_width, screen_height = get_display_size()
474472

475-
window_width, window_height = self.get_size()
473+
window_width, window_height = self.get_framebuffer_size()
476474
# Center the window
477475
self.set_location((screen_width - window_width) // 2, (screen_height - window_height) // 2)
478476

arcade/start_finish_data.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@ def begin(self):
5252
5353
Should only be called once followed by a call to :py:meth:`end`.
5454
"""
55-
self.generator_func = self.atlas.render_into(self.texture)
55+
self.generator_func = self.atlas.render_into(
56+
self.texture,
57+
projection=(0, self.window.width, 0, self.window.height),
58+
)
5659
fbo = self.generator_func.__enter__()
5760
fbo.clear(color=self.window.background_color)
5861

tests/conftest.py

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
import os
44
from pathlib import Path
55

6+
os.environ["ARCADE_TEST"] = "True"
7+
8+
69
if os.environ.get("ARCADE_PYTEST_USE_RUST"):
710
import arcade_accelerate # pyright: ignore [reportMissingImports]
811

0 commit comments

Comments
 (0)