Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » OpenLayer / AllegroGL desktop resizing error

This thread is locked; no one can reply to it. rss feed Print
OpenLayer / AllegroGL desktop resizing error
Richard Phipps
Member #1,632
November 2001
avatar

I've noticed that when I run a full-screen OpenLayer program and I alt-tab out of it the desktop (windows XP) is running in the same screensize as the OpenLayer program. When I quit my program the desktop is fine and restored to it's normal size.

Is there are way people know of here to make it keep the desktop at it's normal size of people Alt-Tab to it while an OpenLayer program is still running?

It might be an AllegroGL issue, I'm not sure..

Thanks for your help all! :)

Milan Mimica
Member #3,877
September 2003
avatar

I think it's the same with all OpenGL programs. If you really want to, you can work around it. I've seen some people doing it. Use set_display_switch_callback() and set_gfx_mode(). Be aware that OGL context (textures and all the rest) will be lost due to screen-mode change so you'll have to restore it.

Richard Phipps
Member #1,632
November 2001
avatar

Really? It seems strange that OpenGL has this problem and DirectX doesn't. :(

Thomas Fjellstrom
Member #476
June 2000
avatar

Um, DX does have that problem, if you're not running at the same res.. Though DX or the games may auto switch the res back for you, but afaik, when you change the mode, the desktop automatically resizes, no matter what changed the 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

Richard Phipps
Member #1,632
November 2001
avatar

EDIT:

Ok, I'm having a few problems and wonder if someone out there can help.
I'm trying to resize the desktop back to it's original size when the user Alt-Tabs away from my OpenLayer program in fullscreen.

Here's the problem:

If in my switch out code I change the screenmode (either using openlayer, or set_gfx_mode(OPEN_GL..) then the screen is restored to the correct size, but I am unable to select my program from the taskbar. I have to Ctrl-Alt-Delete to quit. As soon as I change the screenmode, no code below that call is executed and the switch-in and out hooks are lost.

If instead of doing this I call set_gfx_mode(GFX_TEXT..) then the desktop is restored and I can indeed return to my program, however any call to OpenLayer or with set_gfx_mode(OPEN_GL..) to restore my program's screenmode causes an immediate lock-up.

Has anyone else ran into this problem with OpenGL/AllegroGL and found a solution?

Thanks for your help!

BAF
Member #2,981
December 2002
avatar

DX doesn't have that problem. Whenever I play DX games and alt+tab out my desktop goes to its normal size... dunno about OGL, never tried it.

Richard Phipps
Member #1,632
November 2001
avatar

Surely there is someone here who's worked in OpenGL or AllegroGL or OpenLayer who's had this problem?

HELP! :)

Bob
Free Market Evangelist
September 2000
avatar

Quote:

DX doesn't have that problem. Whenever I play DX games and alt+tab out my desktop goes to its normal size...

Indeed. D3D has a feature called "full-screen" which wgl does not. In Windows, there are no such thing as a full-screen OpenGL application. You can thank the designers of wgl for that.

Of course, the obvious workaround to get a full-screen-like mode is to change the desktop resolution, then create a big window that covers it all. Hopefully, you also remembered to set the magic bits to cover the taskbar too.

Unfortunately, this does mean making Alt-Tab work correctly will take a little effort on the app side of things. Namely, you need to detect the switch out, minimize the window and reset the desktop resolution. Then, on switch-in, change the desktop resolution, maximize the window, recreate the context and all resources.

--
- Bob
[ -- All my signature links are 404 -- ]

Richard Phipps
Member #1,632
November 2001
avatar

Well, I'm trying this with OpenLayer, AllegroGL and allegro. I can detect the switch out, and try to alter the resolution, but then the OS seems to lose the thread as I can never switch back in. Reloading the textures into video memory is not a problem though..

Do you have any code that could help Bob?

Milan Mimica
Member #3,877
September 2003
avatar

Do you mean you can't switch in after you switched out? Or is this because you made something in the meantime?

Richard Phipps
Member #1,632
November 2001
avatar

I explained the problem in more detail in a post above:

Quote:

I'm trying to resize the desktop back to it's original size when the user Alt-Tabs away from my OpenLayer program in fullscreen.

Here's the problem:

