<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Reusing bitmaps after creating a new display</title>
		<link>http://www.allegro.cc/forums/view/608819</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Sun, 20 Nov 2011 01:01:13 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;ve implemented switching between fullscreen and windowed modes in my game.  I destroy the old display, then create a new one.  The next step is to reload the bitmaps, so I don&#39;t get FPS in the single digits.  Just loading them from disk again works fine.</p><p>Then I tried using al_clone_bitmap() to speed up the process:</p><div class="source-code snippet"><div class="inner"><pre>  <span class="k1">for</span> <span class="k2">(</span>i <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span> i <span class="k3">&lt;</span> NUMBER_OF_BITMAPS<span class="k2">;</span> i<span class="k3">+</span><span class="k3">+</span><span class="k2">)</span> <span class="k2">{</span>
    old <span class="k3">=</span> bitmaps<span class="k2">[</span>i<span class="k2">]</span><span class="k2">;</span>
    <span class="k1">if</span> <span class="k2">(</span><span class="k3">!</span><span class="k2">(</span>bitmaps<span class="k2">[</span>i<span class="k2">]</span> <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_clone_bitmap"><span class="a">al_clone_bitmap</span></a><span class="k2">(</span>old<span class="k2">)</span><span class="k2">)</span><span class="k2">)</span>
      exit_message<span class="k2">(</span><span class="s">"Feil under konvertering av bitmaps til nytt display."</span><span class="k2">)</span><span class="k2">;</span>
    <a href="http://www.allegro.cc/manual/al_destroy_bitmap"><span class="a">al_destroy_bitmap</span></a><span class="k2">(</span>old<span class="k2">)</span><span class="k2">;</span>
  <span class="k2">}</span>
</pre></div></div><p>
After doing this, some of the bitmaps have been replaced by just white boxes. Any ideas?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (torhu)</author>
		<pubDate>Tue, 15 Nov 2011 17:17:25 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;m not sure, but I&#39;m going to be committing a change soon that should help. It adds an ALLEGRO_PRESERVE_TEXTURE flag (default off so nothing changes) that when used, will save your textures in system memory. Then in combination with ALLEGRO_CONVERT_BITMAP, you can simply destroy a display and create a new one and all the bitmaps are automatically converted.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Trent Gamblin)</author>
		<pubDate>Tue, 15 Nov 2011 19:49:07 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Ok, cool.  I was under the impression that reuploading of bitmaps to the video card would happen automatically with 5.1, but I guess that&#39;s not the case?  I&#39;m using 5.0.5, by the way.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (torhu)</author>
		<pubDate>Tue, 15 Nov 2011 20:48:39 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Yeah, I guess if your scenario is like... user presses button, toggle fullscreen, then you don&#39;t really need the ALLEGRO_PRESERVE_TEXTURE flag, in which case your code should work, provided that you are not cloning the bitmaps after destroying the display... but then they <u>should</u> be converted to memory bitmaps so I don&#39;t know why it isn&#39;t working. The use case for the ALLEGRO_PRESERVE_TEXTURE flag is when the bitmaps can become invalidated at any time, such as hotplugging monitors.</p><p>Short answer: not sure, can you post more code?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Trent Gamblin)</author>
		<pubDate>Tue, 15 Nov 2011 21:09:54 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>This is the code that does the switching, and creates the lovely white boxes.  I tried waiting until after I created the new display with destroying the old one, but that didn&#39;t work.  When switching from fullscreen to windowed, I got a window of the correct size, but that had no title bar, and was glued to the top left of the screen.  Like the old and the new display conflicted somehow.</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> toggle_fullscreen_mode<span class="k2">(</span><a href="http://www.allegro.cc/manual/ALLEGRO_EVENT_QUEUE"><span class="a">ALLEGRO_EVENT_QUEUE</span></a><span class="k3">*</span> event_queue<span class="k2">)</span>
<span class="number">  2</span><span class="k2">{</span>
<span class="number">  3</span>  <span class="k1">int</span> i<span class="k2">;</span>
<span class="number">  4</span>  <a href="http://www.allegro.cc/manual/ALLEGRO_BITMAP"><span class="a">ALLEGRO_BITMAP</span></a> <span class="k3">*</span>old<span class="k2">;</span>
<span class="number">  5</span>  <span class="k1">bool</span> <a href="http://www.delorie.com/djgpp/doc/libc/libc_865.html" target="_blank">window</a> <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_get_new_display_flags"><span class="a">al_get_new_display_flags</span></a><span class="k2">(</span><span class="k2">)</span> <span class="k3">&amp;</span> ALLEGRO_WINDOWED<span class="k2">;</span>
<span class="number">  6</span>
<span class="number">  7</span>  <a href="http://www.allegro.cc/manual/al_destroy_display"><span class="a">al_destroy_display</span></a><span class="k2">(</span>display<span class="k2">)</span><span class="k2">;</span>
<span class="number">  8</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><a href="http://www.delorie.com/djgpp/doc/libc/libc_865.html" target="_blank">window</a> ? ALLEGRO_FULLSCREEN <span class="k2">:</span> ALLEGRO_WINDOWED<span class="k2">)</span><span class="k2">;</span>
<span class="number">  9</span>  display <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>GFX_WIDTH, GFX_HEIGHT<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 10</span>
<span class="number"> 11</span>  <span class="c">/* if it didn't work, go back to the previous mode */</span>
<span class="number"> 12</span>  <span class="k1">if</span> <span class="k2">(</span><span class="k3">!</span>display<span class="k2">)</span> <span class="k2">{</span>
<span class="number"> 13</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><a href="http://www.delorie.com/djgpp/doc/libc/libc_865.html" target="_blank">window</a> ? ALLEGRO_WINDOWED <span class="k2">:</span> ALLEGRO_FULLSCREEN<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 14</span>    display <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>GFX_WIDTH, GFX_HEIGHT<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 15</span>  <span class="k2">}</span>
<span class="number"> 16</span>  <a href="http://www.delorie.com/djgpp/doc/libc/libc_48.html" target="_blank">assert</a><span class="k2">(</span>display<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 17</span>
<span class="number"> 18</span>  <span class="c">/* redo some of the setup that was originally done by init(), main(), and</span>
<span class="number"> 19</span><span class="c">     graphics_init() */</span>
<span class="number"> 20</span>  <a href="http://www.allegro.cc/manual/al_hide_mouse_cursor"><span class="a">al_hide_mouse_cursor</span></a><span class="k2">(</span>display<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 21</span>  <a href="http://www.allegro.cc/manual/al_set_window_title"><span class="a">al_set_window_title</span></a><span class="k2">(</span>display, WINDOW_TITLE<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 22</span>  <a href="http://www.allegro.cc/manual/al_register_event_source"><span class="a">al_register_event_source</span></a><span class="k2">(</span>event_queue, <a href="http://www.allegro.cc/manual/al_get_display_event_source"><span class="a">al_get_display_event_source</span></a><span class="k2">(</span>display<span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 23</span>  <span class="k1">if</span> <span class="k2">(</span><span class="k3">!</span><span class="k2">(</span><a href="http://www.allegro.cc/manual/font"><span class="a">font</span></a> <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_grab_font_from_bitmap"><span class="a">al_grab_font_from_bitmap</span></a><span class="k2">(</span>font_bitmap, <span class="n">4</span>, font_ranges<span class="k2">)</span><span class="k2">)</span><span class="k2">)</span>
<span class="number"> 24</span>    exit_message<span class="k2">(</span><span class="s">"Feil under konvertering av font til nytt display."</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 25</span>
<span class="number"> 26</span>  <span class="c">/* have to reupload all bitmaps to the graphics card */</span>
<span class="number"> 27</span>  <span class="k1">for</span> <span class="k2">(</span>i <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span> i <span class="k3">&lt;</span> NUMBER_OF_BITMAPS<span class="k2">;</span> i<span class="k3">+</span><span class="k3">+</span><span class="k2">)</span> <span class="k2">{</span>
<span class="number"> 28</span>    old <span class="k3">=</span> bitmaps<span class="k2">[</span>i<span class="k2">]</span><span class="k2">;</span>
<span class="number"> 29</span>    <span class="k1">if</span> <span class="k2">(</span><span class="k3">!</span><span class="k2">(</span>bitmaps<span class="k2">[</span>i<span class="k2">]</span> <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_clone_bitmap"><span class="a">al_clone_bitmap</span></a><span class="k2">(</span>old<span class="k2">)</span><span class="k2">)</span><span class="k2">)</span>
<span class="number"> 30</span>      exit_message<span class="k2">(</span><span class="s">"Feil under konvertering av bitmaps til nytt display."</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 31</span>    <a href="http://www.allegro.cc/manual/al_destroy_bitmap"><span class="a">al_destroy_bitmap</span></a><span class="k2">(</span>old<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 32</span>  <span class="k2">}</span>
<span class="number"> 33</span>  backgr <span class="k3">=</span> bitmaps<span class="k2">[</span>BACKGR_IMAGE<span class="k2">]</span><span class="k2">;</span>
<span class="number"> 34</span><span class="k2">}</span>
</div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (torhu)</author>
		<pubDate>Wed, 16 Nov 2011 02:23:29 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Does 5.0.5 have the bitmap auto-conversion that Elias and Matthew added? If so it seems like it&#39;s not working. In fact, some part of me thinks that I fixed a bug in that code while doing the ALLEGRO_PRESERVE_TEXTURE code... actually I&#39;m almost sure of it. I can send you a patch to that file so you can look for changes I made, if you want, but you&#39;ll have to just ignore the big chunks I added... the only thing holding this patch up from being committed to 5.1 is that there is a race condition I couldn&#39;t pin down and put in an al_rest(1) for the time being (in the iphone display creation code).
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Trent Gamblin)</author>
		<pubDate>Wed, 16 Nov 2011 02:50:27 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;m not sure if the auto-conversion is present in 5.0.5 or not.  I can&#39;t find it in the docs.  Working around it by loading the files from disk again works fine at the moment, since I have only 30 relatively small bitmaps.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (torhu)</author>
		<pubDate>Wed, 16 Nov 2011 03:11:40 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>The auto conversion stuff is not in 5.0. It needs more testing before that happens.</p><p>And before you commit anything that alters its behavior, you should probably post on AD first just to make sure the bug isn&#39;t actually a feature. Elias wrote the code, so I don&#39;t know it is implemented, but I know how it&#39;s supposed to work.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Matthew Leverton)</author>
		<pubDate>Wed, 16 Nov 2011 03:16:10 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Ok, I looked at it and I didn&#39;t actually change anything except adding a conditional branch. But it shouldn&#39;t matter AFAIK, destroying a display has always been supposed to convert to memory bitmaps. One quick fix might be to clone the bitmaps before destroying the display (save them in an array or some such, then copy them back.) Sounds like a hack though. This really sounds like the problems I was having with hot-plugging displays, except my textures were all black or had some noise in them. Are you using D3D or OpenGL?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Trent Gamblin)</author>
		<pubDate>Wed, 16 Nov 2011 04:03:44 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Looks I&#39;m using Direct3D, I checked the log file.  I tried cloning all the bitmaps (with al_clone_bitmap) after calling <span class="source-code"><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_MEMORY_BITMAP<span class="k2">)</span></span>, before destroying the old display.  Then I called <span class="source-code"><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_VIDEO_BITMAP<span class="k2">)</span></span> after destroying the old and creating the new display, and then cloned all bitmaps again.  But it just crashed.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (torhu)</author>
		<pubDate>Wed, 16 Nov 2011 04:36:48 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Did you destroy the video bitmaps after cloning them, before destroying the display?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Trent Gamblin)</author>
		<pubDate>Wed, 16 Nov 2011 07:19:55 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Yes.</p><p>EDIT:<br />It did actually work, I just had a bug in my code.  Sorry about that.</p><p>This code works:
</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> toggle_fullscreen_mode<span class="k2">(</span><a href="http://www.allegro.cc/manual/ALLEGRO_EVENT_QUEUE"><span class="a">ALLEGRO_EVENT_QUEUE</span></a><span class="k3">*</span> event_queue<span class="k2">)</span>
<span class="number">  2</span><span class="k2">{</span>
<span class="number">  3</span>  <span class="k1">int</span> i<span class="k2">;</span>
<span class="number">  4</span>  <a href="http://www.allegro.cc/manual/ALLEGRO_BITMAP"><span class="a">ALLEGRO_BITMAP</span></a> <span class="k3">*</span>old<span class="k2">;</span>
<span class="number">  5</span>  <a href="http://www.allegro.cc/manual/ALLEGRO_BITMAP"><span class="a">ALLEGRO_BITMAP</span></a> <span class="k3">*</span>backup<span class="k2">[</span>NUMBER_OF_BITMAPS<span class="k2">]</span><span class="k2">;</span>
<span class="number">  6</span>  <span class="k1">bool</span> <a href="http://www.delorie.com/djgpp/doc/libc/libc_865.html" target="_blank">window</a> <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_get_new_display_flags"><span class="a">al_get_new_display_flags</span></a><span class="k2">(</span><span class="k2">)</span> <span class="k3">&amp;</span> ALLEGRO_WINDOWED<span class="k2">;</span>
<span class="number">  7</span>
<span class="number">  8</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_MEMORY_BITMAP<span class="k2">)</span><span class="k2">;</span>
<span class="number">  9</span>  <span class="k1">for</span> <span class="k2">(</span>i <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span> i <span class="k3">&lt;</span> NUMBER_OF_BITMAPS<span class="k2">;</span> i<span class="k3">+</span><span class="k3">+</span><span class="k2">)</span> <span class="k2">{</span>
<span class="number"> 10</span>    old <span class="k3">=</span> bitmaps<span class="k2">[</span>i<span class="k2">]</span><span class="k2">;</span>
<span class="number"> 11</span>    <span class="k1">if</span> <span class="k2">(</span><span class="k3">!</span><span class="k2">(</span>backup<span class="k2">[</span>i<span class="k2">]</span> <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_clone_bitmap"><span class="a">al_clone_bitmap</span></a><span class="k2">(</span>old<span class="k2">)</span><span class="k2">)</span><span class="k2">)</span>
<span class="number"> 12</span>      exit_message<span class="k2">(</span><span class="s">"Feil under kopiering av bitmaps før fullskjermsbyte."</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 13</span>    <a href="http://www.allegro.cc/manual/al_destroy_bitmap"><span class="a">al_destroy_bitmap</span></a><span class="k2">(</span>old<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 14</span>  <span class="k2">}</span>
<span class="number"> 15</span>
<span class="number"> 16</span>  <a href="http://www.allegro.cc/manual/al_destroy_display"><span class="a">al_destroy_display</span></a><span class="k2">(</span>display<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 17</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><a href="http://www.delorie.com/djgpp/doc/libc/libc_865.html" target="_blank">window</a> ? ALLEGRO_FULLSCREEN <span class="k2">:</span> ALLEGRO_WINDOWED<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 18</span>  display <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>GFX_WIDTH, GFX_HEIGHT<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 19</span>
<span class="number"> 20</span>  <span class="c">/* if it didn't work, go back to the previous mode */</span>
<span class="number"> 21</span>  <span class="k1">if</span> <span class="k2">(</span><span class="k3">!</span>display<span class="k2">)</span> <span class="k2">{</span>
<span class="number"> 22</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><a href="http://www.delorie.com/djgpp/doc/libc/libc_865.html" target="_blank">window</a> ? ALLEGRO_WINDOWED <span class="k2">:</span> ALLEGRO_FULLSCREEN<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 23</span>    display <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>GFX_WIDTH, GFX_HEIGHT<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 24</span>  <span class="k2">}</span>
<span class="number"> 25</span>  <a href="http://www.delorie.com/djgpp/doc/libc/libc_48.html" target="_blank">assert</a><span class="k2">(</span>display<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 26</span>
<span class="number"> 27</span>  <span class="c">/* redo some of the setup that was originally done by init(), main(), and</span>
<span class="number"> 28</span><span class="c">     graphics_init() */</span>
<span class="number"> 29</span>  <a href="http://www.allegro.cc/manual/al_hide_mouse_cursor"><span class="a">al_hide_mouse_cursor</span></a><span class="k2">(</span>display<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 30</span>  <a href="http://www.allegro.cc/manual/al_set_window_title"><span class="a">al_set_window_title</span></a><span class="k2">(</span>display, WINDOW_TITLE<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 31</span>  <a href="http://www.allegro.cc/manual/al_register_event_source"><span class="a">al_register_event_source</span></a><span class="k2">(</span>event_queue, <a href="http://www.allegro.cc/manual/al_get_display_event_source"><span class="a">al_get_display_event_source</span></a><span class="k2">(</span>display<span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 32</span>  <span class="k1">if</span> <span class="k2">(</span><span class="k3">!</span><span class="k2">(</span><a href="http://www.allegro.cc/manual/font"><span class="a">font</span></a> <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_grab_font_from_bitmap"><span class="a">al_grab_font_from_bitmap</span></a><span class="k2">(</span>font_bitmap, <span class="n">4</span>, font_ranges<span class="k2">)</span><span class="k2">)</span><span class="k2">)</span>
<span class="number"> 33</span>    exit_message<span class="k2">(</span><span class="s">"Feil under konvertering av font til nytt display."</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 34</span>
<span class="number"> 35</span>  <span class="c">/* have to reupload all bitmaps to the graphics card */</span>
<span class="number"> 36</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_VIDEO_BITMAP<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 37</span>  <span class="k1">for</span> <span class="k2">(</span>i <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span> i <span class="k3">&lt;</span> NUMBER_OF_BITMAPS<span class="k2">;</span> i<span class="k3">+</span><span class="k3">+</span><span class="k2">)</span> <span class="k2">{</span>
<span class="number"> 38</span>    old <span class="k3">=</span> backup<span class="k2">[</span>i<span class="k2">]</span><span class="k2">;</span>
<span class="number"> 39</span>    <span class="k1">if</span> <span class="k2">(</span><span class="k3">!</span><span class="k2">(</span>bitmaps<span class="k2">[</span>i<span class="k2">]</span> <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_clone_bitmap"><span class="a">al_clone_bitmap</span></a><span class="k2">(</span>old<span class="k2">)</span><span class="k2">)</span><span class="k2">)</span>
<span class="number"> 40</span>      exit_message<span class="k2">(</span><span class="s">"Feil under konvertering av bitmaps til nytt display."</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 41</span>    <a href="http://www.allegro.cc/manual/al_destroy_bitmap"><span class="a">al_destroy_bitmap</span></a><span class="k2">(</span>old<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 42</span>  <span class="k2">}</span>
<span class="number"> 43</span>  backgr <span class="k3">=</span> bitmaps<span class="k2">[</span>BACKGR_IMAGE<span class="k2">]</span><span class="k2">;</span>
<span class="number"> 44</span><span class="k2">}</span>
</div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (torhu)</author>
		<pubDate>Wed, 16 Nov 2011 14:02:19 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>So I wonder if the conversion is happening too late in the d3d driver..
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Trent Gamblin)</author>
		<pubDate>Wed, 16 Nov 2011 19:12:24 +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/608819/937503#target">Trent Gamblin</a> said:</div><div class="quote"><p> But it shouldn&#39;t matter AFAIK, destroying a display has always been supposed to convert to memory bitmaps.
</p></div></div><p>Reading back through the discussion, it looks like no definitive answer was ever given regarding that. </p><p>There were three things suggested:</p><ol><li><p>Only bitmaps marked as CONVERT would be downgraded. Other video bitmaps would be invalidated (0x0 zombies).</p><br /></li><li><p>All video bitmaps would be downgraded to memory and implicitly tagged as auto-convert</p><br /></li><li><p>All video bitmaps would be downgraded to memory, but the convert tag would not be added. (Thus video bitmaps which were not explicitly tagged would be stuck as memory.)</p></li></ol><p>I&#39;m not sure which Elias implemented. I would prefer the first option because it is the most consistent: Allegro only tries to manage bitmaps marked with the auto-convert tag.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Matthew Leverton)</author>
		<pubDate>Thu, 17 Nov 2011 00:13:26 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Yes, I was talking about before the AUTO_CONVERT flag was introduced. At that time there was no conversion except for destroy display-&gt;displays video bitmaps converted to memory, and all platforms did it. I&#39;m not sure either which of those 3 is used now, but I guess it could be relevant. I&#39;d have to ask Elias which is used, which might tell us why the first code snippet of torhu&#39;s didn&#39;t work.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Trent Gamblin)</author>
		<pubDate>Thu, 17 Nov 2011 01:45:17 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I think destroying a display always converts all display bitmaps to memory bitmaps (if it is the last display sharing the bitmaps). Both in 5.0 and 5.1. The reason was to never have zombie bitmaps I think. I&#39;m all for changing it, so that a VIDEO bitmap would never be a MEMORY bitmap unless it is set to auto convert (which it would be by default).</p><p>The drawback is that we&#39;d have to introduce the concept of zombie bitmaps, i.e. bitmaps which cannot be drawn at all, not even as memory bitmaps. The only valid operation on them would be destroying them.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Thu, 17 Nov 2011 02:07:19 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>When I tried just destroying the old display and creating a new one, all the bitmaps seemed to be ok.  So the automatic conversion to memory bitmaps works.  It&#39;s when I cloned them after creating the new display that some of them turned into white boxes.</p><p>EDIT:<br />Nevermind, I just tried it and got white boxes anyway.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (torhu)</author>
		<pubDate>Thu, 17 Nov 2011 02:14:05 +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/608819/937572#target">Elias</a> said:</div><div class="quote"><p> The drawback is that we&#39;d have to introduce the concept of zombie bitmaps, i.e. bitmaps which cannot be drawn at all, not even as memory bitmaps. The only valid operation on them would be destroying them.</p></div></div><p>If video bitmaps were to be invalidated, Peter&#39;s comment was:
</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p> They should be 0x0 bitmaps without any data associated.<br /> We should allow al_create_bitmap to create 0x0 bitmaps anyway</p></div></div><p>I&#39;m not sure if he meant that those bitmaps should be able to be drawn (null op) or not.</p><p>Regardless of whether they can or not, I still prefer it (zombie bitmaps) because I think it makes it easier to document, explain, and understand when conversions happen: if you don&#39;t set the conversion flag, the bitmap will never be converted, and if you destroy the last display, the bitmap is lost.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Matthew Leverton)</author>
		<pubDate>Thu, 17 Nov 2011 02:37:18 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>The al_clone_bitmap() call in the first loop in my function has a tendency to return NULL.  Is there a limit to how many bitmaps I can create or something?  I destroy the old ones, but maybe there&#39;s some resource that gets depleted.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (torhu)</author>
		<pubDate>Thu, 17 Nov 2011 22:40:08 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Video Bitmaps live in the video card memory, if you run out of that, it tends to fail.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Thu, 17 Nov 2011 23:29:21 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Yes, but the video memory should be freed when I call al_destroy_bitmap, right?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (torhu)</author>
		<pubDate>Thu, 17 Nov 2011 23:57:28 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>yeah, but if you just create too many, then you have no recourse.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Thu, 17 Nov 2011 23:59:55 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I think I have no more than 32 bitmaps at any given time, so it&#39;s not the number of bitmaps that the problem.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (torhu)</author>
		<pubDate>Fri, 18 Nov 2011 00:02:02 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>It&#39;s not really the number that matters, but the amount of video memory they use up, and how much free video memory you have.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Fri, 18 Nov 2011 00:03:18 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Even the cheapest video cards have half a gig of memory nowadays.</p><p><a href="http://www.newegg.com/Store/SubCategory.aspx?SubCategory=48&amp;name=Desktop-Graphics-Video-Cards&amp;Order=PRICE">http://www.newegg.com/Store/SubCategory.aspx?SubCategory=48&amp;name=Desktop-Graphics-Video-Cards&amp;Order=PRICE</a>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Arthur Kalliokoski)</author>
		<pubDate>Fri, 18 Nov 2011 00:05:54 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Yeah, I don&#39;t know how likely it is that he&#39;s actually running out of video memory, unless he&#39;s leaking, or allegro is.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Fri, 18 Nov 2011 00:41:02 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I guess the question is: is Allegro leaking something?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (torhu)</author>
		<pubDate>Fri, 18 Nov 2011 01:13:42 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I don&#39;t think it is. Other people would have likely had problems by now.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Fri, 18 Nov 2011 01:33:16 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Guess I&#39;ll have to produce a test case then <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" /></p><p>UPDATE:<br />I did some debugging.  al_clone_bitmap returns null because it calls al_lock_bitmap, which calls al_lock_bitmap_region, which contains this piece of code:</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">if</span> <span class="k2">(</span>bitmap-&gt;locked<span class="k2">)</span>
      <span class="k1">return</span> NULL<span class="k2">;</span>
</pre></div></div><p>

Kind of embarrassing for me, don&#39;t you think? <img src="http://www.allegro.cc/forums/smileys/rolleyes.gif" alt="::)" />  My collision testing code locks the bitmaps before using al_get_pixel on them, but didn&#39;t always unlock them.  My original toggle_fullscreen_mode() function works fine after all, cloning the bitmaps once is enough.</p><p>Thanks for trying to help, guys <img src="http://www.allegro.cc/forums/smileys/grin.gif" alt=";D" /></p><p>I have a bonus question:  After toggling fullscreen, I would like to redraw the last frame.  The menu screens in the game are just static images being drawn once, which means that the screen turns black after toggling the fullscreen mode.  There is no way to get a copy of the front buffer, right?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (torhu)</author>
		<pubDate>Sat, 19 Nov 2011 03:29:40 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;m not sure you can get the frontbuffer, its not always supported IIRC. But you can grab the backbuffer, just draw the screen again on switch?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Sat, 19 Nov 2011 03:39:13 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>The backbuffer tends to not be the last frame, that&#39;s the problem...</p><p>It&#39;s not hard to work around, but it means that my toggle_fullscreen_mode function can&#39;t be completely self-contained.  There has to be code outside of it that knows about the switching.  And just always copying the backbuffer before blitting seems like a waste.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (torhu)</author>
		<pubDate>Sat, 19 Nov 2011 03:42:38 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Can you just call your &quot;render&quot; function again, if it&#39;s not all over the place?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Trent Gamblin)</author>
		<pubDate>Sat, 19 Nov 2011 04:52:56 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I don&#39;t have a render function for the menu stuff, since it&#39;s just static. I guess I&#39;ll just make the menu code save the frame before calling al_flip_display().  When the actual game loop is running, I have to do some extra stuff anyway.  Before calling toggle_fullscreen_mode() I stop the timers, and after calling it I call graphics_update() and then restart the timers.  Unless the game was already paused, that is.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (torhu)</author>
		<pubDate>Sat, 19 Nov 2011 05:05:35 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>If it&#39;s static why can&#39;t you just draw it?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Trent Gamblin)</author>
		<pubDate>Sat, 19 Nov 2011 05:34:16 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Well, it&#39;s not a single image, it&#39;s some text on a background, on another background.  It&#39;s just that there&#39;s no animation.  And there are several different screens like that.  I can just add a global last_frame variable and make the menu code update that.</p><p>Each menu has its own event loop, so the alternative would be to add code for handling the fullscreen switch in several places.</p><p>UPDATE:<br />I did it like this in my menu system:</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">static</span> <span class="k1">void</span> update_display<span class="k2">(</span><span class="k1">void</span><span class="k2">)</span>
<span class="k2">{</span>
  <span class="c">/* save the frame first, in case of a fullscreen switch */</span>
  <a href="http://www.allegro.cc/manual/al_set_target_bitmap"><span class="a">al_set_target_bitmap</span></a><span class="k2">(</span>last_frame<span class="k2">)</span><span class="k2">;</span>
  <a href="http://www.allegro.cc/manual/al_draw_bitmap"><span class="a">al_draw_bitmap</span></a><span class="k2">(</span><a href="http://www.allegro.cc/manual/al_get_backbuffer"><span class="a">al_get_backbuffer</span></a><span class="k2">(</span>display<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>
  <a href="http://www.allegro.cc/manual/al_set_target_backbuffer"><span class="a">al_set_target_backbuffer</span></a><span class="k2">(</span>display<span class="k2">)</span><span class="k2">;</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="k2">}</span>
</pre></div></div><p>
But this function takes about half a second to run, which is very noticeable.  The display is only 800x600x32.  Why would it take so long, and is there a better way of doing this?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (torhu)</author>
		<pubDate>Sat, 19 Nov 2011 22:36:40 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Instead of drawing to &#39;last_frame&#39; from the backbuffer, try just drawing your screen twice, once to &#39;last_frame&#39;, and once to the backbuffer before flipping.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Sat, 19 Nov 2011 22:51:42 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Thanks, that&#39;s better.  I just draw the menu to a bitmap, then draw that to the backbuffer.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (torhu)</author>
		<pubDate>Sun, 20 Nov 2011 00:27:20 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Assuming you don&#39;t use dirty rectangles and you make a full update of the display on every frame, then you don&#39;t need to draw twice, just call your display function on a different target just before you toggle fullscreen.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Sun, 20 Nov 2011 00:32:20 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>The original problem was that I don&#39;t have a single update_display() function, so that won&#39;t work <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (torhu)</author>
		<pubDate>Sun, 20 Nov 2011 00:45:29 +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/608819/937884#target">torhu</a> said:</div><div class="quote"><p>
I don&#39;t have a single update_display() function,
</p></div></div><p>
<img src="http://www.allegro.cc/forums/smileys/shocked.gif" alt=":o" />  The Horror!
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Sun, 20 Nov 2011 00:54:37 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>If this is A5, drawing to video bitmaps can be slow on older/slower hardware (like intel gpus).
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Sun, 20 Nov 2011 01:01:13 +0000</pubDate>
	</item>
</rss>
