<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Going from Windowed to Fullscreen at runtime?</title>
		<link>http://www.allegro.cc/forums/view/608811</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Tue, 15 Nov 2011 03:27:19 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Right now to do this I use:
</p><div class="source-code snippet"><div class="inner"><pre><a href="http://www.allegro.cc/manual/al_toggle_display_flag"><span class="a">al_toggle_display_flag</span></a><span class="k2">(</span>context,ALLEGRO_FULLSCREEN_WINDOW,fullscreen<span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

But the problem with this is I cannot set the fullscreen resolution. What do I do if the user wants to go fullscreen at 640x480 but the desktop is at 1280x800?</p><p>Thanks
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (jmasterx)</author>
		<pubDate>Mon, 14 Nov 2011 18:53:55 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I think you have to use the regular fullscreen mode if you want to control the resolution.  Otherwise you&#39;d effectively be changing the user&#39;s desktop resolution, which kind of defeats the purpose of the fullscreen windowed mode.  And the user probably wouldn&#39;t be too happy about it either.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (torhu)</author>
		<pubDate>Mon, 14 Nov 2011 22:34:43 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>So basically I should decide this at application startup and when the user selected fullscreen I should tell them this will take effect the next time the application is started?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (jmasterx)</author>
		<pubDate>Mon, 14 Nov 2011 22:36:08 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>A related question - what happens to all your video bitmaps when you change from a windowed to a fullscreen resolution? Are they all compatible with the new display?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Mon, 14 Nov 2011 22:42:09 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>If you&#39;re using the fullscreen_window mode, you don&#39;t need to do a thing.</p><p>If you &quot;switch between&quot; windowed and fullscreen modes with the other drivers you have to recreate the displays, and all bitmaps have to be re-uploaded, but I THINK allegro will do that for you, at least 5.1 will. And 5.0 <i>might</i>? I can&#39;t remember the full details.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Tue, 15 Nov 2011 02:07:33 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I can&#39;t remember completely, but I think I read somewhere that SFML only uses a single OpenGL / DX context, so I don&#39;t think it would suffer the same problem.</p><p>I don&#39;t know much about OpenGL or DX, but why does allegro need to recreate the &#39;context&#39; for every display? Could there be a <span class="source-code">al_initialize_graphics<span class="k2">(</span><span class="k2">)</span></span> function that performed this task, and then every successive <span class="source-code"><a href="http://www.allegro.cc/manual/al_create_display"><span class="a">al_create_display</span></a></span> call would use the same context, thus eliminating the need to re-upload textures?</p><p>Also, wouldn&#39;t that eliminate the problem of secondary threads not being able to correctly access video bitmaps?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Tue, 15 Nov 2011 02:13:41 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;m pretty sure the context tends to be tied to a given &quot;window&quot;. Destroy the window, and there goes your context.</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/608811/937394#target">Edgar Reynaldo</a> said:</div><div class="quote"><p>Also, wouldn&#39;t that eliminate the problem of secondary threads not being able to correctly access video bitmaps?</p></div></div><p>Doubt it. OpenGL context and state is per thread. You have to have one thread give up exclusive access on that context, and then have your other thread acquire the context, then do stuff with it. If the first thread wants access back, you have to do the same thing all over again, just in the reverse direction.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Tue, 15 Nov 2011 02:18:47 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Can SFML switch between fullscreen/window mode without re-uploading textures? If yes then there must be a way.</p><p>For Allegro (under Windows, in Linux changing video modes doesn&#39;t touch the context anyway) what happens is the display gets destroyed and all bitmaps tied to it get converted to memory bitmaps (if it&#39;s the last display at least). Then when you create a new display in 5.0.x they stay memory bitmaps and you have to re-upload them. In current SVN with the default flags the bitmaps will automatically be re-uploaded and get assigned to the new display (I think). So at least in 5.2 you won&#39;t have to do anything.</p><p>Also in SVN is an example which has a background thread loading bitmaps.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Tue, 15 Nov 2011 02:26:19 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Does switching from fullscreen to window work properly?  When I try it, I get a window that is glued to the upper left of the screen, and doesn&#39;t have a title bar.  Maybe I&#39;m doing it wrong?  And of course, I get 3 fps because I haven&#39;t reuploaded the textures.  I&#39;m using 5.0.5 on Windows 7.</p><p>I tried switching from fullscreen to window with ex_display_options, but that just crashes.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (torhu)</author>
		<pubDate>Tue, 15 Nov 2011 02:38:51 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/608811/937396#target">Elias</a> said:</div><div class="quote"><p>
Can SFML switch between fullscreen/window mode without re-uploading textures? If yes then there must be a way.
</p></div></div><p>
I really don&#39;t know, I would have to do some research to be sure. From the docs it seemed like it could though (or maybe it just automatically converts all it&#39;s bitmaps and just gives the illusion of compatibility).</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/608811/937395#target">Thomas Fjellstrom</a> said:</div><div class="quote"><p>
and then have your other thread acquire the context, then do stuff with it. If the first thread wants access back, you have to do the same thing all over again, just in the reverse direction. 
</p></div></div><p>
Grr... Just can&#39;t seem to reach the goal of being able to simultaneously display and load resources into video bitmaps. But I guess it might not make sense to have more than one thread with access to the GPU at a time.</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/608811/937396#target">Elias</a> said:</div><div class="quote"><p>
Also in SVN is an example which has a background thread loading bitmaps. 
</p></div></div><p>
But it can only load them into memory bitmaps right? And then the main thread with the display has to convert them to video bitmaps? It would be nice if they could be loaded directly into video bitmaps instead.</p><p>&lt;/wishlist&gt;
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Tue, 15 Nov 2011 02:42:25 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Yes, you need to do the conversion manually. </p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/608811/937399#target">Edgar Reynaldo</a> said:</div><div class="quote"><p> It would be nice if they could be loaded directly into video bitmaps instead.</p></div></div><p>I think it&#39;s not possible, because as Thomas stated OpenGL context and state is per thread, and in my deep ignorance I think the reason it&#39;s per thread is because of the hardware acceleration, I think OpenGL wants just one thread accessing to the GPU memory directly.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (AMCerasoli)</author>
		<pubDate>Tue, 15 Nov 2011 03:11:22 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>You can make it work, I&#39;m not sure how well or how smooth it would go, but you can do something like...</p><p>1. (thread1) Display loading screen<br />2. (thread1) give up context<br />3. (thread1) signal thread2 to acquire context (and sleep)<br />4. (thread2) acquire context<br />5. (thread2) load one bitmap<br />6. (thread2) give up context<br />7. (thread2) signal thread1 to acquire context (and sleep)<br />8. goto 1
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Tue, 15 Nov 2011 03:15:13 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>But that is still serial processing and not parallel, so why bother having more than one thread in the first place?</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">while</span> <span class="k2">(</span><span class="k3">!</span>done<span class="k2">)</span> <span class="k2">{</span>
   Display<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
   CheckInput<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
   done <span class="k3">=</span> LoadNextResource<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="k2">}</span>
</pre></div></div><p>

I&#39;ve been looking at SFML, and their RenderWindow has a Draw(Drawable&amp; d) function. Their Image class doesn&#39;t have any way to specify memory or video bitmap use, so that must be automated somehow, and you can have more than one RenderWindow draw the same Drawable, so either there is some automatic conversion between contexts, or somehow it is shared. I&#39;d have to dig through their source code to find out though, and I don&#39;t have time for that right now.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Tue, 15 Nov 2011 03:25:58 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Well thread1 can be doing other stuff at the same time. logic and what not. it doesn&#39;t have to sleep the whole time.</p><p>I think you can have shared contexts in some cases, but I don&#39;t think they work everywhere (on all platforms).</p><p>append: or rather, you can have two GL contexts that can share data. But I&#39;m not sure how well it works, and if its all that fast? and again it probably isn&#39;t supported in all places.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Tue, 15 Nov 2011 03:27:19 +0000</pubDate>
	</item>
</rss>
