<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Alpha Transparency</title>
		<link>http://www.allegro.cc/forums/view/608387</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Mon, 19 Sep 2011 21:18:45 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hello again everyone, </p><p>I am noticing that alpha is not working the way I figured it would. It seems I cannot notice my alpha changes at all when my background is black. Doing a little searching, I discovered that it is probably due to the blending mode. Here is what I am doing:</p><p>at some point, the user will set the RGBA for a sprites color</p><div class="source-code snippet"><div class="inner"><pre><span class="c">//arbitrary example</span>
this-&gt;color <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_map_rgba"><span class="a">al_map_rgba</span></a><span class="k2">(</span><span class="n">255</span>, <span class="n">0</span>, <span class="n">0</span>, <span class="n">100</span><span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

later, in the draw method</p><div class="source-code snippet"><div class="inner"><pre><a href="http://www.allegro.cc/manual/al_draw_tinted_bitmap_region"><span class="a">al_draw_tinted_bitmap_region</span></a><span class="k2">(</span>this-&gt;image, this-&gt;color, etc...<span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

What do I need to do to get this to render with alpha in a straight forward manner?</p><p>Thank you
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (InfiniteLoop)</author>
		<pubDate>Mon, 19 Sep 2011 08:10: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/608387/931533#target">InfiniteLoop</a> said:</div><div class="quote"><p>It seems I cannot notice my alpha changes at all when my background is black.</p></div></div><p>

Which background? Do you mean black pixels in your bitmap? Your example should make them get drawn transparently already. Maybe you can post a screenshot of the bitmap and how it looks and how you want it to look instead.</p><p>Also in general you probably want to multiply the RGB components in your color with the alpha component when using the default blending mode: <span class="source-code">this-&gt;color <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_map_rgba"><span class="a">al_map_rgba</span></a><span class="k2">(</span><span class="n">255</span> <span class="k3">*</span> <span class="n">100</span> <span class="k3">/</span> <span class="n">255</span>, <span class="n">0</span>, <span class="n">0</span>, <span class="n">100</span><span class="k2">)</span><span class="k2">;</span></span> But it depends on what you want to do.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Mon, 19 Sep 2011 16:22:57 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>That background is black (as in clear_to_color(0, 0, 0)). My code would make my images appear transparent if there was anything behind them. One would imagine that a red block drawn at half opacity over a black background would appear much darker, but in my program, it appears bright red until something is drawn behind it.</p><p>Also, given the way I read in color and handle my function call, I do not have direct access to the alpha component (or any individual component). Instead, I just have an ALLEGRO_COLOR object. Not sure how to do what you are suggesting. </p><p>I cannot get you screenshots until tonight when I am home again. I am hoping someone can share some insight before then though.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (InfiniteLoop)</author>
		<pubDate>Mon, 19 Sep 2011 17:38:50 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Try something like this:
</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> premul_alpha<span class="k2">(</span><a href="http://www.allegro.cc/manual/ALLEGRO_COLOR"><span class="a">ALLEGRO_COLOR</span></a> color<span class="k2">)</span> <span class="k2">{</span>
    <span class="k1">float</span> r, g, b, a<span class="k2">;</span>
    <a href="http://www.allegro.cc/manual/al_unmap_rgba_f"><span class="a">al_unmap_rgba_f</span></a><span class="k2">(</span>color, <span class="k3">&amp;</span>r, <span class="k3">&amp;</span>g, <span class="k3">&amp;</span>b, <span class="k3">&amp;</span>a<span class="k2">)</span><span class="k2">;</span>
    <span class="k1">return</span> <a href="http://www.allegro.cc/manual/al_map_rgba_f"><span class="a">al_map_rgba_f</span></a><span class="k2">(</span>r <span class="k3">*</span> a, g <span class="k3">*</span> a, b <span class="k3">*</span> a, a<span class="k2">)</span><span class="k2">;</span>
<span class="k2">}</span>
</pre></div></div><p>

and then draw like this:</p><div class="source-code snippet"><div class="inner"><pre><a href="http://www.allegro.cc/manual/al_draw_tinted_bitmap"><span class="a">al_draw_tinted_bitmap</span></a><span class="k2">(</span>bitmap, premul_alpha<span class="k2">(</span>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 (Elias)</author>
		<pubDate>Mon, 19 Sep 2011 18:20:56 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Thank you, I will give this a whirl when I get home. While I wait, why is it I have to do this? Is this a feature?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (InfiniteLoop)</author>
		<pubDate>Mon, 19 Sep 2011 18:28:25 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>The default blending mode is <span class="source-code"><a href="http://www.allegro.cc/manual/al_set_blender"><span class="a">al_set_blender</span></a><span class="k2">(</span>ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_INVERSE_ALPHA<span class="k2">)</span></span> - so basically the source RGB is added to the RGB already on the target. Therefore to get transparency you need to multiply it first.</p><p>ex_premul_alpha should explain why this is the default blending mode.</p><p>And al_map_rgba does not do the multiplication because it probably would be confusing.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Mon, 19 Sep 2011 19:15:49 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Excellent. That answer is exactly what I was looking for. </p><p>Thank you</p><p>EDIT:<br />This worked. Thank you.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (InfiniteLoop)</author>
		<pubDate>Mon, 19 Sep 2011 21:18:45 +0000</pubDate>
	</item>
</rss>
