Hello I have a lot of trouble understanding how the DPI scaling with Retina and OSX to adjust my window.
My current retina resolution is: 1680x1050, but I would like to create a 1920x1080 window (my SFML implementation seems to manage retina scaling by default.)
When I create my SDL window it takes the whole window, so I look at the SDL documentation that mentions the flags: SDL_WINDOW_ALLOW_HIGHDPI
.
I add this flags when creating the window, but nothing happens, my window is still huge.
I obviously took care to put the flags a true in my plist.info file.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>antara-sdl-example</string>
<key>CFBundleGetInfoString</key>
<string></string>
<key>CFBundleIconFile</key>
<string>antara-sdl-example</string>
<key>CFBundleIdentifier</key>
<string></string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleLongVersionString</key>
<string>0.0.1</string>
<key>CFBundleName</key>
<string>antara-sdl-example</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>0.0.1</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string></string>
<key>CSResourcesFileMapped</key>
<true/>
<key>LSRequiresCarbon</key>
<true/>
<key>NSHumanReadableCopyright</key>
<string></string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
<key>NSHighResolutionCapable</key>
<string>true</string>
</dict>
</plist>
I even bothered to create a function in objective c that confirms me that the flags are set to true in the plist file
bool is_high_dpi_capable() noexcept
{
NSBundle *bundle = [NSBundle mainBundle];
if (!bundle)
return false;
return bool([bundle objectForInfoDictionaryKey:@"NSHighResolutionCapable"]);
}
SDL_Window *create_window(entt::registry ®istry) noexcept
{
auto &canvas_2d = registry.ctx<graphics::canvas_2d>();
SDL_Window *window = nullptr;
auto[screen_width, screen_height] = canvas_2d.window.size.to<math::vec2i>(); // 1920x1080 here
//auto[screen_pos_x, screen_pos_y] = canvas_2d.window.position.to<math::vec2i>();
if (!core::is_high_dpi_capable()) {
SDL_LogWarn(SDL_LOG_CATEGORY_SYSTEM, "Your system is not high dpi capable, physical dpi used instead");
}
Uint32 flags = SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI;
if (canvas_2d.is_fullscreen) {
flags |= SDL_WINDOW_FULLSCREEN;
}
window = SDL_CreateWindow("SDL2 Window", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, screen_width, screen_height, flags);
return window;
}
Is there anything I’m doing wrong or not knowing about scaling on OSX?
Current window:
Expected window:
SDL Version : Upstream SDL Compiled Statically for OSX.
Macbook pro: 15.3 inch 2017 OSX Mojave