I have some SDL code that, before creating a Window and a Renderer, detects the display DPI using SDL_GetDisplayDPI, to properly scale textures late on for different types of monitors (for instance my MacBook Pro's monitor returns a DPI of 258, while my external Dell monitor returns 93).

When I use 2 monitors, SDL_GetNumVideoDisplays properly returns 2, but I couldn't find any function in SDL that would get me which monitor the window is running in, to call SDL_GetDisplayDPI with the correct index, nor any way to detect when the window is dragged from one monitor to the other.

Is there a way to do those things in SDL, or is there a tutorial somewhere that would explain how to do that (hopefully in a platform-independent way)?


I think you want SDL_GetWindowDisplayIndex. It takes in a pointer to your SDL_Window and returns the display index where the center of that window lies.

As to handling dragging, you probably have to manually requery this index yourself while handling resize events inside the event loop.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.