<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Allegro 5 Multithread Issue</title>
		<link>http://www.allegro.cc/forums/view/617427</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Fri, 08 Jun 2018 14:39:51 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>al_init();<br />al_init_primitives_addon();<br />al_init_image_addon();<br />etc----------<br />I called all the necessary functions to make a window from the main function. Then I used al_clear_to_color(al_map_rgb(200, 100, 150)); and it works fine - no problem. </p><p>I called all the necessary functions to make a window from the main function. Then I used another thread to call al_clear_to_color(al_map_rgb(200, 100, 150)); but it shows error(not working). It&#39;s acting like as if the thread that called all the necessary functions like al_init() and etc..... are in control. Can anyone help me fix it?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thinkal VB)</author>
		<pubDate>Fri, 01 Jun 2018 03:00:42 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>You can use <a href="https://liballeg.org/a5docs/trunk/graphics.html#al_set_target_bitmap">al_set_target_bitmap</a> to change the target display for drawing commands on the current thread. However note that this can be slow and lead to unexpected errors if you&#39;re not careful - best is to do your drawing commands on the same thread which called al_create_display.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Fri, 01 Jun 2018 04:43:44 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hai Elias, thanks for answering <br />I never thought this forum is this much active - I admire and respect peoples like you (really) Thanks... </p><p>I fixed it in a weird way. <br />Every thread that goes to the rendering subroutine will go through this -&gt; <br />// Note:- AClass contains the display variable 
</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>AClass::AClass<span class="k2">(</span><span class="k2">)</span> <span class="c">// constructor</span>
<span class="number">  2</span><span class="k2">{</span>
<span class="number">  3</span><span class="c">/*initialize all the allegro variables*/</span>
<span class="number">  4</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>NULL<span class="k2">)</span><span class="k2">;</span>
<span class="number">  5</span><span class="k2">}</span>
<span class="number">  6</span>
<span class="number">  7</span><span class="k1">void</span> AClass::startRendering<span class="k2">(</span><span class="k2">)</span>
<span class="number">  8</span><span class="k2">{</span>
<span class="number">  9</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><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="k2">)</span><span class="k2">;</span>
<span class="number"> 10</span>
<span class="number"> 11</span><span class="k1">while</span><span class="k2">(</span>keepRendering<span class="k2">)</span>
<span class="number"> 12</span><span class="k2">{</span> <span class="c">/* take animations from que and render them */</span> <span class="k2">}</span>
<span class="number"> 13</span>
<span class="number"> 14</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>NULL<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 15</span><span class="k2">}</span>
</div></div><p>
However it is working, but sometimes it is throwing an exception. Is it a good way to get this done? <br />Also, I heard that the thread with the control to the display&#39;s back buffer must load the bitmaps or else they will be loaded in RAM rather than into the graphics RAM(resulting in lag). Is it correct?  <br />One more thing- can you explain why 3.44 KB PNG file, when loaded using al_load_bitmap(), takes ~3MB of memory space? </p><p>Test : <br />Normal execution : 27 MB </p><p>Load bitmap (an image) 88*2064 pixels <br />Execution : 35 MB</p><p>Create bitmap (blank) 88*2064 pixels <br />Execution : 33 MB
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thinkal VB)</author>
		<pubDate>Fri, 01 Jun 2018 13:13:40 +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/617427/1037629#target">Thinkal VB</a> said:</div><div class="quote"><p>
One more thing- can you explain why 3.44 KB PNG file, when loaded using al_load_bitmap(), takes ~3MB of memory space?
</p></div></div><p>
That&#39;s easy! It&#39;s not compressed when you put it in memory! That&#39;s the whole point. If it was, you&#39;d have to uncompress it every time you wanted to use it and then throw away that result and do it again the next time. Allocating and freeing a block of memory takes a lot time, and, why throw away the uncompressed version anyway if you already have it?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Chris Katko)</author>
		<pubDate>Fri, 01 Jun 2018 18:40:25 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Thanks, Chris Kato<br /> I did some research on the memory issue and found some information like the total m/y space for an image x *y pixel (long and wide) would be x*y*3 for RGB. I calculated a rough of 0.5 MB for a pic which takes up 5 MB of space in reality. Is it normal or I am leaking m/y or stuff? I double checked for memory leak but didn&#39;t find any.</p><p>You guys are amazing...<br />I wish I had some friends who are pro programmers.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thinkal VB)</author>
		<pubDate>Fri, 01 Jun 2018 18:47:41 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>It&#39;s normal. Uncompressed images take a lot of space (and the main reason why modern AAA titles supporting 4K displays are over 60GB pretty regularly).</p><p>That said graphics cards do support some image compression formats, but these are specialized formats the card can decode in hardware. You wont see any typical image editor outputting them--you&#39;ll usually use a special conversion step to go from image editor output to a compressed texture format (and which one depends on the type of texture). <a href="https://www.fsdeveloper.com/wiki/index.php?title=DXT_compression_explained">DXT Compression</a>. There are more formats than listed in that link, btw. I think there are either 7 or 8 now, though, you&#39;ll need recent hardware to access the latest formats.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (relpatseht)</author>
		<pubDate>Fri, 01 Jun 2018 20:55:53 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>That&#39;d probably be because you forgot to multiply that by the number of bits per channel <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" /></p><div class="source-code snippet"><div class="inner"><pre>total pixels <span class="k3">=</span> width <span class="k3">*</span> height
bits per pixel <span class="k3">=</span> <span class="n">32</span> <span class="k3">=</span> <span class="n">8</span> bits <span class="k3">*</span> <span class="n">4</span> channels <span class="k2">(</span>red, green, blue, alpha<span class="k2">)</span>

minimum bits needed to store image <span class="k3">=</span> total pixels <span class="k3">*</span> bits per pixel
</pre></div></div><p>

Taking this into account, the minimum size for your 88x2064 image as stored in memory would be:</p><div class="source-code snippet"><div class="inner"><pre><span class="n">88</span> <span class="k3">*</span> <span class="n">2064</span> <span class="k3">*</span> <span class="n">32</span> <span class="k3">=</span> <span class="n">5812224</span> bits
</pre></div></div><p>

This equates to about 750kB, which is a fair bit less than the 3MB you mentioned. However, there will be other things taking up space; we haven&#39;t yet accounted for all of the bitmap&#39;s metadata, struct padding, or any other memory that Allegro or libpng may have had to allocate to facilitate the loading of images.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (dthompson)</author>
		<pubDate>Fri, 01 Jun 2018 20:58:55 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Thank you dthompson for your enlightening support <br />I never knew the computer graphics is this much deep and complicated. Next time I will keep in mind to multiply it by the number of channels <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" /> <br />You guys are legends ......... I love this Forum more than Facebook </p><p>One more thing; I have a background texture - I guess it doesn&#39;t need alpha channel?. <br />How can I remove alpha channel from bitmaps to reduce its size? <img src="http://www.allegro.cc/forums/smileys/huh.gif" alt="???" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thinkal VB)</author>
		<pubDate>Fri, 01 Jun 2018 21:36:20 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Your paint program should have an option to save as a 24 bit png. Or you can just use .bmp.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Thu, 07 Jun 2018 08:05:46 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Thank you Edgar Reynaldo for the replay <br />I will use 24 bit bmp - my paint doesn&#39;t have the 24 bit png. <img src="http://www.allegro.cc/forums/smileys/sad.gif" alt=":(" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thinkal VB)</author>
		<pubDate>Thu, 07 Jun 2018 14:09:22 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>A note : The same image, encoded as .bmp or as .png, may be smaller as a png due to its compression. .bmp is not a compressed format.</p><p>If you want good compression, export as a .jpg with various levels of quality. Quality level 70 still looks very much the same as the original, but gets really good compression.</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/617427/1037743#target">Thinkal VB</a> said:</div><div class="quote"><p>
Thank you Edgar Reynaldo for the <b>replay</b>
</p></div></div><p>
You&#39;re welcome. I always like giving players another life. <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" /> xD
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Thu, 07 Jun 2018 14:29:51 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p><img src="http://www.allegro.cc/forums/smileys/cheesy.gif" alt=":D" /><img src="http://www.allegro.cc/forums/smileys/cool.gif" alt="8-)" /> Thank you Edgar Reynaldo<br />I will keep that in my mind when I browse for game assets.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thinkal VB)</author>
		<pubDate>Thu, 07 Jun 2018 15:33:40 +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/617427/1037743#target">Thinkal VB</a> said:</div><div class="quote"><p>
I will use 24 bit bmp - my paint doesn&#39;t have the 24 bit png. <img src="http://www.allegro.cc/forums/smileys/sad.gif" alt=":(" />
</p></div></div><p>
What? WHY?</p><p>Also, you can always convert bmp to PNG using any other program afterwards. If you&#39;re on Linux, it&#39;s super easy, with plenty of terminal one-liners.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Chris Katko)</author>
		<pubDate>Thu, 07 Jun 2018 19:52:29 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Thank you Chris Katko for replying <br />I did download photoshop to my system. So no problem regarding conversion anymore. Thanks for your kind support.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thinkal VB)</author>
		<pubDate>Thu, 07 Jun 2018 21:27:30 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Would you rather take less disk space, or load faster? The only format you should use for images is a compressed texture, as I said earlier.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (relpatseht)</author>
		<pubDate>Fri, 08 Jun 2018 05:09:06 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Thank you relpatseht- for your kind suggestions and knowledge. I am learning new things every day...8-)
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thinkal VB)</author>
		<pubDate>Fri, 08 Jun 2018 14:39:51 +0000</pubDate>
	</item>
</rss>
