Toggling fullscreen at run time

Hi,

I need to make my application so it can toggle between fullscreen or not
in run time. How do I do that?

I read in the documentation that there’s no other function to set the
fullscreen option except SDL_SetVideoMode (CMIIW). And also the display
surface generated from SDL_SetVideoMode should only be freed with a call
to SDL_Quit. So based on what I’ve just read, the only way that came to my
mind is this:

  1. Freeing all resources (eg. surfaces, mix musics, mix chunks, etc)
  2. Calling SDL_Quit.
  3. Calling SDL_Init again.
  4. Calling SDL_SetVideo without the fullscreen flag
  5. Loading the resources again.

Is this the only way to do it? It seems rather inefficient.

Thanks in advance.

Fare thee well,
Bawenang R. P. P.----------------
ERROR: Brain not found. Please insert a new brain!

?Do nothing which is of no use.? - Miyamoto Musashi.

“I live for my dream. And my dream is to live my life to the fullest.”

I’m pretty sure you can skip steps 2 and 3, but it’s still inefficient.

It would be really nice if SDL (or is it just the Windows back end?)
virtualised surfaces enough that the toggle fullscreen function worked
without problems. I wonder if this is this possible for 1.3?

PeterOn 22/08/07, benang at cs.its.ac.id wrote:

Hi,

I need to make my application so it can toggle between fullscreen or not
in run time. How do I do that?

I read in the documentation that there’s no other function to set the
fullscreen option except SDL_SetVideoMode (CMIIW). And also the display
surface generated from SDL_SetVideoMode should only be freed with a call
to SDL_Quit. So based on what I’ve just read, the only way that came to my
mind is this:

  1. Freeing all resources (eg. surfaces, mix musics, mix chunks, etc)
  2. Calling SDL_Quit.
  3. Calling SDL_Init again.
  4. Calling SDL_SetVideo without the fullscreen flag
  5. Loading the resources again.

Is this the only way to do it? It seems rather inefficient.

Thanks in advance.

Fare thee well,
Bawenang R. P. P.


ERROR: Brain not found. Please insert a new brain!

“Do nothing which is of no use.” - Miyamoto Musashi.

“I live for my dream. And my dream is to live my life to the fullest.”


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

All,
This may be a stupid question but when I pop up an SDL window using the
SDL video functions I can’t seem to control where it appears on the
screen - ideally I would like to embed it into a wxWidgets app.
I am capturing video frames from local camera and displaying them.
wxWidgets do provide an image overlay thingy but my captured frames
would have to first be converted to this image format and this seems to
be slow and cumbersome - unlike the SDL double-buffering which is great!

-Chris

benang at cs.its.ac.id wrote:

  1. Freeing all resources (eg. surfaces, mix musics, mix chunks, etc)
  2. Calling SDL_Quit.
  3. Calling SDL_Init again.
  4. Calling SDL_SetVideo without the fullscreen flag
  5. Loading the resources again.
    Is this the only way to do it? It seems rather inefficient.

If your game is 2D you only have to call SDL_SetVideoMode() with or
without the SDL_FULLSCREEN flag.

If you are using OpenGL you may need to rebuild the opengl context (at
least on win32 you will). You don’t have to realloc audio or generic
data, you may need to realloc surfaces IF you want top speed and the
pixel format of the fullscreen mode is different from the windowed one.–
Bye,
Gabry

Gabriele Greco wrote:

If your game is 2D you only have to call SDL_SetVideoMode() with or
without the SDL_FULLSCREEN flag.

Not quite. If you have surfaces with the SDL_HWSURFACE flag, you need
to free those before calling SDL_SetVideoMode (and reload them
afterwards). If your new video mode has a different pixel format than
your old video mode, you should convert your surfaces to the new pixel
format (possibly reloading them first). You don’t need to reload any
other resources unless they use SDL_Surfaces internally.–
Rainer Deyke - rainerd at eldwood.com

