Jump to content
  • Advertisement
Sign in to follow this  
TooLSHeD

SDL - Toggling Fullscreen

This topic is 4069 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!