|
How to detect the currrent system resolution? |
nshade
Member #4,372
February 2004
|
I've made a change to my system and it appears that a function I was using incorrectly has now made it known I'm using it wrong. I need to gather what the resolution that my screen is running at, and if it's smaller than 1280x800 to create a smaller window. Here is the code I used. 1 al_set_new_display_flags(ALLEGRO_WINDOWED | ALLEGRO_RESIZABLE);
2 al_get_display_mode(0, &mode);
3 DisplayWidth = mode.width;
4 DisplayHeight = mode.height;
5 OffcenterX = 0;
6 OffcenterY = 0;
7 if (DisplayWidth >= GameWidth && DisplayHeight >= GameHeight)
8 {
9 DISPLAY = al_create_display(GameWidth, GameHeight);
10 }
11 else
12 {
13 DisplayWidth = 1366;
14 DisplayHeight = 768;
15 DISPLAY = al_create_display(DisplayWidth, DisplayHeight);
16 al_set_window_position(DISPLAY, 0, 0);
17 }
Now I thought that al_get_display_mode(0, &mode); would give me my current desktop resolution. Nope! Turns out I have 40 different resolutions to pick from. (It appears to be all 20 of my available resolutions in landscape and portrait) So how do I know which one my desktop is running at before I create the display? |
Frank Drebin
Member #2,987
December 2002
|
This is how I do it: ALLEGRO_MONITOR_INFO info; al_get_monitor_info(0,&info); printf("%i x %i",info.x2-info.x1,info.y2-info.y1);
|
Edgar Reynaldo
Major Reynaldo
May 2007
|
That will tell you the current resolution, sure, but not the max, or the native one. For that, you have to store the results of your enumeration and then sort them by area, and then by aspect. You can then choose the best option easily. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
|