|
switch FULLSCREEN on and off |
taiwing
Member #16,774
December 2017
|
Hello everyone. I'm currently trying to implement a fullscreen on/off function on my allegro game. It basically consists of destroying the current display and generating a new one in fullscreen mode, or in the game's native resolution if it already was in fullscreen mode. The problem is, once I activate the function, images drawn before the new display was created can't be displayed, so I get a black screen. So I have to redraw every bitmap needed for the portion of the game I'm in for it to behave normally. I looked in the allegro manual, but I couldn't find the answer I was looking for. Is this problem unavoidable ? here's the relevant portion of my code: 1//gameScreen is a structure where I store the display and the buffer of my game
2void fullScreen(gameScreen *screen)
3{
4 if(!screen->fullScreenOnOff)
5 {
6 screen->fullScreenOnOff = true;
7 al_destroy_display(screen->display);
8
9 //I get my screen's native resolution
10 ALLEGRO_DISPLAY_MODE mode;
11 al_get_display_mode(0, &mode);
12
13 //I create a new window
14 al_set_new_display_flags(ALLEGRO_FULLSCREEN_WINDOW);
15 screen->display = al_create_display(mode.width, mode.height);
16 }
17 else
18 {
19 screen->fullScreenOnOff = false;
20 al_destroy_display(screen->display);
21
22 //I recreate a window in my game's resolution
23 al_set_new_display_flags(ALLEGRO_WINDOWED);
24 al_set_new_display_flags(ALLEGRO_RESIZABLE);
25 screen->display = al_create_display(SCREEN_W, SCREEN_H);
26 }
27}
|
Arvidsson
Member #4,603
May 2004
|
If you are using a fullscreen window you can switch between fullscreen and windowed without having to destroy anything, eg: // toggle fullscreen al_set_display_flag(display, ALLEGRO_FULLSCREEN_WINDOW, !(al_get_display_flags(display) & ALLEGRO_FULLSCREEN_WINDOW));
|
taiwing
Member #16,774
December 2017
|
Ok thank you a lot, you reduced a non-working 25 lines function to a beautiful single line of code |
|