I am trying to save the display size and position, so that it will
persist when the game is started again.
Mostly everything is working good, except for a few minor things:
Here is what works:
- I create a display with a certain width and height
- then I let the user resize and move the window
- I save the display size and position in my config file
- It comes back perfectly the next time the game is run
Here is what doesn't:
When I switch to ALLEGRO_FULLSCREEN_WINDOW and back,
the window uses the values that were used to create the display
not the window size that it previously was
I can store my changed position, and then when I change back:
- restore the position (easy)
- resize the display (takes another complete resize)
What I would really like to do, is be able to modify the values
in the display structure, so that switching back goes to the values
that were there before I switched into ALLEGRO_FULLSCREEN_WINDOW,
and not the ones used when creating the display.
From the manual:
"The passed width and height are only used if the window is switched
out of fullscreen mode later but will be ignored initially."
If I just had access to those variables, I could set them to what I want.
(Or they could automatically be updated when the screen is resized.)
I suppose I could just destroy and re-create the display, but that
seems like a bit of overkill.
Does anyone have any advice on how I can achieve what I'm trying to do here?
ALLEGRO_FULLSCREEN_WINDOW by definition creates a Window which is the size of your full screen. That can't be changed.
If you wish to switch out of fullscreen mode to just a resized window, than you should perhaps record the new size and the fact that it is no longer a fullscreen window and then when you run the program again, it could instead create an ALLEGRO_WINDOW. Otherwise it will always come up fullscreen. Save the new size in config, when it is reloaded check the new size, if it does not match fullscreen modem just create a normal window with the new size rather than a fullscreen window.
Thanks Neil,
That's not quite exactly what I'm trying to do.
I already had it working so that it would save in the config and get reloaded.
And yes it worked with full screen mode that way too.
I could make the window any size or position, including fullscreen and it would
save and get re-loaded flawlessly, but only when the game was restarted.
That is because only time I was creating the display was on game start.
All other times I was making adjustments on this already created display.
So suppose I set the window to a small (say 1/4 screen size) and moved it up to
left corner. Then I quit the game and re-started. The window would be in the
exact same position, just as expected.
I could also set the screen to full screen with ALLEGRO_FULLSCREEN_WINDOW,
then exit and restart the program and that would also work exactly as expected.
The problem I am having can be described as follows:
1 - While the game is running change the window size
2 - Change into fullscreen mode
3 - Change back out of fullscreen mode to windowed mode
The window that I come back to is not the one that I changed to in step 1
It is the size that was passed to create_display(int width, int height)
when the program was started.
It would be nice to have some control over those hidden variables.
(or maybe even have them update automatically when the screen changes)
---------------------------------------------------------------------
Anyway I have come up with a work around.
I'm not even going to use ALLEGRO_FULLSCREEN_WINDOW.
I re-wrote my code to keep track of the variables myself and made my own
full screen windowed mode.
When I switch into it I just resize to desktop width and height and
set ALLEGRO_FRAMELESS mode.
When I switch out of it i just resize to my previous window size and
clear ALLEGRO_FRAMELESS mode.
So I consider this question answered, unless anyone has any insights
or ideas about other ways to accomplish this.
Thanks.
Ah!!! Okay, I see what you mean. Yeah, I had the same problem in my Deluxe Pacman 2 game (at my website linked below).
I ended up creating two initialize() functions. One for the display, one for everything else. I am a C programmer, so don't look to me for C++ class solutions.
When you wish to reset the display, you destroy the old one, totally recreate a new one, that also means you need to reload all the graphics you had loaded prior as they are loaded into video memory and will be gone as well. I'll pull up the code I have in Deluxe Pacman 2 for this. You can set Windowed mode, Fullscreen mode or fullscreen windowed mode in my game and it will reset the display while the game is running. You can even toggle OpenGL mode in game.
First I have shutdown_display() which destroys all loaded fonts, graphics, icons etc. You need to call then when you change the display first...
void shutdown_display(void) { // Destroy loaded fonts // Destroy loaded icon(s) // Destroy loaded bitmaps // unregister display event // destroy display /// Make certain you set all variables to NULL that used to point to bitmaps }
You then call your init display function to set everything back up with the new settings. I have a bool which is set to true when this is for resetting the display from my options. It is false when the game is first run, so the same function is used to start the initial display. I'll cut out most of my own code and leave just a few things in as an example...
And of course, when you change the display settings, you just call
shutdown_display();
init_display(true);
Thanks Neil!!
What OS is this? I see code to do what you want on Windows, but it might be missing on Linux.