Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Proper Way to switch from Windowed to Fullscreen during runtime

This thread is locked; no one can reply to it. rss feed Print
Proper Way to switch from Windowed to Fullscreen during runtime
FlyingFromage
Member #16,349
May 2016
avatar

Im trying to add an option for the user to be able to switch from fullscreen to windowed and back again, during run time in a settings menu but the current code that ive tried and thought would work did not.

#SelectExpand
1GameManager *g = &GameManager::getGameManager(); 2 3 4if (currOption == ON) 5{ 6 al_set_new_display_flags(ALLEGRO_FULLSCREEN); 7} 8else if (currOption == OFF) 9{ 10 al_set_new_display_flags(ALLEGRO_WINDOWED); 11} 12 13ALLEGRO_DISPLAY *newDisplay = al_create_display(screenWidth, screenHeight); 14al_destroy_display(g->getDisplay()); 15g->setDisplay(newDisplay);

When switching from windowed to full screen, everything works fine and dandy but when switching back, 2 windows are displayed one seemingly normal but with nothing loaded and one called "ALLEGRO" and no user interaction for either window.

I've also tried ALLEGRO_FULLSCREEN_WINDOW instead of ALLEGRO_FULLSCREEN and with that everything works great and no issues have yet to arise but it is not what i'm looking for.

I have also looked around old posts but couldn't find anything of relevance except for only switching between full screen and windowed then restarting but preferably i would like a solution without having to restart the program. Thanks for the help, please ask if you need more clarification.

*edit: I tried using different screen sizes (in this post i had only been testing with 800x600) and larger resolutions would end up causing assertion failures from Visual Studio when trying to go from windowed to full screen (which previously worked). And then i tested starting in full screen and got the same "assertion failed!" dialog box so idk whats with that but thats not even part of my original post so feel no need to help with that part.

David Couzelis
Member #10,079
August 2008
avatar

Here are my display functions. I just recently added the ability to toggle fullscreen. I don't know if this is the "proper way"... :P

https://github.com/drcouzelis/colorwandcastle/blob/master/src/display.h
https://github.com/drcouzelis/colorwandcastle/blob/master/src/display.c

Do you call "al_destroy_display" before creating a new one?

FlyingFromage
Member #16,349
May 2016
avatar

Thanks for the response David. It looks like we are doing just about the same thing except for I am not dealing with clipping rectangles which i doubt would effect much. And also you are toggling from windowed to fullscreen_window which i said worked so I guess ill just settle for that for now. Thanks for the help.

And i guess fullscreen window is better because of the monitor resolution thing anyways

Go to: