libsdl-org / SDL

Simple Directmedia Layer
https://libsdl.org
zlib License
9.62k stars 1.78k forks source link

DPI and scaling #8661

Closed r-tmp closed 1 week ago

r-tmp commented 10 months ago

Not sure what I'm doing wrong here, I have 3 4K screens with scaling of 100% and 250%. I create a window:

auto sdlWindow = SDL_CreateWindow("TEST", 800, 600, SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE
| SDL_WINDOW_HIGH_PIXEL_DENSITY);

I'm creates a really small window, I can get the scale and scale it up:

auto scale = SDL_GetWindowDisplayScale(sdlWindow);

SDL_SetWindowSize(sdlWindow, 800 * scale, 600 * scale);

Which seems about right, however creating the window then resizing it briefly shows the small window before it's resized which doesn't look great.

I thought of getting the display scale first then before creating the window, but I'm not sure how to get the display that the window is going to be created on.

Primary screen is built in and is at 100% scale, it's disabled, and the window is created on screen 2.

I'm using SDL3 (main branch). On Windows 11 23H2 (22631.2792)

A bit more detail... My monitors setup is as follows:

  1. 3840x2160 @ 100% (Laptop screen - "disconnected").
  2. 3840x2160 @ 250% (Monitor - Primary - this is where the window is created).
  3. 3840x2160 @ 250% (Monitor). image

When I create a 800x600 window, this is what is created (you can see relative to my screen size): Screenshot 2023-12-05 204522

After calling resize (basically 800x600 * 2.5) and recentering the window (notice the two white lines - probably need to clear the window):

Screenshot 2023-12-05 205040

I've created a 800x600 in WPF, for size comparison: Screenshot 2023-12-05 205535

Kontrabant commented 10 months ago

What os/window manager is this on?

r-tmp commented 10 months ago

Sorry, forgot to mention, this is on Windows 11 23H2 (22631.2792). Added a bit more detail to the issue.

r-tmp commented 10 months ago

Added further details and screenshots for clarity.

slouken commented 1 week ago

You can create the window hidden using the flag SDL_WINDOW_HIDDEN if you want to resize it after creating it, and then show it with SDL_ShowWindow().