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

Add HiDPI support for MacOS (Retina) #8296

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

shatyuka
Copy link

@shatyuka shatyuka commented May 3, 2024

Description

Bring Retina support to MonoGame. Now we can render at full resolution instead of 1/2.

Details/Checklist

  • Set SDL_WINDOW_ALLOW_HIGHDPI to SDL window
  • Get the backing scale factor. Should be -[NSWindow backingScaleFactor]. But SDL_GL_GetDrawableSize() / SDL_GetWindowSize() is acceptable
  • Convert between points and pixels (viewport/back buffer/mouse state)
  • Only affects MacOS

What users should do

  1. Set NSHighResolutionCapable to true in Info.plist.
<key>NSHighResolutionCapable</key>
<true/>

It's recommended to create a separate project for MacOS and set target framework to have the -macos suffix.

  1. Set window size to a proper scale (like what we do in Windows).
    We can get scale factor from NSScreen.MainScreen.BackingScaleFactor.Value.

  2. Handle screen change event and set back buffer size accoradingly.
    Insert the following code between using var game = new Game() and game.Run().

NSApplication.Init();
var window = NSApplication.SharedApplication.DangerousWindows[0];
NSNotificationCenter.DefaultCenter.AddObserver(NSApplication.DidChangeScreenParametersNotification, action, null);
NSNotificationCenter.DefaultCenter.AddObserver(NSWindow.DidChangeScreenNotification, action, window);

Related

#4802 #6936

@shatyuka shatyuka marked this pull request as ready for review May 4, 2024 10:03
@mrhelmut mrhelmut self-requested a review May 7, 2024 10:51
@mrhelmut
Copy link
Contributor

Would you mind rebasing this PR so that the build passes the checks? I'll proceed to reviewing it.

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.

None yet

2 participants