I have been working on a game and have noticed a small problem. The game works perfectly so far, I was working on my options menu where I can switch from WINDOWED to a FULLSCREEN_WINDOW and FULLSCREEN. The game resolution is 800x600 and I use a transform and clipping to fit it to FULLSCREEN (Matthew's function):
Now my problem is in my game, when you press ESC a small menu pops up. In my game I copy the background game screen so when you move between menu items, the background is redrawn, then the menu. This works fine in WINDOWED and in FULLSCREEN_WINDOWED, but it FULLSCREEN the background ignores the clipping that was set in the above function and the background is drawn way off. So on a 1920x1080 screen, the upper left 800x600 is copied rather than the game screen.
Code used to copy the background...
(WIDTH = 800, HEIGHT = 600)
// Copy game screen onto a bitmap menuback = al_create_bitmap(WIDTH, HEIGHT); if(!menuback) { a5_error(AT, setting.screen, "Failed to create menuback"); goto SHUTDOWN; } al_set_target_bitmap(menuback); al_draw_bitmap(al_get_backbuffer(setting.screen), 0, 0, 0); al_set_target_bitmap(al_get_backbuffer(setting.screen));
Here is what the menu looks like on an 800x600 window (it also looks that way on a larger 1920x1080 Fullscreen Window, only scaled up with black borders obviously...
{"name":"608559","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/1\/4\/140aaf57f7c183403dc189ddf34f0c56.jpg","w":800,"h":600,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/1\/4\/140aaf57f7c183403dc189ddf34f0c56"}
But with true Fullscreen mode, I get this...
{"name":"608560","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/c\/7\/c7d66c59df6f79abd7477d5a40e0fde7.jpg","w":1920,"h":1080,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/c\/7\/c7d66c59df6f79abd7477d5a40e0fde7"}
Is there a special way to copy this properly in Fullscreen mode, or am I going to have to store the clipping co-ordinates and use that in Fullscreen mode?
Thanks in advance.
Well, I think you'll need to keep track of the clipping coordinates if you want to do it like that.
However, I'd reccomend a different approach. I wouln't store the game screen in a buffer. Rather I'd redraw the game screen as usual and use a game state machine to see whether or not the menu is active or not. If the menu is active the game logic is paused, the menu is drawn and keystrokes are rerouted to interaction with the menu. If the menu is not active the menu is not drawn and the input is sent to the game input handler.
Like that, you don't need any extra bitmap buffers, and any menu you draw will scale in the same way as the game screen.
Okay, I managed to fix it. The solution was very simple. The scaling function which Matthew came up with has some variables that are set automatically originally for use with mouse movement which I can use to copy the game screen for use with this menu.
The variables offset_x, offset_y, scale_x, and scale_y all give the information needed to copy the screen properly in fullscreen mode.
I basically replaced:
al_draw_bitmap(al_get_backbuffer(setting.screen), 0, 0, 0);
with:
al_draw_scaled_bitmap(al_get_backbuffer(setting.screen), offset_x, offset_y, WIDTH*scale_x, HEIGHT*scale_y, 0, 0, WIDTH, HEIGHT, 0);
Which works perfectly in all screen modes.
I needed to do it this way as my menu that pops up is in it's own function and I want to leave it separate from the rest of the game code.