Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How is it possible to determine the correct drawable size of a window on Windows 10? (SDL2)

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%

like image 997
Iter Ator Avatar asked Dec 26 '17 14:12

Iter Ator


1 Answers

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.

like image 104
Arakis Avatar answered Nov 16 '22 04:11

Arakis