Allegro.cc - Online Community

Allegro.cc Forums » Allegro Development » allegro window

This thread is locked; no one can reply to it. rss feed Print
allegro window
motyas
Member #16,305
April 2016

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
Member #1,881
January 2002
avatar

Call:

Before you set up the display with:

So

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.
//or
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);

-----sig:
“Programs should be written for people to read, and only incidentally for machines to execute.” - Structure and Interpretation of Computer Programs

Elias
Member #358
May 2000

Don't use || but use | instead.

--
"Either help out or stop whining" - Evert

Chris Katko
Member #1,881
January 2002
avatar

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

-----sig:
“Programs should be written for people to read, and only incidentally for machines to execute.” - Structure and Interpretation of Computer Programs

motyas
Member #16,305
April 2016

The code will be like this?

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

al_init();

al_create_display;

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

al_set_new_display_option;


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
Member #1,881
January 2002
avatar

More like this:

#SelectExpand
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:

https://wiki.allegro.cc/index.php?title=Basic_Keyboard_Example

-----sig:
“Programs should be written for people to read, and only incidentally for machines to execute.” - Structure and Interpretation of Computer Programs

motyas
Member #16,305
April 2016

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

Chris Katko
Member #1,881
January 2002
avatar

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.)

-----sig:
“Programs should be written for people to read, and only incidentally for machines to execute.” - Structure and Interpretation of Computer Programs

motyas
Member #16,305
April 2016

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

Go to: