Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » A5 question about display adapters

This thread is locked; no one can reply to it. rss feed Print
 1   2 
A5 question about display adapters
William Labbett
Member #4,486
March 2004
avatar

hi,

I get 84 different display adapters with ALLEGRO_OPENGL as the display flags.

On all of them the format is 2686584.

Is this expected ?

What does it mean ?

EDIT : also : is there any way to get the dimensions of the screen ?

jmasterx
Member #11,410
October 2009

to get the display size I do:

AguiSize AguiAllegro5GraphicsManager::getDisplaySize()
{
  if(al_get_current_display())
  return AguiSize(al_get_display_width(
    al_get_current_display()),
    al_get_display_height(al_get_current_display()));
  else
    return AguiSize(0,0);
}

Not sure about the formats though.

William Labbett
Member #4,486
March 2004
avatar

thanks.

The thing is an actual monitor has a certain size : aspect ratio. So you could have a widescreen monitor or something else other than 3 : 4 and still set a 3 : 4 fullscreen display eg 640 : 480 etc..

The code you show wouldn't actually give the size of the physical screen.

The reason I'm bothered about this is because I've written my game at 640 by 480 but on a screen which isn't in these proportions, the graphics will all get stretched.

This could be avoided by drawing black rectangles on the left and right of the screen and resizing the 640 480 bitmap to fit in the middle but I need to know what the proportions of the screen are to do this.

Arthur Kalliokoski
Second in Command
February 2005
avatar

Does the example program not work?

They all watch too much MSNBC... they get ideas.

Thomas Fjellstrom
Member #476
June 2000
avatar

This could be avoided by drawing black rectangles on the left and right of the screen and resizing the 640 480 bitmap to fit in the middle but I need to know what the proportions of the screen are to do this.

width / height

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

jmasterx
Member #11,410
October 2009

I see so you want the desktop resolution. Do this through al_get_monitor_info

Matthew Leverton
Supreme Loser
January 1999
avatar

I think he's looking for the equivalent of A4's get desktop resolution, where you could then (sort of) know what the native resolution is.

William Labbett
Member #4,486
March 2004
avatar

What I really want is the screen resolution.

As an example of the problem. here's what I get for the monitor info's on my card :

i 0 width 640, height 480. format 2686584, refresh rate 59
i 1 width 640, height 480. format 2686584, refresh rate 60
i 2 width 640, height 480. format 2686584, refresh rate 66
i 3 width 640, height 480. format 2686584, refresh rate 73
i 4 width 640, height 480. format 2686584, refresh rate 75
i 5 width 640, height 480. format 2686584, refresh rate 59
i 6 width 640, height 480. format 2686584, refresh rate 60
i 7 width 640, height 480. format 2686584, refresh rate 66
i 8 width 640, height 480. format 2686584, refresh rate 73
i 9 width 640, height 480. format 2686584, refresh rate 75
i 10 width 640, height 480. format 2686584, refresh rate 59
i 11 width 640, height 480. format 2686584, refresh rate 60
i 12 width 640, height 480. format 2686584, refresh rate 66
i 13 width 640, height 480. format 2686584, refresh rate 73
i 14 width 640, height 480. format 2686584, refresh rate 75
i 15 width 800, height 600. format 2686584, refresh rate 56
i 16 width 800, height 600. format 2686584, refresh rate 60
i 17 width 800, height 600. format 2686584, refresh rate 70
i 18 width 800, height 600. format 2686584, refresh rate 72
i 19 width 800, height 600. format 2686584, refresh rate 75
i 20 width 800, height 600. format 2686584, refresh rate 56
i 21 width 800, height 600. format 2686584, refresh rate 60
i 22 width 800, height 600. format 2686584, refresh rate 70
i 23 width 800, height 600. format 2686584, refresh rate 72
i 24 width 800, height 600. format 2686584, refresh rate 75
i 25 width 800, height 600. format 2686584, refresh rate 56
i 26 width 800, height 600. format 2686584, refresh rate 60
i 27 width 800, height 600. format 2686584, refresh rate 70
i 28 width 800, height 600. format 2686584, refresh rate 72
i 29 width 800, height 600. format 2686584, refresh rate 75
i 30 width 1024, height 768. format 2686584, refresh rate 60
i 31 width 1024, height 768. format 2686584, refresh rate 66
i 32 width 1024, height 768. format 2686584, refresh rate 70
i 33 width 1024, height 768. format 2686584, refresh rate 72
i 34 width 1024, height 768. format 2686584, refresh rate 75
i 35 width 1024, height 768. format 2686584, refresh rate 60
i 36 width 1024, height 768. format 2686584, refresh rate 66
i 37 width 1024, height 768. format 2686584, refresh rate 70
i 38 width 1024, height 768. format 2686584, refresh rate 72
i 39 width 1024, height 768. format 2686584, refresh rate 75
i 40 width 1024, height 768. format 2686584, refresh rate 60
i 41 width 1024, height 768. format 2686584, refresh rate 66
i 42 width 1024, height 768. format 2686584, refresh rate 70
i 43 width 1024, height 768. format 2686584, refresh rate 72
i 44 width 1024, height 768. format 2686584, refresh rate 75
i 45 width 1152, height 864. format 2686584, refresh rate 60
i 46 width 1152, height 864. format 2686584, refresh rate 70
i 47 width 1152, height 864. format 2686584, refresh rate 75
i 48 width 1152, height 864. format 2686584, refresh rate 60
i 49 width 1152, height 864. format 2686584, refresh rate 70
i 50 width 1152, height 864. format 2686584, refresh rate 75
i 51 width 1152, height 864. format 2686584, refresh rate 60
i 52 width 1152, height 864. format 2686584, refresh rate 70
i 53 width 1152, height 864. format 2686584, refresh rate 75
i 54 width 1280, height 768. format 2686584, refresh rate 75
i 55 width 1280, height 768. format 2686584, refresh rate 75
i 56 width 1280, height 768. format 2686584, refresh rate 75
i 57 width 1280, height 960. format 2686584, refresh rate 60
i 58 width 1280, height 960. format 2686584, refresh rate 70
i 59 width 1280, height 960. format 2686584, refresh rate 72
i 60 width 1280, height 960. format 2686584, refresh rate 75
i 61 width 1280, height 960. format 2686584, refresh rate 60
i 62 width 1280, height 960. format 2686584, refresh rate 70
i 63 width 1280, height 960. format 2686584, refresh rate 72
i 64 width 1280, height 960. format 2686584, refresh rate 75
i 65 width 1280, height 960. format 2686584, refresh rate 60
i 66 width 1280, height 960. format 2686584, refresh rate 70
i 67 width 1280, height 960. format 2686584, refresh rate 72
i 68 width 1280, height 960. format 2686584, refresh rate 75
i 69 width 1280, height 1024. format 2686584, refresh rate 60
i 70 width 1280, height 1024. format 2686584, refresh rate 70
i 71 width 1280, height 1024. format 2686584, refresh rate 75
i 72 width 1280, height 1024. format 2686584, refresh rate 60
i 73 width 1280, height 1024. format 2686584, refresh rate 70
i 74 width 1280, height 1024. format 2686584, refresh rate 75
i 75 width 1280, height 1024. format 2686584, refresh rate 60
i 76 width 1280, height 1024. format 2686584, refresh rate 70
i 77 width 1280, height 1024. format 2686584, refresh rate 75
i 78 width 1440, height 900. format 2686584, refresh rate 60
i 79 width 1440, height 900. format 2686584, refresh rate 75
i 80 width 1440, height 900. format 2686584, refresh rate 60
i 81 width 1440, height 900. format 2686584, refresh rate 75
i 82 width 1440, height 900. format 2686584, refresh rate 60
i 83 width 1440, height 900. format 2686584, refresh rate 75

Now from this information can the screen resolution be worked out ?

Can anyone guess what my screen resolution is ?

Arthur Kalliokoski
Second in Command
February 2005
avatar

In each line, "width" and "height" refer to the resolution of that particular screen mode, not how many pixels your monitor is capable of.

They all watch too much MSNBC... they get ideas.

William Labbett
Member #4,486
March 2004
avatar

not how many pixels your monitor is capable of.

but that's what I want to know, because for all those options which are fullscreen any that aren't the same ratio as my screen res will mean my buffer will get stretched.

Sorry to be a bore but it really matters to me.

jmasterx
Member #11,410
October 2009

So what you want is the monitor's native resolution, not the one that is necessarily currently set?

Arthur Kalliokoski
Second in Command
February 2005
avatar

I'd suppose that everybody runs their desktop at the native resolution, so I'd guess passing ALLEGRO_FULLSCREEN_WINDOW to a screen mode set, then using al_get_display_height() and al_get_display_width(), then setting the actual open gl mode you want would work.

They all watch too much MSNBC... they get ideas.

jmasterx
Member #11,410
October 2009

Then why doesn't monitor info work? If x1 || y1 != 0, then just subtract x1 from x2 and subtract y2 from y1 to get the desktop res right?

Matthew Leverton
Supreme Loser
January 1999
avatar

I don't think he understands that you are suggesting this:

    ALLEGRO_MONITOR_INFO monitor;
    al_get_monitor_info(0, &monitor);

    int w = monitor.x2 - monitor.x1;
    int h = monitor.y2 - monitor.y1;

This is the same thing as get_desktop_resolution() on A4. It's not guaranteed to be the monitor's native resolution, but it's what the user has set. So that's probably just as good.

William Labbett
Member #4,486
March 2004
avatar

Alrighty.

So that's what I should I do and say in the readme to make sure your desktop res is set the native one for the display/monitor.

But just out of interest : would it be possible to hold a database of display's and all the makes and relevant data and then somehow find out which one it is by poking around the OS ?

jmasterx
Member #11,410
October 2009

Yea I imagine it is possible. You can get the vendor id and device id from the OS and then compare that to a database to know which one it is. However making this cross platform might require some work.

William Labbett
Member #4,486
March 2004
avatar

Right.

Thanks j

jmasterx
Member #11,410
October 2009

Glad to help :)

Trent Gamblin
Member #261
April 2000
avatar

That's certainly not in the scope of something Allegro would do... and I suspect there are probably ways to find an lcds native resolution without a giant database. Seems probably, but I don't know. I think a database is extreme overkill in any case, and you'd never get every monitor into it so it wouldn't be any better than the guesses you can make already, IMO.

William Labbett
Member #4,486
March 2004
avatar

Thanks Trent.

just need to work out what 2686584 means for the pixel format.

Trent Gamblin
Member #261
April 2000
avatar

Yes. Are you using an example included with Allegro to get that output, and if so which one? If not, can you upload your code? I'll try it out on Windows/OpenGL.

William Labbett
Member #4,486
March 2004
avatar

I isolated the code down to a simple program and now all the values are 21 which makes sense. Not sure why I'm getting that value in my game code. I'll keep fiddling and see if I can reproduce it without posting my entire project.

Okay. This code reproduces the problem :

#SelectExpand
1#include <stdio.h> 2#include <allegro5/allegro.h> 3#include <allegro5/allegro_image.h> 4#include <allegro5/allegro_font.h> 5 6 7 8 9static void initialise_game(void); 10 11 12 13int main() 14{ 15 16 17 printf("calling initialise game.\n"); 18 19 initialise_game(); 20 21 return 0; 22} 23 24 25 26 27 28static void initialise_game(void) 29{ 30 int x, y; 31 32 33 int num_display_modes; 34 35 ALLEGRO_DISPLAY_MODE mode; 36 37 int i; 38 39 40 if ( !al_init() ) 41 { 42 printf("Could not init Allegro.\n"); 43 exit(1); 44 } 45 46 47 if(!al_init_image_addon()) 48 { 49 printf("Couldn't initialise image addon.\n"); 50 exit(1); 51 } 52 53 if(!al_init_primitives_addon()) 54 { 55 printf("couldn't init primitives addon.\n"); 56 } 57 58 59 60 al_set_new_bitmap_format(ALLEGRO_PIXEL_FORMAT_ANY_32_WITH_ALPHA); 61 62 al_init_font_addon(); 63 64 65 if(!al_init_ttf_addon()) 66 { 67 printf(" couldn't init ttf_addon.\n"); 68 exit(1); 69 } 70 71 al_inhibit_screensaver(1); 72 73 74 al_install_keyboard(); 75 76 77 78 srand(time(0)); 79 80 al_set_new_display_flags(ALLEGRO_OPENGL); 81 82 83 84 FILE *modes = fopen("modes.txt", "w"); 85 86 num_display_modes = al_get_num_display_modes(); 87 88 89 for(i = 0; i < num_display_modes; ++i) 90 { 91 92 al_get_display_mode(i, &mode); 93 94 fprintf(modes, " i %d width %d, height %d. format %d, refresh rate %d\n", i, mode.width, mode.height, mode.format, mode.refresh_rate); 95 } 96 97 fclose(modes); 98 99 100 printf("num display modes = %d.\n", num_display_modes); 101 102}

Trent Gamblin
Member #261
April 2000
avatar

hmm this sort of reminded me that with OpenGL you can't actually set or get a specific pixel format, which means the "format" field is meaningless. If that's the case then it should just be removed. When I run that program I get "0" for each of them. Could just be uninitialized memory, which happens to be some strange value for you but 0 is pretty likely...

Elias
Member #358
May 2000

I'd suppose that everybody runs their desktop at the native resolution, so I'd guess passing ALLEGRO_FULLSCREEN_WINDOW to a screen mode set, then using al_get_display_height() and al_get_display_width(), then setting the actual open gl mode you want would work.

I'd suggest that solution as well. The desktop usually will be set to the native size so there's little reason not to use it. Best is probably to make it a user option though so someone with a very low-end system could configure the game to use a lower resolution.

[edit: in code]

al_set_new_display_flags(ALLEGRO_OPENGL | ALLEGRO_FULLSCREEN_WINDOW);
al_create_display(640, 480); /* size given here is ignored */

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

Matthew Leverton
Supreme Loser
January 1999
avatar

Elias said:

I'd suggest that solution as well

I don't think William wants to set the exact desktop mode, but just one that matches the aspect ratio.

So you might have two main resolutions, one for 4:3 and another for widescreen. This is more convenient for tile/sprite based games than trying to support any resolution.

 1   2 


Go to: