15

I am working on an OpenGL application. I use a high-dpi screen, and the Windows GUI is scaled to 125%, to make the programs look like on a regular screen.

If I create a 800*600 window using SDL2, it appears the same size as in a regular screen, but it is 1000*750 px. Since I use deferred rendering, I have to create buffers with the same size as the drawable area, so I would like to find out the real size of the window in pixels

If I call SDL_GL_GetDrawableSize I incorrectly get 800*600 instead of 1000*750. I added the flag SDL_WINDOW_ALLOW_HIGHDPI on window creation.

What do I wrong?


Edit:

If I change DPI Awareness in Visual Studio to Per Monitor High DPI Aware then the window is really 800*600, but it looks small. It should be 1000*750 because the scaling factor in the Windows settings is 125%

Iter Ator
  • 8,226
  • 20
  • 73
  • 164

1 Answers1

3

Your post is from Dec 2017 and your SDL version (2.0.7) comment from Jan 2018. Your bounty is up to date, but without newer information.

The main problem is, SDL2.0.7 didn't support HighDPI correctly on windows. In May 2017, they prepared a bigger patch, but it was merged on Feb. 2018, so after the version of SDL2.0.7. As far as I see it, it was introduced in SDL2.0.8. The primary changes were made in the file src/video/windows/SDL_windowswindow.c. I compared the sources and the changelog. It's definitively upstream, but someone forgot to write it down in the WhatIsNew.txt, which is very annoying.

I strongly suggest upgrade SDL to at least 2.0.8, better 2.0.10.

Btw. the author of the patch is mentioning, you need to use the new hint SDL_HINT_VIDEO_HIGHDPI_ENABLED.

In the worst case, if you have still trouble, you can use GLFW instead of SDL.

EDIT: The Questioner provided new informations today.

You can query DPI value per Monitor on windows via GetDpiForMonitor and calculate from that the size.

Since you're using OpenGL with deferred shading: Ensure you're setting glViewPort correctly for every render pass.

Arakis
  • 849
  • 5
  • 16
  • I use SDL 2.0.10, and I still have this issue. And `SDL_HINT_VIDEO_HIGHDPI_ENABLED` is not defined. – Iter Ator Apr 19 '20 at 22:07
  • I researched one hour on your issue. Sorry I have no more idea. You did't wrote you are now using 2.0.10! I would be happy to get a vote. – Arakis Apr 19 '20 at 22:40
  • 1
    @IterAtor Just in case, are you sure your program doesn't pick up an outdated `SDL2.dll`? Does `SDL_GetVersion` show 2.0.10? If that's not it, you could try building SDL2 yourself, and debugging it. – HolyBlackCat Apr 19 '20 at 23:25
  • @HolyBlackCat Both `SDL_VERSION` and `SDL_GetVersion` returns 2.0.10 It looks like that the mentioned patch was never merged. – Iter Ator Apr 20 '20 at 08:17
  • 1
    @IterAtor Consider submitting a bug report. – HolyBlackCat Apr 20 '20 at 09:47
  • Even if the issue is not totally solvable it would be nice to get an accepted answer or a vote. Please keep in mind I spend a notable amount of time in careful research. – Arakis Apr 21 '20 at 08:17
  • Did you tried the `GetDpiForMonitor` Variant, and do you set the `glViewport` for every render pass/target? – Arakis Apr 21 '20 at 15:39
  • @Arakis I can not accept this answer, because it is incorrect. The patch was never merged. And `SDL_HINT_VIDEO_HIGHDPI_ENABLED` is not defined – Iter Ator Apr 21 '20 at 17:48
  • Regardless of your original question, the assumption that the patch was never merged (which could be) is bugging me (I wanted to check the commit history when the Symbol was added/removed). I just cloned the repo (mirror) of SDL and it tells me on checkout, the SHA 2dbd68d8972f59ce690598f17bd5bbbecb26902a is not a valid tree reference. So, why can github show a ref that's not in the cloned repo? – Arakis Apr 21 '20 at 18:23
  • @Arakis This is an unofficial SDL2 mirror: https://github.com/spurious/SDL-mirror The other repo which you linked ( https://github.com/ericwa/SDL-mirror/ ) is just a fork of that repo. So you have found a fork of an unofficial repo. The official is located here: http://hg.libsdl.org/SDL – Iter Ator Apr 21 '20 at 18:28
  • I know that this is a mirror. I checked before on the mirror (not the fork) that the commit hash is existing: https://github.com/spurious/SDL-mirror/commit/2dbd68d8972f59ce690598f17bd5bbbecb26902a . It't true that I didn't checked the original Repo because i don't have the Mercurial tool here/never worked with it. I trusted the mirror, because "normally" a mirror mirrors without extra patches (otherwise it's not a mirror), regardless of official or not. Regardless if the patch was merged or not, in the future i try to check on the original repo first. Sorry for confusion. – Arakis Apr 21 '20 at 18:44
  • But of course i'm still interested to get your issue running. So again, did you had a look at `GetDpiForMonitor`? – Arakis Apr 21 '20 at 18:47