<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Transparent pixel</title>
		<link>http://www.allegro.cc/forums/view/615498</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Wed, 01 Jul 2015 06:45:36 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>My question regards going about the transparent pixel of my sprite, I use 24 bit .tga&#39;s with no alpha channel(obviously) and load them using al_load_bitmap(*char);<br />I recall reading that there is a specific color (a shade of pink i believe) that allegros renderer omits from being rendered to create transparency, I wondered if there was any way i could tell the engine what color to omit from each sprite either individually or globally and if not then which rgb value is by default omitted to create transparency?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (blakat)</author>
		<pubDate>Mon, 29 Jun 2015 13:32:53 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;m asuming you&#39;re using Allegro 5. In case you&#39;re actually using Allegro 4, &quot;magic pink&quot; (R: 255, G: 0, B: 255) is the color you want for transparency. If you&#39;re using Allegro 5, though, this is the function you want:</p><p><span class="source-code"><span class="k1">void</span> <a href="http://www.allegro.cc/manual/al_convert_mask_to_alpha"><span class="a">al_convert_mask_to_alpha</span></a><span class="k2">(</span><a href="http://www.allegro.cc/manual/ALLEGRO_BITMAP"><span class="a">ALLEGRO_BITMAP</span></a> <span class="k3">*</span>bitmap, <a href="http://www.allegro.cc/manual/ALLEGRO_COLOR"><span class="a">ALLEGRO_COLOR</span></a> mask_color<span class="k2">)</span><span class="k2">;</span></span></p><p>It converts all pixels on an image with a certain color to transparent.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (RPG Hacker)</author>
		<pubDate>Mon, 29 Jun 2015 13:36:38 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I am using Allegro 5<br />I used al_convert_mask_to_alpha to no avail, i passed it a the pointer to my ALLEGRO_BITMAP and my ALLEGRO_COLOR with the values 0, 255, 114 and it failed to create transparency on my 24 bit tga(the green color pixals still rendered, would this function only work if my tga had a alpha channel? If so is there another way passed this? I tried placing it both inside and outside the loop i swap buffers by the way.<br /><img src="http://www.allegro.cc/forums/smileys/huh.gif" alt="???" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (blakat)</author>
		<pubDate>Mon, 29 Jun 2015 16:13:35 +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/615498/1014394#target">blakat</a> said:</div><div class="quote"><p> would this function only work if my tga had a alpha channel</p></div></div><p>Maybe Allegro automatically picks a bitmap format without Alpha when loading an image that doesn&#39;t have an alpha channel. You can override the bitmap format, though. Just call this function before loading your image:</p><p><span class="source-code"><span class="k1">void</span> <a href="http://www.allegro.cc/manual/al_set_new_bitmap_format"><span class="a">al_set_new_bitmap_format</span></a><span class="k2">(</span><span class="k1">int</span> format<span class="k2">)</span><span class="k2">;</span></span></p><p>Just pass it any format that supports alpha like ALLEGRO_PIXEL_FORMAT_ANY_WITH_ALPHA, ALLEGRO_PIXEL_FORMAT_ARGB_8888 etc.</p><p>I recommend first calling</p><p><span class="source-code"><span class="k1">int</span> <a href="http://www.allegro.cc/manual/al_get_new_bitmap_format"><span class="a">al_get_new_bitmap_format</span></a><span class="k2">(</span><span class="k1">void</span><span class="k2">)</span><span class="k2">;</span></span></p><p>to backup the currently active bitmap format and then restore this format after loading your bitmap (so that all bitmaps loader afterwards will be created with the originally set bitmap format).
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (RPG Hacker)</author>
		<pubDate>Tue, 30 Jun 2015 00:42:34 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Well... Are you sure you got the color right (maybe try full black / white)? Are you sure you use the function on the very bitmap you draw later?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Polybios)</author>
		<pubDate>Tue, 30 Jun 2015 01:43:42 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I got it to work, I simply had the wrong rgb value. My final question is how come when pass a ALLEGRO_COLOR variable directly into the second arguement of al_convert_mask_to_alpha() it doesnt seem to have effect? It only seems to work when I write al_convert_mask_to_alpha(*, al_map_rgb(short, short, short));
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (blakat)</author>
		<pubDate>Tue, 30 Jun 2015 07:17:03 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>ALLEGRO_COLOR uses float values for color components (0.0f to 1.0f). Could that have been your mistake?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (RPG Hacker)</author>
		<pubDate>Tue, 30 Jun 2015 13:46:27 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I tried modifying my operation with the info you shared<br />transparentPixal = al_map_rgb(0.0f, 255.0f, 114.0f);<br />It did not help<br />al_convert_mask_to_alpha(bmp, transparentPixal);<br />It compiles fine, but no transparency, this line however works<br />al_convert_mask_to_alpha(bmp, al_map_rgb(0.0f, 255.0f, 114.0f));<br />But I would like to pass a variable as a argument instead, I guess if all else fails I can use a array to store objects rgb values to pass as arguement to al_map_rgb(), but before i succumb to that any suggestions?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (blakat)</author>
		<pubDate>Tue, 30 Jun 2015 15:03:24 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>It should work... <br />caller:<br /><span class="source-code">YourFunction<span class="k2">(</span><a href="http://www.allegro.cc/manual/al_map_rgb"><span class="a">al_map_rgb</span></a><span class="k2">(</span><span class="n">0</span>, <span class="n">255</span>, <span class="n">114</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span></span><br />or
</p><div class="source-code snippet"><div class="inner"><pre><a href="http://www.allegro.cc/manual/ALLEGRO_COLOR"><span class="a">ALLEGRO_COLOR</span></a> col <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_map_rgb"><span class="a">al_map_rgb</span></a><span class="k2">(</span><span class="n">0</span>, <span class="n">255</span>, <span class="n">114</span><span class="k2">)</span><span class="k2">;</span>
YourFunction<span class="k2">(</span>col<span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

Definition:
</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">void</span> Yourfunction<span class="k2">(</span><a href="http://www.allegro.cc/manual/ALLEGRO_COLOR"><span class="a">ALLEGRO_COLOR</span></a> transparent_color<span class="k2">)</span>
<span class="k2">{</span>
...
<a href="http://www.allegro.cc/manual/al_convert_mask_to_alpha"><span class="a">al_convert_mask_to_alpha</span></a><span class="k2">(</span>bmp, transparent_color<span class="k2">)</span><span class="k2">;</span>
<span class="k2">}</span>
</pre></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Audric)</author>
		<pubDate>Tue, 30 Jun 2015 15:15:49 +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/615498/1014478#target">blakat</a> said:</div><div class="quote"><p> transparentPixal = al_map_rgb(0.0f, 255.0f, 114.0f);</p></div></div><p>You don&#39;t need to use floats, unless you use al_map_rgb_f() (in which case you use values from 0.0f to 1.0f). If you use al_map_rgb(), integers will do (ranging from 0 to 255).</p><p>Aside from that, nothing wrong with your code. It should work the way you posted it here. Is that the exact code from your game? Can you copy &amp; paste the snippet directly from your game?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (RPG Hacker)</author>
		<pubDate>Tue, 30 Jun 2015 16:16:05 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Line 56 and 57 are the ones of focus, transparentPixal is declared on line 20. This is just a test program, once test succeed i paste it&#39;s snippets into my game.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (blakat)</author>
		<pubDate>Tue, 30 Jun 2015 16:16:26 +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/615498/1014483#target">blakat</a> said:</div><div class="quote"><p> I&#39;m stumped 
</p></div></div><p>As I suggested:
</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/615498/1014482#target">RPG Hacker</a> said:</div><div class="quote"><p> Can you copy &amp; paste the snippet directly from your game?
</p></div></div></div>]]>
		</description>
		<author>no-reply@allegro.cc (RPG Hacker)</author>
		<pubDate>Tue, 30 Jun 2015 16:23:18 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Sorry i posted that without refreshing the page, I only saw Audric&#39;s message. That edited post has a file attachment.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (blakat)</author>
		<pubDate>Tue, 30 Jun 2015 16:26:05 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;m seeing nothing that strikes me as obviously wrong with your code. Are you sure that passing transparentPixal to the function doesn&#39;t work and passing al_map_rgb(0, 255, 114) to the function directly DOES work? That is the only thing that is puzzling me. I&#39;m not currently at my home computer, so I can&#39;t test the code myself. If you look at transparentPixal in your debugger after asigning the value to it, what does it say? And in case you have access to the Allegro source while debugging, if you step into the call</p><p><span class="source-code"><a href="http://www.allegro.cc/manual/al_convert_mask_to_alpha"><span class="a">al_convert_mask_to_alpha</span></a><span class="k2">(</span>bmp, <a href="http://www.allegro.cc/manual/al_map_rgb"><span class="a">al_map_rgb</span></a><span class="k2">(</span><span class="n">0</span>, <span class="n">255</span>, <span class="n">114</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span></span></p><p>What does the color argument say when looking at it in the debugger?</p><p>Also, what OS are you on, what version of Allegro are you using and which compiler did you compile this with?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (RPG Hacker)</author>
		<pubDate>Tue, 30 Jun 2015 16:41:35 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Edit: Here are the results of both calls.<br />I actually dont have a debugger, I&#39;m on ubuntu 14.04 (64 bit) allegro 5 and g++ as my compiler.<br />I&#39;ve never got into using debuggers, any way you could direct me to one?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (blakat)</author>
		<pubDate>Tue, 30 Jun 2015 16:43:50 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I don&#39;t have too much experience with Linux systems unfortunately, so maybe someone else can provide better help. In any case, two IDEs for Linux I know of are Eclipse and Code::Blocks. Just pick whichever IDE you like best. I haven&#39;t worked much with either of those, so I can&#39;t give any specific instructions on how to do it, but basically you&#39;ll want to find out how to set breakpoints and view the value of a variable. In many IDEs, both things are pretty straight-forward. For example, in Visual Studio you just click a line number to set a breakpoint and hover the mouse over a variable to view its value. I can imagine it&#39;s similar with the two aforementioned IDEs, but you&#39;ll have to find that out for yourself.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p> allegro 5</p></div></div><p>Yeah, I figured as much. But which specific version of Allegro 5? As in, Allegro 5.X.X?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (RPG Hacker)</author>
		<pubDate>Tue, 30 Jun 2015 17:26:41 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="source-code snippet"><div class="inner"><pre><span class="k1">int</span> main<span class="k2">(</span><span class="k1">int</span> argc, <span class="k1">char</span> <span class="k3">*</span><span class="k3">*</span>argv<span class="k2">)</span>
