Creating a fullscreen window

Hi all,

Just starting to get up to speed with SDL 1.3. This might be a silly question, but I was wondering what the ‘right’ way to create a fullscreen window is.

In looking through the examples and the API reference, I see that SDL_SetWindowDisplayMode() is used to set the fullscreen mode for a window.

That seems to suggest that the window must exist before these settings can be made; in other words, it doesn’t seem like you can create a fullscreen window and specify parameters such as color depth and refresh rate at the same time.

Given that, what is the ‘correct’ procedure for creating a fullscreen window? Do you create it in windowed mode and not shown, use SetWindowDisplayMode() to set the fullscreen mode, switch the window to fullscreen mode, and then show the window?

Typically all you need to do is call createwindow with the fullscreen and
shown flags and you’re good. If you want more control over what refresh
rate you want or want to find a good available resolution or pixel format,
you could create a fullscreen window that isn’t shown, set the mode you
want, and then show it.

I haven’t thoroughly tested all the combinations of operations yet, so if
you run into bugs please let me know!

See ya!On Thu, Feb 17, 2011 at 11:55 AM, Jesse A. wrote:

Hi all,

Just starting to get up to speed with SDL 1.3. This might be a silly
question, but I was wondering what the ‘right’ way to create a fullscreen
window is.

In looking through the examples and the API reference, I see that
SDL_SetWindowDisplayMode() is used to set the fullscreen mode for a window.

That seems to suggest that the window must exist before these settings can
be made; in other words, it doesn’t seem like you can create a fullscreen
window and specify parameters such as color depth and refresh rate at the
same time.

Given that, what is the ‘correct’ procedure for creating a fullscreen
window? Do you create it in windowed mode and not shown, use
SetWindowDisplayMode() to set the fullscreen mode, switch the window to
fullscreen mode, and then show the window?


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


-Sam Lantinga, Founder and CEO, Galaxy Gameworks

Thanks for the fast reply! (And thanks for 1.3 :slight_smile:

Here’s what I tried (with error checking and so on removed):

Code:
SDL_Window* window = SDL_CreateWindow("", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, w, h, 0);
SDL_DisplayMode mode;
mode.format = SDL_PIXELFORMAT_ARGB8888;
mode.w = w;
mode.h = h;
mode.refresh_rate = 0;
mode.driverdata = 0;
SDL_SetWindowDisplayMode(window, &mode);
SDL_SetWindowFullscreen(window, SDL_TRUE),
SDL_ShowWindow(window);

I may have done something wrong, but this didn’t appear to work (this is with Windows XP). The window was shown, but didn’t go to fullscreen.

The case I’m wondering about is the typical scenario where a user is allowed to select a video mode from an in-game menu, and thereafter the game is automatically launched in that mode.

In the previous API, you’d do this using SDL_SetVideoMode(), which, although it didn’t expose the refresh rate or the exact format, did allow you to create a fullscreen window with the desired specifications ‘all in one go’, as it were.

I know the API is pretty much locked (and I know you’ve got your hands full development-wise!), but being able to create a fullscreen window ‘all at once’ seems desirable as far as game applications go. If there were a function that allowed you to specify the dimensions, format, and refresh rate - basically the 1.3 equivalent of SDL_SetVideoMode() - that would obviate the need for going through multiple steps (and would avoid any visual artifacts or other possible problems related to creating and then showing a fullscreen window).

I have a report that this isn’t working right now, but you should be able to
simply do this:
SDL_Window* window = SDL_CreateWindow("", SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED, w, h, SDL_WINDOW_FULLSCREEN | SDL_WINDOW_SHOWN);On Thu, Feb 17, 2011 at 1:22 PM, Jesse A. wrote:

Thanks for the fast reply! (And thanks for 1.3 :slight_smile:

Here’s what I tried (with error checking and so on removed):

Code:

SDL_Window* window = SDL_CreateWindow("", SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED, w, h, 0);
SDL_DisplayMode mode;
mode.format = SDL_PIXELFORMAT_ARGB8888;
mode.w = w;
mode.h = h;
mode.refresh_rate = 0;
mode.driverdata = 0;
SDL_SetWindowDisplayMode(window, &mode);
SDL_SetWindowFullscreen(window, SDL_TRUE),
SDL_ShowWindow(window);

I may have done something wrong, but this didn’t appear to work (this is
with Windows XP). The window was shown, but didn’t go to fullscreen.

The case I’m wondering about is the typical scenario where a user is
allowed to select a video mode from an in-game menu, and thereafter the game
is automatically launched in that mode.

In the previous API, you’d do this using SDL_SetVideoMode(), which,
although it didn’t expose the refresh rate or the exact format, did allow
you to create a fullscreen window with the desired specifications ‘all in
one go’, as it were.

I know the API is pretty much locked (and I know you’ve got your hands full
development-wise!), but being able to create a fullscreen window ‘all at
once’ seems desirable as far as game applications go. If there were a
function that allowed you to specify the dimensions, format, and refresh
rate - basically the 1.3 equivalent of SDL_SetVideoMode() - that would
obviate the need for going through multiple steps (and would avoid any
visual artifacts or other possible problems related to creating and then
showing a fullscreen window).


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


-Sam Lantinga, Founder and CEO, Galaxy Gameworks

Sam Lantinga wrote:

I have a report that this isn’t working right now, but you should be able to simply do this:
SDL_Window* window = SDL_CreateWindow("", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, w, h, SDL_WINDOW_FULLSCREEN | SDL_WINDOW_SHOWN)

Yes, that works fine here (that’s actually what I was doing previously). The problem is that you can’t specify the format or refresh rate for fullscreen windows that way.

In any case, the code I posted earlier actually does work (the earlier problem was due to a mistake on my part).

Since it’s such a common thing for games to need to do, it seems it’d be useful to be able to create a fullscreen window with a specified color depth and refresh rate without having to create it, modify it, and then show it. But, if no one else has mentioned it, maybe it’s not that important :slight_smile: In any case, the multi-step approach seems to be working, so I’ll just use that.

Thanks again for your reply. (And again, thanks for your work on 1.3 - the new features and API all look great.)