Allegro.cc - Online Community

Allegro.cc Forums » Allegro Development » Question about ALLEGRO_FULLSCREEN_WINDOW

This thread is locked; no one can reply to it. rss feed Print
Question about ALLEGRO_FULLSCREEN_WINDOW
Michael Weiss
Member #223
April 2000

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?

NiteHackr
Member #2,229
April 2002

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.

Michael Weiss
Member #223
April 2000

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.

NiteHackr
Member #2,229
April 2002

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

#SelectExpand
1void init_display(bool reset_display) 2{ 3 if(!reset_display) { // These will already be NULL'd out if this is a reset 4 // Initialize pointer arrays to zero before anything else so that if we 5 // have to call shutdown() they can be checked without problems 6 7 /// Here I set all my bitmaps to NULL as this is the game startup 8 /// otherwise all the bitmaps will already be NULL if this is a reset 9 /// and doing this won't be needed 10 } 11 12 // Vsync 1 means force on, 2 means forced off. 13 if(setting.vsync) 14 al_set_new_display_option(ALLEGRO_VSYNC, setting.vsync, ALLEGRO_SUGGEST); 15 16 // Which display mode will we be using? Check for OpenGL setting as well. 17 switch(setting.fullscreen) { 18 case 0: // Windowed 19 if(setting.opengl) al_set_new_display_flags(ALLEGRO_OPENGL | ALLEGRO_WINDOWED); 20 else al_set_new_display_flags(ALLEGRO_WINDOWED); 21 break; 22 case 1: // Fullscreen Window 23 if(setting.opengl) al_set_new_display_flags(ALLEGRO_FULLSCREEN_WINDOW | ALLEGRO_OPENGL); 24 else al_set_new_display_flags(ALLEGRO_FULLSCREEN_WINDOW); 25 if(setting.frequency) al_set_new_display_refresh_rate(setting.frequency); 26 break; 27 case 2: // Regular Fullscreen 28 if(setting.opengl) al_set_new_display_flags(ALLEGRO_FULLSCREEN | ALLEGRO_OPENGL); 29 else al_set_new_display_flags(ALLEGRO_FULLSCREEN); 30 if(setting.frequency) al_set_new_display_refresh_rate(setting.frequency); 31 break; 32 default: // invalid mode, we'll select windowed by default and reset the fullscreen variable 33 if(setting.opengl) al_set_new_display_flags(ALLEGRO_OPENGL | ALLEGRO_WINDOWED); 34 else al_set_new_display_flags(ALLEGRO_WINDOWED); 35 setting.fullscreen = 0; 36 } 37 38 al_set_new_bitmap_flags(ALLEGRO_MAG_LINEAR); 39 al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_INVERSE_ALPHA); 40 41 al_set_new_display_option(ALLEGRO_SINGLE_BUFFER, 1, ALLEGRO_REQUIRE); 42 43 // Allegro picks the desktop resolution automatically with ALLEGRO_FULLSCREEN_WINDOW flag set. 44 setting.screen = al_create_display(WIDTH, HEIGHT); 45 if(!setting.screen) { 46 a5_error(AT, setting.screen, "Create display failed."); 47 shut_down(); 48 exit(1); 49 } 50 51 setting.w = al_get_display_width(setting.screen); 52 setting.h = al_get_display_height(setting.screen); 53 54 if(setting.opengl) printf("OpenGL version: 0x%08X\n", al_get_opengl_version()); 55 56 al_clear_to_color(al_map_rgb_f(0, 0, 0)); 57 al_flip_display(); 58 59 /// Load Window Icon here 60 /// Set Window Title here 61 62 /// ****** Load Fonts ******* 63 /// ****** Load background tiles ******* 64 /// ****** Load pills ******* 65 /// ******* Load lines ******* 66 /// ******* Load Pickups ******* 67 /// ******* Load Tools ******* 68 /// ******* Load hearts ******* 69 /// ******* Load Ghost Spawn ******* 70 /// ******* Load Teleport ******* 71 /// ******* Load Pickup Spawn ******* 72 /// ******* Create bitmap for drawing the level on ******* 73 /// ******* Initialize Pacman ******* 74 // Load Pacman sprite sheet first 75 /// ****** Initialize Ghosts ******* 76 // Load Ghosts bitmaps 77 // Load Blue Ghost and Eyes bitmaps 78 // Load ice_cube used when ghosts are frozen. 79 // reset the target bitmap back to the display 80 // register the new display in the event_queue 81}

And of course, when you change the display settings, you just call
shutdown_display();
init_display(true);

Michael Weiss
Member #223
April 2000

Thanks Neil!!

SiegeLord
Member #7,827
October 2006
avatar

What OS is this? I see code to do what you want on Windows, but it might be missing on Linux.

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

Go to: