Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Problem toggling between Window and Fullscreen

This thread is locked; no one can reply to it. rss feed Print
 1   2 
Problem toggling between Window and Fullscreen
Slartibartfast
Member #8,789
June 2007
avatar

pkrcel said:

Now, NH should answer, but I got the impression that the scaled version is fundamental in maintaining the aspect ratio?

Sure, but as per documentation - he can still write from the screen to another bitmap without scaling and then write from the bitmap to the screen with scaling.
And if he does that, then wouldn't it be better to just do all drawing to that temporary bitmap and then just draw that bitmap scaled?

Neil Roy
Member #2,229
April 2002
avatar

It copies the screen to itself as far as I can see which doesn't make a lot of sense to me.

I left out the code which sets up another bitmap. Which should be obvious given that I already stated that works in all DirectX modes and all Windowed OpenGL modes. It only doesn't work in OpenGL Fullscreen.

pkrcel said:

He probably sets a different taget bitmap before the instruction, I guess.

Yup.

Here's the relevant code:

ALLEGRO_BITMAP *menuback = NULL;

menuback = al_create_bitmap(WIDTH, HEIGHT);
al_set_target_bitmap(menuback);
al_draw_scaled_bitmap(al_get_backbuffer(setting.screen), offset_x, offset_y, WIDTH*scale_x, HEIGHT*scale_y, 0, 0, WIDTH, HEIGHT, 0);
al_set_target_bitmap(al_get_backbuffer(setting.screen));

I left out error checking code and other nonrelavent code, but I do check all return values. Anyhow, t his works perfectly fine in ALL modes except OpenGL Fullscreen. So it is not my code.

pkrcel said:

Now, NH should answer, but I got the impression that the scaled version is fundamental in maintaining the aspect ratio?

Yup. That is exactly why I did this. But I suppose I could try creating a larger buffer then copying the full screen to it, that takes up much more memory though and still doesn't explain why it works in all other modes.

I don't have a problem when using DirectX with this code at all. I don't have a problem when using this code in any of the Windowed modes with OpenGL (ALLEGRO_WINDOWED & ALLEGRO_FULLSCREEN_WINDOW work fine) only with OpenGL and ALLEGRO_FULLSCREEN does this happen.

If it was a problem, than why am I not seeing it in DirectX? I'll try your fix out anyhow and see how that goes. It would be a good temporary (albeit, memory hogging) solution, but this should be looked into.

Edit: Okay, I changed that to...

al_set_target_bitmap(menuback);
al_draw_bitmap(al_get_backbuffer(setting.screen), 0, 0, 0);

...and it is drawn with..

al_set_target_bitmap(al_get_backbuffer(setting.screen));
al_draw_bitmap(menuback, 0, 0, 0);

And it works fine, no errors AND the game screen looks just as it should, but what bothers me now is, IT SHOULD NOT WORK! That is, the game screen, which is an 800x600 screen that is transformed and clipped to fit on the player's desktop resolution, in my case, 1920x1080, should not be displaying properly at all with the code I use, but it is, meaning that OpenGL in Fullscreen mode is ignoring the transforms and clipping that was set up. When I draw the bitmap to 0,0, that should be 0,0 of the clipped region, not 0,0 of my actual screen, if you see what I mean.

(I don't know if I mentioned this, but I am using a precompiled Allegro 5.1.7 and my OpenGL is version 4 all on Windows 7 with up to date nVidia drivers).

Edit: Okay, so now it looks fine in ALLEGRO_FULLSCREEN but not ALLEGRO_FULLSCREEN_WINDOW, so I guess my problem is I need to check which mode the game is in and then either drawn normally (because FULLSCREEN uses 800x600) or draw a stretched image (which may be a problem, I don't know) if it is a FULLSCREEN_WINDOW.

EDIT2:

I changed my code so the following works...

For copying the background...

al_set_target_bitmap(menuback);
al_draw_bitmap(al_get_backbuffer(setting.screen), 0, 0, 0);

When drawing (fullscreen == 2 for ALLEGRO_FULLSCREEN_WINDOW)

if(setting.fullscreen == 2) al_draw_scaled_bitmap(menuback, offset_x, offset_y, WIDTH*scale_x, HEIGHT*scale_y, 0, 0, WIDTH, HEIGHT, 0);
else al_draw_bitmap(menuback, 0, 0, 0);

<cheer> I tested this thoroughly, in all modes, in DirectX and OpenGL, switching from both Fullscreen modes back to Windowed etc... no problems... yay! \o/ ;)

It's funny that I have to actually scale the background DOWN to 800x600 in ALLEGRO_FULLSCREEN_WINDOW before I draw it, which will then get it transformed and scaled back up again... but... it works. It's a menu screen and not speed dependant at all so.

---
“I love you too.” - last words of Wanda Roy

 1   2 


Go to: