<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Question about ALLEGRO_FULLSCREEN_WINDOW</title>
		<link>http://www.allegro.cc/forums/view/617328</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Sun, 25 Mar 2018 23:01:29 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I am trying to save the display size and position, so that it will<br />persist when the game is started again.</p><p>Mostly everything is working good, except for a few minor things:</p><p>Here is what works:</p><p>- I create a display with a certain width and height<br />- then I let the user resize and move the window<br />- I save the display size and position in my config file<br />- It comes back perfectly the next time the game is run</p><p>Here is what doesn&#39;t:</p><p>When I switch to ALLEGRO_FULLSCREEN_WINDOW and back,<br />the window uses the values that were used to create the display<br />not the window size that it previously was</p><p>I can store my changed position, and then when I change back:<br />- restore the position (easy)<br />- resize the display (takes another complete resize)</p><p>What I would really like to do, is be able to modify the values<br />in the display structure, so that switching back goes to the values<br />that were there before I switched into ALLEGRO_FULLSCREEN_WINDOW,<br />and not the ones used when creating the display.</p><p>From the manual:</p><p>&quot;The passed width and height are only used if the window is switched<br />out of fullscreen mode later but will be ignored initially.&quot;</p><p>If I just had access to those variables, I could set them to what I want.<br />(Or they could automatically be updated when the screen is resized.)</p><p>I suppose I could just destroy and re-create the display, but that<br />seems like a bit of overkill.</p><p>Does anyone have any advice on how I can achieve what I&#39;m trying to do here?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Michael Weiss)</author>
		<pubDate>Fri, 23 Mar 2018 18:04:10 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>ALLEGRO_FULLSCREEN_WINDOW by definition creates a Window which is the size of your full screen.  That can&#39;t be changed.</p><p>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.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Neil Roy)</author>
		<pubDate>Fri, 23 Mar 2018 23:59:38 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Thanks Neil,</p><p>That&#39;s not quite exactly what I&#39;m trying to do.</p><p>I already had it working so that it would save in the config and get reloaded.<br />And yes it worked with full screen mode that way too.<br />I could make the window any size or position, including fullscreen and it would<br />save and get re-loaded flawlessly, but only when the game was restarted.</p><p>That is because only time I was creating the display was on game start.</p><p>All other times I was making adjustments on this already created display.</p><p>So suppose I set the window to a small (say 1/4 screen size) and moved it up to<br />left corner.  Then I quit the game and re-started.  The window would be in the <br />exact same position, just as expected.</p><p>I could also set the screen to full screen with ALLEGRO_FULLSCREEN_WINDOW,<br />then exit and restart the program and that would also work exactly as expected.</p><p>The problem I am having can be described as follows:</p><p>1 - While the game is running change the window size<br />2 - Change into fullscreen mode<br />3 - Change back out of fullscreen mode to windowed mode</p><p>The window that I come back to is not the one that I changed to in step 1</p><p>It is the size that was passed to create_display(int width, int height)<br />when the program was started.</p><p>It would be nice to have some control over those hidden variables.<br />(or maybe even have them update automatically when the screen changes)</p><p>---------------------------------------------------------------------</p><p>Anyway I have come up with a work around.<br />I&#39;m not even going to use ALLEGRO_FULLSCREEN_WINDOW.</p><p>I re-wrote my code to keep track of the variables myself and made my own<br />full screen windowed mode.</p><p>When I switch into it I just resize to desktop width and height and<br />set ALLEGRO_FRAMELESS mode.</p><p>When I switch out of it i just resize to my previous window size and<br />clear ALLEGRO_FRAMELESS mode.</p><p>So I consider this question answered, unless anyone has any insights<br />or ideas about other ways to accomplish this.</p><p>Thanks.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Michael Weiss)</author>
		<pubDate>Sat, 24 Mar 2018 03:35:55 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Ah!!!  Okay, I see what you mean.  Yeah, I had the same problem in my Deluxe Pacman 2 game (at my website linked below).</p><p>I ended up creating two initialize() functions.  One for the display, one for everything else.  I am a C programmer, so don&#39;t look to me for C++ class solutions. <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" /></p><p>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&#39;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.</p><p>First I have <span class="source-code">shutdown_display<span class="k2">(</span><span class="k2">)</span></span> which destroys all loaded fonts, graphics, icons etc.  You need to call then when you change the display first...</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">void</span> shutdown_display<span class="k2">(</span><span class="k1">void</span><span class="k2">)</span>
<span class="k2">{</span>
   <span class="c">// Destroy loaded fonts</span>
   <span class="c">// Destroy loaded icon(s)</span>
   <span class="c">// Destroy loaded bitmaps</span>
   <span class="c">// unregister display event</span>
   <span class="c">// destroy display</span>

   <span class="c">/// Make certain you set all variables to NULL that used to point to bitmaps</span>
<span class="k2">}</span>
</pre></div></div><p>

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

And of course, when you change the display settings, you just call<br /><span class="source-code">shutdown_display<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span></span><br /><span class="source-code">init_display<span class="k2">(</span><span class="k1">true</span><span class="k2">)</span><span class="k2">;</span></span>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Neil Roy)</author>
		<pubDate>Sat, 24 Mar 2018 08:40:19 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Thanks Neil!!
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Michael Weiss)</author>
		<pubDate>Sun, 25 Mar 2018 06:11:44 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>What OS is this? I see code to do what you want on Windows, but it might be missing on Linux.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SiegeLord)</author>
		<pubDate>Sun, 25 Mar 2018 23:01:29 +0000</pubDate>
	</item>
</rss>
