|
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 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 Here is what doesn't: When I switch to ALLEGRO_FULLSCREEN_WINDOW and back, I can store my changed position, and then when I change back: What I would really like to do, is be able to modify the values From the manual: "The passed width and height are only used if the window is switched If I just had access to those variables, I could set them to what I want. I suppose I could just destroy and re-create the display, but that Does anyone have any advice on how I can achieve what I'm trying to do here?
|
Neil Roy
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. 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 I could also set the screen to full screen with ALLEGRO_FULLSCREEN_WINDOW, The problem I am having can be described as follows: 1 - While the game is running change the window size 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) It would be nice to have some control over those hidden variables. --------------------------------------------------------------------- Anyway I have come up with a work around. I re-wrote my code to keep track of the variables myself and made my own When I switch into it I just resize to desktop width and height and When I switch out of it i just resize to my previous window size and So I consider this question answered, unless anyone has any insights Thanks.
|
Neil Roy
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... 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 --- |
Michael Weiss
Member #223
April 2000
|
Thanks Neil!!
|
SiegeLord
Member #7,827
October 2006
|
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 |
|