I’m currently (with SDL 2.0.3) using SDL_CreateWindow to create a centered, borderless window with a predetermined resolution to create a “windowed fullscreen” mode. However, this requires one to know the display’s resolution in advance. I know I can get a window’s associated display’s resolution. What would be great is if I could know before creating a window what display it would be on. Is this possible? Or does the OS maybe handle that or something?
I had also thought of creating a window with SDL_WINDOW_FULLSCREEN_DESKTOP for a simple fullscreen window. However, I’d like to have a display number option so users can switch the display that the game window is on. Is there some way to specify a display to create a window on using SDL_CreateWindow?
Is this on Windows ? If so, you can use the standard API to grab display information (including list of monitors and what-not) before you create a window. Its not easy, but it is all there…
They are, but is there a way to know which display my window will be created on before I create it?
I can see what displays there are, and their sizes and relative positions. So I can map all the displays out. But I would like to know which of the displays my window will be created on if I just do SDL_CreateWindow.
Also, if I create a window instead using the SDL_WINDOW_FULLSCREEN_DESKTOP flag, can I specify which display it should be created on? The only way to do that that I can guess is to specify a position that has the window’s center somewhere on the display I want it on. Would that work?
You can use SDL_GetWindowDisplayIndex to get the index, (or SDL_GetDisplayName for the name), at which point you could iterate through the available displays to find out which one it is.
Or rather - there doesn’t seem to be an easy/automatic way - you could do it by calculating the total widths for display - 1 and then horizontally position the window, but is a cumbersome process…
My engine runs on Windows, Linux, OS X, and Android. I’ve found the code for getting number of displays, number of display modes per display, etc. I’ve gone ahead and used that, but the one thing that would be nice is to know before calling SDL_CreateWindow which display the window will be created on.
Yes! Thank you. Last night I tried out the “give it a position on another display at creation time” thing and it does seem to work. It isn’t the prettiest, but it gets the job done!
So now I’ve got a display_number option that starts at -1. If it is greater than -1, I attempt to create the window on that display (after making sure it IS a valid display) using the “give SDL_CreateWindow a position on the display I want” method. If it is -1, the game just creates a window in the normal way, and passes SDL_WINDOWPOS_CENTERED for the x and y position. Then some code checks for things like “is the window fullscreen, using SDL_WINDOW_FULLSCREEN, and larger in either dimension than the largest available dimensions for its current display?” Finally, whatever display the window is now on is saved in display_number.
I?ll quote my previous reply, since it?s not showing up in the forum (yet?):> You can use SDL_WINDOWPOS_CENTERED_DISPLAY(displayindex) for the x and y arguments of SDL_CreateWindow to specify which monitor the window will be created in. You can combine that with the SDL_WINDOW_FULLSCREEN_DESKTOP flag to easily make a fullscreen-desktop window on a specific monitor.
If you don?t want to use SDL_WINDOW_FULLSCREEN_DESKTOP for whatever reason (even though it?s recommended), you can use SDL_GetDesktopDisplayMode or SDL_GetCurrentDisplayMode to get the resolution of a monitor.
On Jan 2, 2015, at 6:33 PM, MrTAToad wrote:
You can use SDL_GetWindowDisplayIndex to get the index, (or SDL_GetDisplayName for the name), at which point you could iterate through the available displays to find out which one it is.
Or rather - there doesn’t seem to be an easy/automatic way - you could do it by calculating the total widths for display - 1 and then horizontally position the window, but is a cumbersome process…
You can use SDL_WINDOWPOS_CENTERED_DISPLAY(displayindex) for the x and y arguments of SDL_CreateWindow to specify which monitor the window will be created in. You can combine that with the SDL_WINDOW_FULLSCREEN_DESKTOP flag to easily make a fullscreen-desktop window on a specific monitor.
If you don?t want to use SDL_WINDOW_FULLSCREEN_DESKTOP for whatever reason (even though it?s recommended), you can use SDL_GetDesktopDisplayMode or SDL_GetCurrentDisplayMode to get the resolution of a monitor.On Jan 2, 2015, at 5:28 AM, Dark_Oppressor wrote:
I’m currently (with SDL 2.0.3) using SDL_CreateWindow to create a centered, borderless window with a predetermined resolution to create a “windowed fullscreen” mode. However, this requires one to know the display’s resolution in advance. I know I can get a window’s associated display’s resolution. What would be great is if I could know before creating a window what display it would be on. Is this possible? Or does the OS maybe handle that or something?
I had also thought of creating a window with SDL_WINDOW_FULLSCREEN_DESKTOP for a simple fullscreen window. However, I’d like to have a display number option so users can switch the display that the game window is on. Is there some way to specify a display to create a window on using SDL_CreateWindow?
You can use SDL_WINDOWPOS_CENTERED_DISPLAY(displayindex) for the x and y arguments of SDL_CreateWindow to specify which monitor the window will be created in. You can combine that with the SDL_WINDOW_FULLSCREEN_DESKTOP flag to easily make a fullscreen-desktop window on a specific monitor.
If you don?t want to use SDL_WINDOW_FULLSCREEN_DESKTOP for whatever reason (even though it?s recommended), you can use SDL_GetDesktopDisplayMode or SDL_GetCurrentDisplayMode to get the resolution of a monitor.
Awesome, thanks! That was mentioned briefly in that link above, but I wasn’t sure if it was real! I actually have 3 fullscreen modes that I support. “desktop” which uses SDL_WINDOW_FULLSCREEN_DESKTOP, “standard” which uses SDL_WINDOW_FULLSCREEN (so users can specify some random resolution if they really want to), and “windowed” which creates a borderless window the same size as the display. I MAY have overengineered this…
SDL_WINDOW_FULLSCREEN_DESKTOP is a borderless window so your third
fullscreen mode may be redundant.
Best,
AaronOn Fri, Jan 2, 2015 at 8:56 PM, Dark_Oppressor wrote:
Alex Szpakowski wrote:
You can use SDL_WINDOWPOS_CENTERED_DISPLAY(displayindex) for the x and y
arguments of SDL_CreateWindow to specify which monitor the window will be
created in. You can combine that with the SDL_WINDOW_FULLSCREEN_DESKTOP
flag to easily make a fullscreen-desktop window on a specific monitor.
If you don?t want to use SDL_WINDOW_FULLSCREEN_DESKTOP for whatever reason
(even though it?s recommended), you can use SDL_GetDesktopDisplayMode or
SDL_GetCurrentDisplayMode to get the resolution of a monitor.
Awesome, thanks! That was mentioned briefly in that link above, but I
wasn’t sure if it was real! I actually have 3 fullscreen modes that I
support. “desktop” which uses SDL_WINDOW_FULLSCREEN_DESKTOP, “standard”
which uses SDL_WINDOW_FULLSCREEN (so users can specify some random
resolution if they really want to), and “windowed” which creates a
borderless window the same size as the display. I MAY have overengineered
this… [image: Very Happy]
You can change that behaviour at runtime with SDL_SetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, “0”) (or “1” for the default behaviour.) No need to create your own pseudo-fullscreen mode.> On Jan 8, 2015, at 12:46 AM, Dark_Oppressor wrote:
Sik wrote:
Oh right, SDL_WINDOW_FULLSCREEN_DESKTOP minimizes when unfocused, but
windowed doesn’t.
In SDL3 there are no longer x and y arguments in the SDL_CreateWindow function. How do I specify that a new window should be created on a particular display, given the DisplayID that I previously obtained from SDL_GetDisplays(&nDisplays)?
EDIT:
oh, by calling SDL_SetWindowPosition!
here is a working example for SDL3:
const auto displays = SDL_GetDisplays(&nDisplays);
for (int i = 0; i < nDisplays; ++i)
{
const auto display = displays[i];
SDL_Rect bounds;
SDL_GetDisplayBounds(display, &bounds);
SDL_Window* window = nullptr;
SDL_Renderer* renderer = nullptr;
if (!SDL_CreateWindowAndRenderer(
"I AM THE SCREEN TORTURER",
bounds.w,
bounds.h,
SDL_WINDOW_FULLSCREEN,
&window,
&renderer
))
{
return 1;
}
SDL_SetWindowPosition(window, bounds.x, bounds.y);
SDL_ShowWindow(window);
if (i == 0)
{
SDL_HideCursor();
}
if (!SDL_SetWindowFullscreenMode(window, NULL))
{
return 1;
}
if (!SDL_SyncWindow(window))
{
return 1;
}
}