Allegro.cc - Online Community

Allegro.cc Forums » Allegro Development » [A5] al_get_desktop_resolution / available resolutions

Credits go to Thomas Fjellstrom for helping out!
This thread is locked; no one can reply to it. rss feed Print
[A5] al_get_desktop_resolution / available resolutions
Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Is a function to retrieve the native desktop resolution planned to be included in Allegro 5?

I'm asking this because the most reliable way to get a display going is to use the native fullscreen mode of the computer.

Also, will there be a way to get a list of the supported resolutions in A5 the way there was with Allegro 4?

Thomas Fjellstrom
Member #476
June 2000
avatar

I believe the first mode given from the mode enumeration stuff is usually the current one, but theres also al_get_monitor_info. You can get the width and height of each monitor via that.

Also, if you're always just going to set the desktop mode, forget a normal ALLEGRO_FULLSCREEN window, use ALLEGRO_FULLSCREEN_WINDOW instead. That will always create a window the size of the screen regardless of what you passed to al_create_display, and will skip any mode set.

Also, will there be a way to get a list of the supported resolutions in A5 the way there was with Allegro 4?

Yes. al_get_display_mode.

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

I looked at the manual, but I must be blind since I missed both those functions.

Okay, so I would use something like this to set a desktop sized fullscreen display and to enumerate the modes available, right? :

#SelectExpand
1/// Set up a fullscreen display using the desktop width and height 2int nva = al_get_num_video_adapters(); 3if (nva < 1) {return 0;} 4 5ALLEGRO_MONITOR_INFO aminfo; 6al_get_monitor_info(0 , &aminfo); 7int desktop_width = aminfo.x2 - aminfo.x1 + 1; 8int desktop_height = aminfo.y2 - aminfo.y1 + 1; 9 10al_set_new_display_flags(ALLEGRO_FULLSCREEN); 11ALLEGRO_DISPLAY* display = al_create_display(desktop_width , desktop_height); 12if (!display) {return 0;} 13 14/// Enumerate available modes 15int mode_flags[3] = { 16 ALLEGRO_FULLSCREEN | ALLEGRO_DIRECT3D , 17 ALLEGRO_FULLSCREEN | ALLEGRO_OPENGL , 18 ALLEGRO_FULLSCREEN | ALLEGRO_OPENGL_3_0 19}; 20const char* mode_driver_text[3] = { 21 "ALLEGRO_DIRECT3D", 22 "ALLEGRO_OPENGL", 23 "ALLEGRO_OPENGL_3_0" 24}; 25for (int i = 0 ; i < 3 ; i++) { 26 al_set_new_display_flags(mode_flags[i]); 27 output_log << "Modes available for " << mode_driver_text[i] << " :" << endl; 28 int num_modes = al_get_num_display_modes(); 29 for (int j = 0 ; j < num_modes ; ++j) { 30 ALLEGRO_DISPLAY_MODE admode; 31 if (al_get_display_mode(j , &admode) == &admode) { 32 output_log << admode.width << " X " << admode.height << " @ "; 33 output_log << admode.refresh_rate << "Hz using"; 34 PrintPixelFormat(output_log , admode.format); 35 output_log << endl; 36 } 37 } 38}

Also, if you're always just going to set the desktop mode, forget a normal ALLEGRO_FULLSCREEN window, use ALLEGRO_FULLSCREEN_WINDOW instead.

About your suggestion to use ALLEGRO_FULLSCREEN_WINDOW instead of ALLEGRO_FULLSCREEN - does using that mode preserve the contents of video memory when the user switches away from the program using Alt-Tab?

Thomas Fjellstrom
Member #476
June 2000
avatar

Okay, so I would use something like this to set a desktop sized fullscreen display and to enumerate the modes available, right?

I suppose you could use something like that.

Quote:

About your suggestion to use ALLEGRO_FULLSCREEN_WINDOW instead of ALLEGRO_FULLSCREEN - does using that mode preserve the contents of video memory when the user switches away from the program using Alt-Tab?

I believe so. And even if it doesn't, just make sure you handle the ALLEGRO_EVENT_DISPLAY_LOST and ALLEGRO_EVENT_DISPLAY_FOUND events, and redraw when you get the latter event.

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

Matthew Leverton
Supreme Loser
January 1999
avatar

void get_desktop_resolution(int adapter, int *w, int *h)
{
  ALLEGRO_MONITOR_INFO info;
  al_get_monitor_info(adapter, &info);

  *w = info.x2 - info.x1;
  *h = info.y2 - info.y1;
}

Side note: maybe al_get_monitor_info() and similar void functions should instead return false if the adapter is out of range.

Elias
Member #358
May 2000

Maybe we should have al_get_desktop_resolution(monitor, *w, *h) and al_get_desktop_position(monitor, *x, *y) instead of al_get_monitor_info, since this question seems to come up repeatedly :P And I agree about the return value - right now you're more or less required to call al_get_num_video_adapters before calling al_get_monitor_info.

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

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Side note: maybe al_get_monitor_info() and similar void functions should instead return false if the adapter is out of range.

I agree, if that happens to matter.

The manual entry for ALLEGRO_MONITOR_INFO doesn't specify whether x2 and y2 are inclusive or exclusive. Are they the bottom right pixel or one past it? It makes a difference when calculating the width and height of the monitor, so I thought I'd ask.

Matthew Leverton
Supreme Loser
January 1999
avatar

Are they the bottom right pixel or one past it?

It's "one past." So you don't need to add 1 to get the correct sizes.

Elias said:

Maybe we should have al_get_desktop_resolution(monitor, *w, *h) and al_get_desktop_position(monitor, *x, *y) instead of al_get_monitor_info

I prefer the A5 functions. Seems less hacky than using multiple integer pointers.

Go to: