Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Fullscreen toggle laggy?

This thread is locked; no one can reply to it. rss feed Print
Fullscreen toggle laggy?
DaGamesta
Member #13,887
January 2012

Using the following code in the main loop:

if (keysDown[ALLEGRO_KEY_F4]) {
if (al_get_display_flags(display) & ALLEGRO_FULLSCREEN)
al_set_new_display_flags(0);
else
al_set_new_display_flags(ALLEGRO_FULLSCREEN);
al_destroy_display(display);
display = al_create_display(640,480);

cdecl::al_set_target_backbuffer(display);
keysDown[ALLEGRO_KEY_F4] = false;
}

I am able to toggle fullscreen on and off. However, while the game runs fine normally in the (initial) windowed mode, when I toggle to fullscreen, it lags badly, and then upon toggling it back the lag remains. What am I doing wrong?

Arthur Kalliokoski
Second in Command
February 2005
avatar

Just guessing, but did you mean this?

if (keysDown[ALLEGRO_KEY_F4]) {
    if (al_get_display_flags(display) & ALLEGRO_FULLSCREEN)
      al_set_new_display_flags(0);
                }
    else{
      al_set_new_display_flags(ALLEGRO_FULLSCREEN);
      al_destroy_display(display);
      display = al_create_display(640,480);
    }

They all watch too much MSNBC... they get ideas.

Matthew Leverton
Supreme Loser
January 1999
avatar

Recreate all your bitmaps after changing modes.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

DaGamesta
Member #13,887
January 2012

Problem here is, I'm using Allegro 5.0.5, which doesn't have al_convert_bitmap. Also, I store all of my bitmaps in separate "sprite" classes, they'd be a major pain to keep track of separately. Is my only option to compile allegro 5.1 elsewise, though?

Matthew Leverton
Supreme Loser
January 1999
avatar

You should be able to do this as a temporary work around:

void fix_bmp(ALLEGRO_BITMAP **bmp)
{
  if (al_get_bitmap_flags(*bmp) & ALLEGRO_MEMORY_BITMAP)
  {
    ALLEGRO_BITMAP *tmp = *bmp;
    *bmp = al_clone_bitmap(*bmp); /* converts to video */
    al_destroy_bitmap(tmp);
  }
}

fix_bmp(&sprite->bmp);
al_draw_bitmap(sprite->bmp, x, y, 0);

DaGamesta
Member #13,887
January 2012

I feel very stupid for not thinking of that, or rather noticing that that function existed. Thank you very much for the help.

Felix-The-Ghost
Member #9,729
April 2008
avatar

If I'm using A4 and I toggle fullscreen dynamically would I also need to refresh my bitmaps?

==========================
<--- The ghost with the most!
---------------------------
[Website] [Youtube]

Thomas Fjellstrom
Member #476
June 2000
avatar

If I'm using A4 and I toggle fullscreen dynamically would I also need to refresh my bitmaps?

Only if they are video bitmaps. Or possibly system bitmaps. If they were created via create_bitmap, you're fine.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Felix-The-Ghost
Member #9,729
April 2008
avatar

Ahh okay. And load_bitmap I assume. Is there anything else I'd need to do (aside from the different drawing code)

I made a fullscreen toggle test waaaay back, ~A4.2 and I forgot what I did :(
Don't you have to allegro_exit() and reinitialize or something before another set_gfx_mode() call?

==========================
<--- The ghost with the most!
---------------------------
[Website] [Youtube]

Arthur Kalliokoski
Second in Command
February 2005
avatar

Seems to me you had to do a set_gfx_mode(GFX_TEXT,0,0,0,0); then you could reset a graphic mode.

They all watch too much MSNBC... they get ideas.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Felix-The-Ghost
Member #9,729
April 2008
avatar

Hmm. What you two are saying is about the same. Is the message output necessary for it to work? If not it's good for at least telling the player what's going on.

==========================
<--- The ghost with the most!
---------------------------
[Website] [Youtube]

Thomas Fjellstrom
Member #476
June 2000
avatar

I'd say the only purpose it serves is putting a delay between the two calls. Some glitch in allegro or the OS/drivers might not like it when the mode is changed too fast.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Felix-The-Ghost
Member #9,729
April 2008
avatar

Interesting. So a rest() call or timer probably wouldn't do it? I think allegro_message() is kinda ugly... but if it works...

==========================
<--- The ghost with the most!
---------------------------
[Website] [Youtube]

Thomas Fjellstrom
Member #476
June 2000
avatar

If it is just a timing issue, a rest should work.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Felix-The-Ghost
Member #9,729
April 2008
avatar

Any magic numbers? :D
Would it vary from OS to OS? :(

==========================
<--- The ghost with the most!
---------------------------
[Website] [Youtube]

Arthur Kalliokoski
Second in Command
February 2005
avatar

I'd imagine a full second delay should work for anything.

They all watch too much MSNBC... they get ideas.

Felix-The-Ghost
Member #9,729
April 2008
avatar

Ah, alright. Sometimes I'm impressed with the speed of computers. I get awed when I make a function that loops a lot of y/x pixels and does something with them and the program still runs at dozens/frames/second :o

==========================
<--- The ghost with the most!
---------------------------
[Website] [Youtube]

weapon_S
Member #7,859
October 2006
avatar

Nobody noticed that putting that in your main loop would try to create a new display for the number of times you check the keyboard while F4 is pressed down? (Or would the actual switch pause the program long enough to let you lift your finger?) And what does cdecl do?!

Felix-The-Ghost
Member #9,729
April 2008
avatar

Looks like cdecl is a name-space -- user defined or otherwise.

weapon_S said:

Nobody noticed that putting that in your main loop would try to create a new display for the number of times you check the keyboard while F4 is pressed down?

I assume this does something about it:

Quote:

keysDown<ALLEGRO_KEY_F4> = false;

==========================
<--- The ghost with the most!
---------------------------
[Website] [Youtube]

Go to: