<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Creating bitmap with ALLEGRO_MAG_LINEAR flag before creating display vs after</title>
		<link>http://www.allegro.cc/forums/view/616874</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Sat, 06 May 2017 02:44:55 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p><b>Update:</b> I managed to fix it by doing this instead, to preserve the existing bitmap flags:</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><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><a href="http://www.allegro.cc/manual/al_get_new_bitmap_flags"><span class="a">al_get_new_bitmap_flags</span></a><span class="k2">(</span><span class="k2">)</span> <span class="k3">|</span> ALLEGRO_MIN_LINEAR <span class="k3">|</span> ALLEGRO_MAG_LINEAR<span class="k2">)</span><span class="k2">;</span>
</div></div><p>

So I&#39;m guessing that by doing what what I was doing before, I was loading them as memory bitmaps, and for some reason, creating a display resets that?</p><p>----------</p><p>I ran into a weird problem today:</p><ul><li><p>If I load a bitmap with the ALLEGRO_MAG_LINEAR flag set before creating a display, drawing the bitmap causes the game to run very slow and eat up a lot of CPU.</p></li></ul><p>Example code:</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><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"> 2</span><a href="http://www.allegro.cc/manual/ALLEGRO_BITMAP"><span class="a">ALLEGRO_BITMAP</span></a><span class="k3">*</span> bitmap <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_load_bitmap"><span class="a">al_load_bitmap</span></a><span class="k2">(</span><span class="s">"my_bitmap.png"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 3</span><a href="http://www.allegro.cc/manual/ALLEGRO_DISPLAY"><span class="a">ALLEGRO_DISPLAY</span></a><span class="k3">*</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><span class="n">640</span>, <span class="n">480</span><span class="k2">)</span><span class="k2">;</span>
</div></div><p>

</p><ul><li><p>If I load the bitmap with the ALLEGRO_MAG_LINEAR flag set <i>after</i> creating a display, it runs perfectly fine.</p></li></ul><p>Example code:</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><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"> 2</span><a href="http://www.allegro.cc/manual/ALLEGRO_DISPLAY"><span class="a">ALLEGRO_DISPLAY</span></a><span class="k3">*</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><span class="n">640</span>, <span class="n">480</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 3</span><a href="http://www.allegro.cc/manual/ALLEGRO_BITMAP"><span class="a">ALLEGRO_BITMAP</span></a><span class="k3">*</span> bitmap <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_load_bitmap"><span class="a">al_load_bitmap</span></a><span class="k2">(</span><span class="s">"my_bitmap.png"</span><span class="k2">)</span><span class="k2">;</span>
</div></div><p>

Why is this? The documentation doesn&#39;t seem to mention anything about it (<a href="https://www.allegro.cc/manual/5/al_set_new_bitmap_flags">https://www.allegro.cc/manual/5/al_set_new_bitmap_flags</a>). Is there something else I should be doing?</p><p>For the record, I was using the Bitmap tutorial <a href="https://wiki.allegro.cc/index.php?title=Allegro_5_Tutorial/Bitmaps">here</a> for testing. I didn&#39;t change anything other than adding the pieces of code mentioned above. </p><p>(In case it matters, I&#39;m using Allegro 5.2.2.1 on Windows 8.1.)
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (xsquid)</author>
		<pubDate>Sun, 30 Apr 2017 10:38:19 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>You can also use <span class="ref"><sup>[<a href="#">1</a>]</sup></span> instead, but yes, using the set variant will clear the flag to auto convert memory bitmaps.
</p><div class="ref-block"><h2>References</h2><ol><li><a href="http://liballeg.org/a5docs/trunk/graphics.html#al_add_new_bitmap_flag">http://liballeg.org/a5docs/trunk/graphics.html#al_add_new_bitmap_flag</a></li></ol></div></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Sun, 30 Apr 2017 23:30:25 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>The problem is that you&#39;re loading a bitmap before the display is created. There&#39;s no graphics context at that point, so no video bitmaps can be created until there is. Which means you get a memory bitmap which uses memory, CPU, etc...</p><p>And Allegro won&#39;t auto convert bitmaps for you until you tell it to by calling <a href="http://liballeg.org/a5docs/trunk/graphics.html#al_convert_memory_bitmaps">al_convert_memory_bitmaps</a>.</p><p>Edit - see here :
</p><div class="quote_container"><div class="title"><a href="http://liballeg.org/a5docs/trunk/graphics.html#al_create_bitmap">The Manual</a> said:</div><div class="quote"><p>
If you create a bitmap without ALLEGRO_MEMORY_BITMAP set but there is no current display, a temporary memory bitmap will be created instead. You can later convert all such bitmap to video bitmap and assign to a display by calling al_convert_memory_bitmaps.
</p></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Mon, 01 May 2017 01:33:17 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="https://www.allegro.cc/forums/thread/616874/1030020#target">Edgar Reynaldo</a> said:</div><div class="quote"><p>The problem is that you&#39;re loading a bitmap before the display is created. There&#39;s no graphics context at that point, so no video bitmaps can be created until there is. Which means you get a memory bitmap which uses memory, CPU, etc...</p><p>And Allegro won&#39;t auto convert bitmaps for you until you tell it to by calling al_convert_memory_bitmaps</p></div></div><p>

That makes a lot of sense; I should&#39;ve realized! I feel like I read this before and then completely forgot about it. Thanks a lot for the helpful responses.</p><p>With regards to Elias&#39; response, the ALLEGRO_CONVERT_BITMAP is set by default, and I was clearing it. The ALLEGRO_AUTO_CONVERT_BITMAPS display flag, which is also set by default, will automatically convert memory bitmaps into video bitmaps when the display is created so long as the ALLEGRO_CONVERT_BITMAP flag is set. Does that mean that I don&#39;t need to call al_convert_memory_bitmaps as long as I keep these flags enabled? According to the docs, the ALLEGRO_AUTO_CONVERT_BITMAPS flag...
</p><div class="quote_container"><div class="title">The Manual said:</div><div class="quote"><p>
... causes any existing memory bitmaps with the ALLEGRO_CONVERT_BITMAP flag to be converted to a display bitmap of the newly created display with the option set.</p></div></div><p>

So then, my understanding is that as long as I&#39;ve got the flags set appropriately I&#39;ll never need to call al_convert_memory_bitmaps; this is only for situations where the flags aren&#39;t set to have this done automatically. Is this correct?</p><p>And as a side-note, would you consider it bad practice to create the bitmaps before creating the display? Is the conversion from memory to video bitmaps super costly?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (xsquid)</author>
		<pubDate>Sat, 06 May 2017 02:25:21 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Yes, by default all bitmaps will get converted to be used with the first display that is created.</p><p>The conversion is costly but has to be done either way because a bitmap loaded from a file always resides in memory at first. So if al_load_bitmap takes time A to load from disk and time B to convert, then if you load your bitmaps after the display you get:</p><p>A+B A+B A+B</p><p>If you load them before you get:</p><p>A+A+A<br />Create display<br />B+B+B</p><p>In the end the actual game starts at the exact same point in time, after each bitmap was loaded and converted.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Sat, 06 May 2017 02:44:55 +0000</pubDate>
	</item>
</rss>
