Properly handling HighDPI on MacOS with SDL and OpenGL
Asked Answered
R

1

8

My attempts at High-DPI rendering on MacOS for my game, Bitfighter, always end up looking bad, like a scaled-up version of a low-res game.

The game uses SDL2 + OpenGL and I have correctly enabled the SDL_WINDOW_ALLOW_HIGHDPI window flag as well as making it HighDPI aware in the Info.plist. This all works and I get the higher-res title bar just fine. I use SDL_GL_GetDrawableSize and it correctly returns the 2x larger pixel size than the window size, but the following techniques to re-scale it don't yield good results:

  • Using glViewport using window coords
  • Using glViewport with drawable coords, then glOrtho to scale (as suggested in the SDL doc README-ios.md)

Both show pixely vector graphics. What can I do to get OpenGL to draw better with MacOS High-DPI?

Thanks.

Resound answered 17/9, 2018 at 17:29 Comment(0)
H
0

I had a rendering issue on this topic. See the screenshot at https://discourse.libsdl.org/t/sdl-gl-getdrawablesize-on-a-retina-mac-rendering-issue/27069

Solution from this post:

If you’re doing OpenGL yourself, make sure to set your viewport to match the actual pixel dimensions of the window. So use what you get from SDL_GL_GetDrawableSize().

So, after CreateWindow() with intended width and height for the window and SDL_GL_CreateContext() set "real" size in viewport:

int drawableWidth, drawableHeight;
SDL_GL_GetDrawableSize(screen, &drawableWidth, &drawableHeight);
glViewport(0, 0, drawableWidth, drawableHeight);

I kept passing window width and height to glOrtho(), not the drawable sizes.

Hydra answered 12/7 at 0:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.