If in my switch out code I change the screenmode (either using openlayer, or set_gfx_mode(OPEN_GL..) then the screen is restored to the correct size, but I am unable to select my program from the taskbar. I have to Ctrl-Alt-Delete to quit. As soon as I change the screenmode, no code below that call is executed and the switch-in and out hooks are lost.

If instead of doing this I call set_gfx_mode(GFX_TEXT..) then the desktop is restored and I can indeed return to my program, however any call to OpenLayer or with set_gfx_mode(OPEN_GL..) to restore my program's screenmode causes an immediate lock-up.

Has anyone else ran into this problem with OpenGL/AllegroGL and found a solution?

Thanks for your help!

Milan Mimica
Member #3,877
September 2003
avatar

The second approach should work. I may try to look into it. I wonder why does it lock-up. Any luck with allegro.log? And which version of AGL are you using?

EDIT:
This code works almost fine, just that the switch-in code is executed twice for some reason. It really looks like there are bugs in Allegro/AGL.

1#define USE_CONSOLE 1
2 
3#include <string.h>
4#include <stdio.h>
5 
6#include "allegro.h"
7#include "alleggl.h"
8 
9int sw_forw = 0;
10int sw_back = 0;
11 
12void sw_out(void) {
13 sw_forw = 1;
14}
15 
16void sw_in(void) {
17 sw_back = 1;
18}
19 
20 
21int main() {
22 allegro_init();
23 install_allegro_gl();
24 install_timer();
25 install_keyboard();
26
27 allegro_gl_clear_settings();
28 allegro_gl_set(AGL_COLOR_DEPTH, 32);
29 allegro_gl_set(AGL_DOUBLEBUFFER, 1);
30 allegro_gl_set(AGL_SUGGEST, AGL_DOUBLEBUFFER | AGL_COLOR_DEPTH);
31
32 set_color_depth(32);
33 if (set_gfx_mode(GFX_OPENGL_FULLSCREEN, 800, 600, 0, 0)) {
34 allegro_message("Error initializing OpenGL!\n");
35 return -1;
36 }
37
38 set_display_switch_callback(SWITCH_OUT, sw_out);
39
40 while (!keypressed()) {
41 rest(5);
42 if (sw_forw) {
43 int i;
44 sw_forw = 0;
45 i = set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
46 printf("f = %i\n", i);
47 set_display_switch_callback(SWITCH_IN, sw_in);
48 }
49
50 if (sw_back) {
51 int i;
52 sw_back = 0;
53 i = set_gfx_mode(GFX_OPENGL_FULLSCREEN, 800, 600, 0, 0);
54 printf("b = %i\n", i);
55 set_display_switch_callback(SWITCH_OUT, sw_out);
56 }
57 }
58 
59 return 0;
60}
61END_OF_MAIN();

Richard Phipps
Member #1,632
November 2001
avatar

MM: I also get multiple switch in's and switch out's when I try to use something like your code. I also just get a blank screen when I switch back in. Drawing primitives or restoring my textures doesn't help show anything on the screen.

Here's from the logfile:

Quote:

*out
Switching out
GFX_TEXT: 0
*in
Switching back in
*in
GFX_OPENGL_FULLSCREEN : 0
Restoring textures.
Switching back in
GFX_OPENGL_FULLSCREEN : 0
Restoring textures.

:(

Milan Mimica
Member #3,877
September 2003
avatar

I don't get the double switch out, just in. I'll investigate further this week and PM you if I find something.

Richard Phipps
Member #1,632
November 2001
avatar

Ahh, it only switches out once the *out is where the switch_out variable is set and the switching out comment is where the code is executed.

Can you draw to the newly opened screen on your computer? I get nothing..

Kitty Cat
Member #2,815
October 2002
avatar

Couldn't Allegro be made to take care of this? Like, if it's in a mode that doesn't resize properly on switch out, it will simply resize the desktop for you, but leave everything else intact (eg. keep the window, minimized, keep the video bitmaps, etc)? Be a lot nicer than having to manually call set_gfx_mode(GFX_TEXT) yourself, along with saving and restoring bitmaps.

--
"Do not meddle in the affairs of cats, for they are subtle and will pee on your computer." -- Bruce Graham

Richard Phipps
Member #1,632
November 2001
avatar

I thought Allegro already did this under DirectX, but not with the AllegroGL / OpenGL side.

I still can't get it to work properly anyway! :(

Milan Mimica
Member #3,877
September 2003
avatar

I can draw to the newly opened screen. Everything works fine except for the double switch in. Try the attached source.

Richard Phipps
Member #1,632
November 2001
avatar

Ah! I've managed to get it working (apart from the double switch in..) I've no idea why it's working now though. Suddenly OpenLayer is correctly reseting the screen when I tell it to! :)

EDIT: I've stopped the switch in code executing twice through a 3rd variable (switched_out). So now it seems to work perfectly.

Thank you very much guys! :D

Milan Mimica
Member #3,877
September 2003
avatar

OK, I found what's wrong. The thing is that switch-in callback is called when a new window is created (WM_ACTIVATE event, allegro src/win/wwnd.c:259). Now, in switch-in callback you set a new gfx mode creating a new window, causing a new switch-in callback. Doesn't even seem to be a bug. :o

Go to: