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?
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); }
Recreate all your bitmaps after changing modes.
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.
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?
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);
I feel very stupid for not thinking of that, or rather noticing that that function existed. Thank you very much for the help.
If I'm using A4 and I toggle fullscreen dynamically would I also need to refresh my bitmaps?
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.
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?
Seems to me you had to do a set_gfx_mode(GFX_TEXT,0,0,0,0); then you could reset a graphic mode.
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.
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.
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.
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.
Interesting. So a rest() call or timer probably wouldn't do it? I think allegro_message() is kinda ugly... but if it works...
If it is just a timing issue, a rest should work.
Any magic numbers? 
Would it vary from OS to OS?
I'd imagine a full second delay should work for anything.
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
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?!
Looks like cdecl is a name-space -- user defined or otherwise.
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:
keysDown<ALLEGRO_KEY_F4> = false;