So, I can just call the SDL_SetVideoMode() again but without the
SDL_FULLSCREEN flag, right? But will it return the same display surface
pointer? I basically just store the display surface pointer generated by
SDL_SetVideoMode() as a private member variables on my main class and pass
it as a parameter to any class which need it (and in turn set it as its
own member variable). And the one that wants to change the mode is the
other class (ie. not the main class). I know that it’s a bad practice, but
that’s what you get when developing without designing first (or designing
on the fly :D). I intend to fix it but it has evolved to a tangled web of
disarray, so I didn’t. After all it has filled its purpose quite well.

Rainer Deyke wrote:

Gabriele Greco wrote:

If your game is 2D you only have to call SDL_SetVideoMode() with or
without the SDL_FULLSCREEN flag.

Not quite. If you have surfaces with the SDL_HWSURFACE flag, you need
to free those before calling SDL_SetVideoMode (and reload them
afterwards). If your new video mode has a different pixel format than
your old video mode, you should convert your surfaces to the new pixel
format (possibly reloading them first). You don’t need to reload any
other resources unless they use SDL_Surfaces internally.


Rainer Deyke - rainerd at eldwood.com

Fare thee well,
Bawenang R. P. P.----------------
ERROR: Brain not found. Please insert a new brain!

?Do nothing which is of no use.? - Miyamoto Musashi.

“I live for my dream. And my dream is to live my life to the fullest.”

So, I can just call the SDL_SetVideoMode() again but without the
SDL_FULLSCREEN flag, right? But will it return the same display surface
pointer?

It may, but you can’t guarantee it.

See ya!
-Sam Lantinga, Lead Software Engineer, Blizzard Entertainment

So, I can just call the SDL_SetVideoMode() again but without the
SDL_FULLSCREEN flag, right? But will it return the same display surface
pointer?

It may, but you can’t guarantee it.

Personally, I store the pointer to the actual display surface globally. To
switch between full- and windowed modes, I call SDL_QuitSubSystem
(SDL_INIT_VIDEO), which (if I am not mistaking) does the video-cleanup for
me. Then I just Initialize the video again, and re-open a display surface,
with (or without) SDL_FULLSCREEN. This has worked just fine for me and as
far as I can tell there has not been any problems, and I am able to switch
between screenmodes without interrupting the program itself.

Cheers,
Peter

SDL_GetVideoSurface() is your friend. No need to store it globally
yourself when SDL does it for you =)
I don’t know what the API for 1.3 will look like for this however…> Personally, I store the pointer to the actual display surface globally. To

switch between full- and windowed modes, I call SDL_QuitSubSystem
(SDL_INIT_VIDEO), which (if I am not mistaking) does the video-cleanup for
me. Then I just Initialize the video again, and re-open a display surface,
with (or without) SDL_FULLSCREEN. This has worked just fine for me and as
far as I can tell there has not been any problems, and I am able to switch
between screenmodes without interrupting the program itself.

Thanks a lot guys. I think maybe toggling between fullscreen and not is
not the best way to solve my problem after all. You see, in my game, I set
it always to be a fullscreen one. But inside the game, there will be an
option for the player to calibrate the touch screen. And this calibration
requires calling an external executable with system() function (I intend
to change it to fork()/exec() after this). This executable uses GTK for
it’s GUI. If the game was called with the SDL_FULLSCREEN flag, it can’t
show up because the game is always on top . But if I call it without the
SDL_FULLSCREEN flag,the calibration menu showed up. Actually the vendor
already gave me the source code for the calibration executable. So, any
idea to overcome this?

Thanks again.

Brian wrote:

SDL_GetVideoSurface() is your friend. No need to store it globally
yourself when SDL does it for you =)
I don’t know what the API for 1.3 will look like for this however…

Personally, I store the pointer to the actual display surface globally.
To
switch between full- and windowed modes, I call SDL_QuitSubSystem
(SDL_INIT_VIDEO), which (if I am not mistaking) does the video-cleanup
for
me. Then I just Initialize the video again, and re-open a display
surface,
with (or without) SDL_FULLSCREEN. This has worked just fine for me and
as
far as I can tell there has not been any problems, and I am able to
switch
between screenmodes without interrupting the program itself.


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

Fare thee well,
Bawenang R. P. P.----------------
ERROR: Brain not found. Please insert a new brain!

?Do nothing which is of no use.? - Miyamoto Musashi.

“I live for my dream. And my dream is to live my life to the fullest.”