Fullscreen toggle laggy?
DaGamesta

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

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);
    }

Matthew Leverton

Recreate all your bitmaps after changing modes.

Edgar Reynaldo

There was a thread about this recently :
http://www.allegro.cc/forums/thread/609132/941627#target

It turned out for him, it was because the bitmaps became memory bitmaps, or else they were incompatible with the new display somehow.

DaGamesta

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

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

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

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

Thomas Fjellstrom

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.

Felix-The-Ghost

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?

Arthur Kalliokoski

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

Edgar Reynaldo

If I don't do :

set_gfx_mode(GFX_TEXT , 0 , 0 , 0 , 0);
allegro_message("blah");
set_gfx_mode(NEW_MODE , W , H , 0 , 0);

then the screen goes pink or doesn't display right on Windows. That's just what works for me. The problems were especially bad going from fullscreen to windowed mode.

Felix-The-Ghost

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.

Thomas Fjellstrom

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.

Edgar Reynaldo

Yeah, at least for me, the allegro message bit was necessary to properly change resolutions. I just use it to output the new resolution to the user.

Felix-The-Ghost

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

Thomas Fjellstrom

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

Felix-The-Ghost

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

Arthur Kalliokoski

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

Felix-The-Ghost

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

weapon_S

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

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;

Thread #609200. Printed from Allegro.cc