SDL - Toggling Fullscreen

Started by
5 comments, last by TooLSHeD 16 years, 8 months ago
Hi I've implemented a way of toggling between fullscreen and windowed mode, but it's temporary and (I think)it sucks. I need a better method.

this->fullscreen = !this->fullscreen;

if (this->fullscreen)
{
    this->screenFlags = SDL_SWSURFACE | SDL_FULLSCREEN;
}
else
{
    this->screenFlags = SDL_SWSURFACE;
}

this->screen = SDL_SetVideoMode(this->width, this->height, this->BPP,
                                this->screenFlags);
SDL_WM_SetCaption("Blah", NULL); // is this necessary? 

I was thinking of XOR'ing screenFlags with SDL_FULLSCREEN to toggle the flag, will that work? Is there a different/better way? Also should I call SDL_Quit or is it fine just to call SDL_SetVideoMode every time it changes? Fanks
Advertisement
Don't call SDL_Quit, calling SDL_SetVideoMode multiple times will do the right thing (tm).

You could use some bitwise fun to toggle your fullscreen flags, but it won't be any more efficient (on al my computers when you toggle out of fullscreen it takes a few seconds for the screen to reset properly ).

I would be tempted to go for:
screenFlags = SDL_SWSURFACE;if( fullScreen ) {    screenFlags |= SDL_FULLSCREEN;}


This way you can add additional flags if you need to easily ( if (noframe) { flags |= SDL_NOFRAME; } ) and is very easy to understand.

I don't know if you need to call SDL_WM_SetCaption when you reset the video surface, I don't have the major 3 platforms to test it on. Better safe than sorry, so I would leave it in.
If all you want is to toggle the fullscreen and nothing else then

this->screenFlags ^= SDL_FULLSCREEN;this->screen = SDL_SetVideoMode(this->width, this->height, this->BPP,                                this->screenFlags);


will to the job. But if you want to add a few extra flags then the rip-off's way is the way to do it.
I don't have my fullscreen code with me right now, but when I get it I'll post that here. It's similar, but I do believe I used XOR and tried to be fancy. I also think mine sucks.

On a side note, is there any reason why you're using the this pointer so many times? Is it just for clarity? I'm just curious.
The code is part of a class method, I use the 'this' pointer because all the variables are private members. I guess I just want to be consistent.
SDL_WM_ToggleFullScreen
Quote:Original post by Ryan52
SDL_WM_ToggleFullScreen


Only works on X11, according to the documentation.

Thanks Fomas, your method works perfectly.

[Edited by - TooLSHeD on August 4, 2007 8:41:22 AM]

This topic is closed to new replies.

Advertisement