<span class="k2">{</span>
  <span class="k2">(</span>...<span class="k2">)</span>
  <a href="http://www.allegro.cc/manual/ALLEGRO_COLOR"><span class="a">ALLEGRO_COLOR</span></a> transparentPixal <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_map_rgb"><span class="a">al_map_rgb</span></a><span class="k2">(</span><span class="n">0</span>, <span class="n">255</span>, <span class="n">114</span><span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>
This calls al_map_rgb() before allegro and its graphic mode get initialized.<br />I wouldn&#39;t be surprized if the pixel format (RGB? BGR? etc) was modified in-between, which would result in a different color number.<br />If this is the issue, you can easily fix it by calling <span class="source-code">transparentPixal <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_map_rgb"><span class="a">al_map_rgb</span></a><span class="k2">(</span><span class="n">0</span>, <span class="n">255</span>, <span class="n">114</span><span class="k2">)</span><span class="k2">;</span></span> after the block where you perform al_create_display().
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Audric)</author>
		<pubDate>Tue, 30 Jun 2015 17:48:47 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Oh, well spotted! I totally overlooked that! al_map_rgb(a) seems to convert colors by taking its values from an array called &quot;_al_u8_to_float&quot; (using the integer color component value as an index). I can imagine that said array isn&#39;t initialized until either Allegro is installed or the graphics system is.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (RPG Hacker)</author>
		<pubDate>Tue, 30 Jun 2015 17:56:06 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>That was a complete duh moment, thanks guys for all the help, it works as I intend it to.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (blakat)</author>
		<pubDate>Tue, 30 Jun 2015 19:07:32 +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/615498/1014498#target">RPG Hacker</a> said:</div><div class="quote"><p>
I can imagine that said array isn&#39;t initialized until either Allegro is installed or the graphics system is. 
</p></div></div><p>
Yes, I can confirm that. The float variants will work without initialization, but converting from integers won&#39;t work without calling al_init().
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Polybios)</author>
		<pubDate>Tue, 30 Jun 2015 22:35:09 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>@Polybios<br />That bit me too, with my recent addition of constant color blending to Allegro.  I was initializing the blend color internally using al_map_rgba(), and it took me a while to realize what was wrong when the color wasn&#39;t set properly.</p><p>The reason, incidentally, is that Allegro uses a lookup table for the integer variants instead of calculating it directly (which would require 3-4 expensive FP divisions), and the tables aren&#39;t initialized until you call al_init().
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Bruce Pascoe)</author>
		<pubDate>Wed, 01 Jul 2015 06:45:36 +0000</pubDate>
	</item>
</rss>
