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)?


1 Answer 1


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.

  • \$\begingroup\$ Is there a way the SDL window in a desired window? Example, can I create a Window in Monitor 2? How to achieve that? \$\endgroup\$
    – programmer
    Dec 23, 2020 at 3:09
  • \$\begingroup\$ @programmer Yes, take a look at SDL_WINDOWPOS_CENTERED_DISPLAY for an example. \$\endgroup\$
    – user35344
    Dec 23, 2020 at 4:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .