Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » display adapter #s are different with ALLEGRO_FULLSCREEN_WINDOW

This thread is locked; no one can reply to it. rss feed Print
display adapter #s are different with ALLEGRO_FULLSCREEN_WINDOW
Mark Oates
Member #1,146
March 2001
avatar

I have a dual-monitor configuration like this (#s are labeled by Windows and I'm in extended mode).

{"name":"607222","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/c\/8\/c82e29c2b77b0e33ac259c13aeec3669.png","w":540,"h":263,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/c\/8\/c82e29c2b77b0e33ac259c13aeec3669"}607222

When using this layout, ALLEGRO_FULLSCREEN for both monitors flat-out fails. The program goes into some bizarre loop where the screens flicker, then it shows the desktop with the mouse cursor showing loading, and nothing responding to mouse movement. Then, about every 5 seconds another program/window with "Allegro" appears on the task bar. This process continues until I abort it.

Using ALLEGRO_FULLSCREEN_WINDOW on both dispays, the screens flicker from black to desktop about 4 times, and the ALLEGRO_DISPLAY designated for Display 1 (with al_set_new_display_adapter(0)) is on Display 2, and the ALLEGRO_DISPLAY designated for Display 2 (with al_set_new_display_adapter(1)) is on Display 1.

Is it supposed to do that? I think there are a few issues happening at the same time, and I'm not isolating things well. I'm using 5.1.4. Here's the basic example code I'm playing around with:

#SelectExpand
1#include <allegro5/allegro.h> 2#include <iostream> 3 4 5void set_as_target(ALLEGRO_DISPLAY *display) 6{ 7 al_set_target_bitmap(al_get_backbuffer(display)); 8} 9 10 11int main(int argc, char *argv[]) 12{ 13 al_init(); 14 15 std::cout << al_get_num_video_adapters() << std::endl; 16 17 18 19 20 al_set_new_display_flags(ALLEGRO_FULLSCREEN_WINDOW); 21 22 al_set_new_display_adapter(0); 23 ALLEGRO_DISPLAY *display1 = al_create_display(1920, 1080); 24 25 26 27 al_set_new_display_flags(ALLEGRO_FULLSCREEN_WINDOW); 28 29 al_set_new_display_adapter(1); 30 ALLEGRO_DISPLAY *display2 = al_create_display(1920, 1080); 31 al_hide_mouse_cursor(display2); 32 33 34 35 set_as_target(display1); 36 al_clear_to_color(al_map_rgba_f(0.1, 0.3, 0.1, 1.0)); 37 al_flip_display(); 38 39 set_as_target(display2); 40 al_clear_to_color(al_map_rgba_f(0.1, 0.1, 0.3, 1.0)); 41 al_flip_display(); 42 43 44 45 int i; 46 std::cin >> i; 47}

--
Visit CLUBCATT.com for cat shirts, cat mugs, puzzles, art and more <-- coupon code ALLEGRO4LIFE at checkout and get $3 off any order of 3 or more items!

AllegroFlareAllegroFlare DocsAllegroFlare GitHub

Thomas Fjellstrom
Member #476
June 2000
avatar

The allegro display adapter numbers do not necessarily map to the platform's own display number. But I can probably say that there is something wrong with the windows multimonitor code, I just don't have a clue what it is. I really don't know much about that code at all.

Just because I'm curious, get the geometry for each monitor (location and size) and see if it matches up with what you're expecting.

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

Trent Gamblin
Member #261
April 2000
avatar

For ALLEGRO_FULLSCREEN you must have built Allegro with -DWANT_D3D9EX as a CMake option and must be running Vista or later.

For the fullscreen windows, I don't think we've come up with anything that detects the display layout properly yet. If you can figure it out, send a patch. :)

Also, is it the same thing if you use OpenGL?

Thomas Fjellstrom
Member #476
June 2000
avatar

For the fullscreen windows, I don't think we've come up with anything that detects the display layout properly yet.

I'm not sure its doable in a sane way. You can try and guestimate the physical layout, but the hints we're given by the os just don't mean a whole heck of a lot. Unless there's an API I don't know about that can tell you that Monitor 1 is physically left of Monitor 2. On X with XRandR you can get a monitor's virtual geometry, but just because it has positive or negative coordinates doesn't say anything reliable about its real world physical location.

The most I've seen in games is they put the main window on the primary screen (or potentially the screen it was on when it was full-screened), and when you enable multi monitor it lets you configure what goes where.

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

Slartibartfast
Member #8,789
June 2007
avatar

I'm not sure if this is at all helpful but a quick Google search brought me to EnumDisplayMonitors. I have a test coming up so I don't have a lot of time to mess around, but the following code

#SelectExpand
1#include <iostream> 2#include <Windows.h> 3#include <WinDef.h> 4 5BOOL 6CALLBACK 7EnumCallback( 8 _In_ HMONITOR hMonitor, 9 _In_ HDC hdcMonitor, 10 _In_ LPRECT lprcMonitor, 11 _In_ LPARAM dwData 12) 13{ 14 std::cout<<(DWORD)hMonitor<<": Left "<<lprcMonitor->left<<" Right "<<lprcMonitor->right<<" Top "<<lprcMonitor->top<<" Bottom "<<lprcMonitor->bottom<<std::endl; 15 return TRUE; 16} 17 18 19int main(int argc, char argv) 20{ 21 EnumDisplayMonitors(NULL, NULL, EnumCallback, NULL); 22 return 0; 23}

Generates the output:

65537: Left 0 Right 1920 Top 0 Bottom 1200
65539: Left 1920 Right 3120 Top -470 Bottom 1450

I was hoping that hMonitor is related to the monitor number, but I'm not sure how. Otherwise the rectangles are accurate (I have a primary monitor to the left that is 1920x1200 and one to the right that is 1200x1920 and its top edge is indeed 470 pixels above the other monitor)

I'll reiterate and say that I'm not sure if this is at all helpful :X

EDIT: Out of curiosity I switched the primary monitor to be the one on the right and then I got

65537: Left -1920 Right 0 Top 470 Bottom 1670
65539: Left 0 Right 1200 Top 0 Bottom 1920

So the hMonitor is indeed unrelated to display number, however it appears to still correctly identify the relative location of the displays and their sizes.

EDIT2: Using the same method Allegro uses (EnumDisplayDevices+EnumDisplaySettings) I'm getting identical results. I'm not really sure if a display device is equivalent to a monitor, but I'm not really sure if that matters. Maybe someone with a problematic system should see if using this alternative method is better? I'm not really sure what the problematic symptoms are.

pkrcel
Member #14,001
February 2012

I don't know about that can tell you that Monitor 1 is physically left of Monitor 2

But is the guestimating done on the "OS-perceived" physical layout?

I mean...if x-origin of diplay 1 is lower than x-origin of diplay 2 one should quite safely assume that 1 is left of 2. ...the other way around is not really what one should expect.

It is unlikely that Google shares your distaste for capitalism. - Derezo
If one had the eternity of time, one would do things later. - Johan Halmén

Thomas Fjellstrom
Member #476
June 2000
avatar

So the hMonitor is indeed unrelated to display number, however it appears to still correctly identify the relative location of the displays and their sizes.

Only in the virtual screen space. A user could have their actual screens in any location they want.

pkrcel said:

But is the guestimating done on the "OS-perceived" physical layout?

That is what you'd have to do, as its the only information you have. But Allegro doesn't do any guestimating afaik.

The X code just enumerates the displays, and assigns each one an index from an incrementing variable. Each display will get a per session unique index/id, including any hot plugged displays. No single index/id should have been assigned to more than one unique display in a given session.

Quote:

I mean...if x-origin of diplay 1 is lower than x-origin of diplay 2 one should quite safely assume that 1 is left of 2. ...the other way around is not really what one should expect.

That's reality for you. The screen space is a virtual space. It bears no relation to reality at all. It may attempt to, but there's no guarantee it does. We can ignore the fact that it may sometimes not relate to reality, if thats what people want. But of course, users of allegro can do that themselves since we provide display geometry.

In the past I have setup X display settings where a screen with negative coords was on the right. And similar things.

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

Slartibartfast
Member #8,789
June 2007
avatar

But if the monitor is to the right virtually but to the left in reality, won't that mean that the screen wraps around wrong? So that if I were to move my mouse all the way to the right of the right screen it would come back from the left side of the left screen? That sounds like a very twisted setup.

Arthur Kalliokoski
Second in Command
February 2005
avatar

Well, you can put your earphones on backwards too.

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

Thomas Fjellstrom
Member #476
June 2000
avatar

But if the monitor is to the right virtually but to the left in reality, won't that mean that the screen wraps around wrong? So that if I were to move my mouse all the way to the right of the right screen it would come back from the left side of the left screen? That sounds like a very twisted setup.

It is.

That said, we don't really need to care about that case. And looking at the XRandR code (that I wrote a while back), it actually does use the monitor's reported geometry to calculate positions and sizes when doing modesets, and even has its own notion of RightOf/LeftOf/Above/Below, etc. Something we could potentially export if there was a higher level api for it.

But yeah. Allegro adapter IDs in X will not match up with X/XRandR display IDs what so ever, for a number of reasons (clones, xrandr using non 0 based identifiers, hotplug, etc). About all we can guarantee there is adapter id's are unique per session.

I really don't know how the windows code works, and in general, (directx) fullscreen modes on windows tend to mess with how things work, so directx's notion of displays may not match up with windows's view.

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

Go to: