Skip to content

Enable HiDPI window on macOS (fixes blurry rendering on Retina) - #227

Open
awkitsune wants to merge 1 commit into
999sian:masterfrom
awkitsune:macos-hidpi-window
Open

awkitsune wants to merge 1 commit into
999sian:masterfrom
awkitsune:macos-hidpi-window

Conversation

@awkitsune

Copy link
Copy Markdown

Problem

On macOS the whole window is blurry on Retina displays: the game image, the CRT/LCD filters and the F8 ImGui menu.

SDL3 only gives a window a full-resolution backing store when it's created with SDL_WINDOW_HIGH_PIXEL_DENSITY. Neither window-creation path set it, so the window got a 1x backing store and macOS upscaled every frame 2x.

Fix

  • port/port_main.c: add SDL_WINDOW_HIGH_PIXEL_DENSITY to both the SDL_CreateWindow (GPU) and SDL_CreateWindowAndRenderer (software) paths, limited to __APPLE__. The present code already sizes itself from pixel dimensions (SDL_GetCurrentRenderOutputSize / swapchain size), so nothing else in the main render path needs to change.
  • port/port_asset_bootstrap.cpp: the first-launch asset-extraction splash now draws in render-output pixels. With HiDPI on, the logical window size would only fill the top-left quarter.
  • port/port_imgui_menu.cpp: same fix for the level-editor toast.
  • Logs one line at startup, [window] WxH points, WxH pixels (density N), which makes DPI problems easy to spot in bug reports.

Testing

Apple Silicon MacBook (built-in Liquid Retina display), USA ROM, python3 build.py --usa, Metal backend (backend=metal, shader=MSL):

Points Pixels Density
Before 1152×480 1152×480 1.00
After 1152×480 2304×960 2.00

The image and the F8 menu are now sharp. Not tested on Intel Macs, Windows or Linux. Those platforms are unchanged except for the new log line.

🤖 Generated with Claude Code

Without SDL_WINDOW_HIGH_PIXEL_DENSITY, SDL3 gives the window a 1x backing
store on macOS, so Retina displays upscale the whole frame (game, filters
and F8 menu) and it looks blurry. Presentation already sizes itself from
pixel dimensions (render output / GPU swapchain), so opt in on Apple.

Also draw the asset-bootstrap splash and level-editor toast in render
output pixels instead of logical window size, and log window points vs
pixels at startup to make DPI issues easy to diagnose.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant