Toggling fullscreen

Hi all,

if my memory doesn’t fool me, someone on the list here said that
SDL_ToggleFullscreen() should not be used. Instead one should call
SDL_SetVideoMode() again with or without SDL_FULLSCREEN flag.
The question that I have is: do I have to re-DisplayFormat or even reload
cached images? I guess the answer is ‘yes’, because the video surface might
move from sysmem to vidmem or vice versa. Just asking for a 'professional’
confirmation…

A related problem I stumbled over some time ago: after compiling my game under
Windows all colorkeyed sprites where completely f**ked up. Sprites with alpha
channel where not affected. It does only happen with fullscreen mode, windows
mode was ok. I found out that I accidently called SDL_DisplayFormat() twice on
the sprites. After removing the second call, everything worked fine.
This problem (bug?) happend only under Windows (Win98, DirectX 7.0, SDL 1.1.5),
not under Linux.
Is it save to call SDL_DisplayFormat() repeatedly at all? Or should I reload
the images if necessary?–
Benjamin Niemann (P!\K)
pink at odahoda.de
http://www.odahoda.de

Hi,

A related problem I stumbled over some time ago: after compiling my game
under Windows all colorkeyed sprites where completely f**ked up. Sprites
with alpha channel where not affected. It does only happen with fullscreen
mode, windows mode was ok. I found out that I accidently called
SDL_DisplayFormat() twice on the sprites. After removing the second call,
everything worked fine. This problem (bug?) happend only under Windows
(Win98, DirectX 7.0, SDL 1.1.5), not under Linux.
Is it save to call SDL_DisplayFormat() repeatedly at all? Or should I
reload the images if necessary?

The same was with me and I found no solution till now. But I guess it’s a bug
in SDL (or DirectX ; ) because windowed mode works fine…

cu
–Alex

If my memory doesn’t fool me, someone on the list here said that
SDL_ToggleFullscreen() should not be used.

SDL_ToggleFullScreen() can be used, but it’s not implemented on very many
platforms. This is the reason that SDL_SetVideoMode() is the recommended
way of going from windowed to fullscreen mode and vice versa.

The question that I have is: do I have to re-DisplayFormat or even reload
cached images? I guess the answer is ‘yes’, because the video surface might
move from sysmem to vidmem or vice versa. Just asking for a 'professional’
confirmation…

If SDL_ToggleFullScreen() is implemented, then no. The semantics are that
the base address of the video surface does not change and no surfaces need
to be reloaded. That’s why it’s not implemented very often. :slight_smile:

You should always free any hardware surfaces before setting a new video
mode, so yes, you need to reload them after you set a new mode.

A related problem I stumbled over some time ago: after compiling my game under
Windows all colorkeyed sprites where completely f**ked up. Sprites with alpha
channel where not affected. It does only happen with fullscreen mode, windows
mode was ok. I found out that I accidently called SDL_DisplayFormat() twice on
the sprites. After removing the second call, everything worked fine.
This problem (bug?) happend only under Windows (Win98, DirectX 7.0, SDL
1.1.5), not under Linux.
Is it save to call SDL_DisplayFormat() repeatedly at all? Or should I reload
the images if necessary?

It should be safe to call it repeatedly, since it returns a new surface and
leaves the old surface alone. If it causes problems, it’s a bug - could you
post a minimal example that demonstrates the bug?

Thanks!
-Sam Lantinga, Lead Programmer, Loki Entertainment Software

Hi Sam,

A related problem I stumbled over some time ago: after compiling my game
under Windows all colorkeyed sprites where completely f**ked up. Sprites
with alpha channel where not affected. It does only happen with
fullscreen mode, windows mode was ok. I found out that I accidently
called SDL_DisplayFormat() twice on the sprites. After removing the
second call, everything worked fine. This problem (bug?) happend only
under Windows (Win98, DirectX 7.0, SDL 1.1.5), not under Linux.
Is it save to call SDL_DisplayFormat() repeatedly at all? Or should I
reload the images if necessary?

It should be safe to call it repeatedly, since it returns a new surface and
leaves the old surface alone. If it causes problems, it’s a bug - could
you post a minimal example that demonstrates the bug?

hehe, digging through my code to extract the critical part for the ‘minimal
example’, if found out that my code was buggy… I created a surface with
the SRCCOLORKEY flag set and the loaded the image data into it, silently
assuming that the pixel format was 8 bit – this assumtion turned out to be
wrong…

The point with ‘repeatedly calling SDL_DisplayFormat()’ was the following
technique:

  • load the image (to a sw-surface :wink:
  • display-format it
  • free the original surface
  • after a video mode change re-display-format the surface to move it from
    sysmem to vidmem or vice-versa

But this will probably not work, because…

You should always free any hardware surfaces before setting a new video
mode, so yes, you need to reload them after you set a new mode.
Thinking a bit further, I decided to keep the original sw-surface. I would
need it anyway for pixel-exact collision checks.–
Benjamin Niemann (P!\K)
pink at odahoda.de
http://www.odahoda.de