SDL_CreateWindow on multiple screens?

Since SDL_CreateWindow() doesn’t allow us to specify what screen to open on, how do we do it?

We already got a list of resolutions that each screen supports (all 3 of them), and their format types, but actually opening up a window on monitor 1, 2 & 3 doesn’t look possible from all the functions I looked at.

Using custom openGL here, so no need for SDL to make a renderer for us (SDL_CreateWindowAndRenderer).

What is the secret sauce for this?

When you get the display bounds, it returns them in global screen space,
and you can use coordinates that match the display you want the window on.

Alternatively, you can use the macros provided if you don’t care or want
them centered and don’t want to do the math:
SDL_WINDOWPOS_UNDEFINED_DISPLAY(N)
SDL_WINDOWPOS_CENTERED_DISPLAY(N)On Sat, Aug 17, 2013 at 4:07 PM, Sparks wrote:

**
Since SDL_CreateWindow() doesn’t allow us to specify what screen to open
on, how do we do it?

We already got a list of resolutions that each screen supports (all 3 of
them), and their format types, but actually opening up a window on monitor
1, 2 & 3 doesn’t look possible from all the functions I looked at.

Using custom openGL here, so no need for SDL to make a renderer for us
(SDL_CreateWindowAndRenderer).

What is the secret sauce for this?


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Sam Lantinga wrote:

When you get the display bounds, it returns them in global screen space, and you can use coordinates that match the display you want the window on.

Alternatively, you can use the macros provided if you don’t care or want them centered and don’t want to do the math:
SDL_WINDOWPOS_UNDEFINED_DISPLAY(N)

SDL_WINDOWPOS_CENTERED_DISPLAY(N)

Ahh, that was it, and this info is missing in the wiki & source… http://wiki.libsdl.org/moin.fcg/SDL_CreateWindow

Perhaps it would be better to use doxygen generated stuff nightly, instead of the wiki, (or perhaps point to the wiki entry in doxygen) lots of stuff is slipping through the cracks, until someone comes along asking on how to do this…

Like, perhaps the bottom part starting with @helper macros

Code:

/**

  • \brief Create a window with the specified position, dimensions, and flags.*
  • \param title The title of the window, in UTF-8 encoding.
  • \param x The x position of the window, ::SDL_WINDOWPOS_CENTERED, or
  •           ::SDL_WINDOWPOS_UNDEFINED.
    
  • \param y The y position of the window, ::SDL_WINDOWPOS_CENTERED, or
  •           ::SDL_WINDOWPOS_UNDEFINED.
    
  • \param w The width of the window.
  • \param h The height of the window.
  • \param flags The flags for the window, a mask of any of the following:
  •           ::SDL_WINDOW_FULLSCREEN, ::SDL_WINDOW_OPENGL,
    
  •           ::SDL_WINDOW_HIDDEN,     ::SDL_WINDOW_BORDERLESS,
    
  •           ::SDL_WINDOW_RESIZABLE,  ::SDL_WINDOW_MAXIMIZED,
    
  •           ::SDL_WINDOW_MINIMIZED,  ::SDL_WINDOW_INPUT_GRABBED.
    
  • \return The id of the window created, or zero if window creation failed.
  • @helper macros SDL_WINDOWPOS_CENTERED_DISPLAY(N), SDL_WINDOWPOS_UNDEFINED_DISPLAY(N)
  • @wiki http://wiki.libsdl.org/moin.fcg/SDL_CreateWindow
  • \sa SDL_DestroyWindow()
    */

Message-ID: <1376797685.m2f.38717 at forums.libsdl.org>
Content-Type: text/plain; charset=“iso-8859-1”

Sam Lantinga wrote:

When you get the display bounds, it returns them in global screen space,
and you can use coordinates that match the display you want the window
on.

Alternatively, you can use the macros provided if you don’t care or want
them centered and don’t want to do the math:
SDL_WINDOWPOS_UNDEFINED_DISPLAY(N)

SDL_WINDOWPOS_CENTERED_DISPLAY(N)

Ahh, that was it, and this info is missing in the wiki & source…
http://wiki.libsdl.org/moin.fcg/SDL_CreateWindow

Perhaps it would be better to use doxygen generated stuff nightly, instead
of the wiki, (or perhaps point to the wiki entry in doxygen) lots of stuff
is slipping through the cracks, until someone comes along asking on how to
do this…

That does sound like an interesting idea. Perhaps have cron invoke a
script for something like “make web-doc”, then "make web-doc-install"
if that succeeds. Meanwhile, have links to relevant wiki pages inside
the doxygen stuff, and links to the doxygen pages inside the wiki
pages (in which case you would probably want to modify the new page
template to list things that need to be added).

This would certainly pose a potential solution to the endless
documentation question.> Date: Sun, 18 Aug 2013 03:48:05 +0000

From: “Sparks”
To: sdl at lists.libsdl.org
Subject: Re: [SDL] SDL_CreateWindow on multiple screens ?

Sam Lantinga wrote:

When you get the display bounds, it returns them in global screen space, and you can use coordinates that match the display you want the window on.

Alternatively, you can use the macros provided if you don’t care or want them centered and don’t want to do the math:
SDL_WINDOWPOS_UNDEFINED_DISPLAY(N)

SDL_WINDOWPOS_CENTERED_DISPLAY(N)

I’ve tried both methods and the results seem implementation dependent. I’ve run the following code on Debian with XFCE and on Windows (compiled with mingw). On Debian it shows the windows correctly if my mouse pointer is on the first display when I run the program, but if the mouse pointer is on the second display, it shows both windows on the second display (resulting in only the second display being visible. On Windows it shows both windows on the second display regardless of the mouse position. The coordinates that are output are the same in all cases. Am I doing something wrong here?

Code:

#include
#include
#include <SDL2/SDL.h>

struct window_data
{
SDL_Rect bounds;
SDL_Window *window;
};

int main( int argc, char* argv[] )
{
SDL_Init( SDL_INIT_EVERYTHING );
int numdisplays = SDL_GetNumVideoDisplays();
std::vector< window_data > screens( numdisplays );
for( int i = 0 ; i < numdisplays ; ++i )
{
SDL_GetDisplayBounds( i, &( screens[ i ].bounds ) );
std::cout << "window # " << i << " : x = " << screens[ i ].bounds.x
<< " y = " << screens[ i ].bounds.y
<< " w = " << screens[ i ].bounds.w
<< " h = " << screens[ i ].bounds.h << std::endl;
screens[ i ].window
= SDL_CreateWindow( “Window test”,
SDL_WINDOWPOS_UNDEFINED_DISPLAY( i ),
SDL_WINDOWPOS_UNDEFINED_DISPLAY( i ),
// screens[ i ].bounds.x,
// screens[ i ].bounds.y,
screens[ i ].bounds.w,
screens[ i ].bounds.h,
SDL_WINDOW_FULLSCREEN );
}
SDL_Delay( 3000 );
SDL_Quit();
return 0;
}