allegro window

Hello guys,
someone can explain me how to use the void al_set_new_display_flags(int flags) function?
because i put it in the main, and when i wanted to enter the parameters (ALLEGRO_WINDOWED), gives me an error (i thing because in the main i can't put a function...) and when i put it out of the main gave me another error... Hahahah, anyway, thanks! ::)

Chris Katko


Before you set up the display with:


al_set_new_display_flags(ALLEGRO_WINDOWED || ALLEGRO_RESIZABLE); //shows how to combine flags

ALLEGRO_DISPLAY *display = al_create_display(800, 600);

You then check if display is valid. Display will be NULL if it cannot apply the flag you requested.

There is also:

Which works like:

al_set_new_display_option(ALLEGRO_VSYNC, 1, ALLEGRO_REQUIRE); //Display will fail if it can't use this.
al_set_new_display_option(ALLEGRO_VSYNC, 1, ALLEGRO_SUGGEST); //Display will still be built even if this doesn't work.

al_set_new_display_option(ALLEGRO_VSYNC, 1, ALLEGRO_DONTCARE); //UNSET any previous requirements you set. (Rarely needed)

ALLEGRO_DISPLAY *display = al_create_display(800, 600);


Don't use || but use | instead.

Chris Katko

Thanks, I wrote that too quickly and didn't notice the typo.


The code will be like this?

int main(int argc, char * argv[]) {



al_set_new_display_flags(ALLEGRO_WINDOWED | ALLEGRO_RESIZABLE); //shows how to combine flags

ALLEGRO_DISPLAY *display = al_create_display(800, 600);

al_set_new_display_option(ALLEGRO_VSYNC, 1, ALLEGRO_REQUIRE);

display = al_create_display(800, 600);


return 0;

If its like this how i do to remain the window? (in SDL is with SDL_Display(time);) but i don't know how its with allegro...
Thanks! :)

Chris Katko

More like this:

1int main(int argc, char * argv[]) { 2 3al_init(); 4 5al_set_new_display_flags(ALLEGRO_WINDOWED | ALLEGRO_RESIZABLE); 6al_set_new_display_option(ALLEGRO_VSYNC, 1, ALLEGRO_REQUIRE); 7 8ALLEGRO_DISPLAY *display = al_create_display(800, 600); 9 10//display = al_create_display(800, 600); // NO NO NO TYPO 11 12main_game_loop(); 13 14return 0; 15} 16 17void main_game_loop() 18{ 19bool done = false; 20while(!done) //each loop represents one frame of game logic 21 { 22 //do stuff including game logic, drawing a frame, etc 23 //if a key is pressed (like ESCAPE), set done = true, and loop will terminate. 24 } 25}

If you need to know how to do keyboard, start reading the basic Allegro 5 tutorials:


Thanks very much, works! But why i have two windows? Hahahah

Chris Katko

Whoops, I edited the posted code and left a typo in.

There should only be one al_create_display.

See the code now, I commented the line out.

Also note that those settings function calls (al_set_new_display_flags and al_set_new_display_option) are not required. They're only required if you want their specific change. So you don't need the VSYNC one if you don't care about VSYNC. I only included them to demonstrate how to call them and in what order. (before creating the actual display.)


Hahaha, thanks! The tutorial of the keyboard is amazing! :D

Thread #616263. Printed from