<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Mask / combine bitmaps</title>
		<link>http://www.allegro.cc/forums/view/616245</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Sat, 14 May 2016 07:40:45 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Is there a function in Allegro that allows me to &quot;mask&quot; or combine two bitmaps? For example, if I have a bitmap with an image of a black star on a transparent background, is there a way to mix that with a picture of some water to make a &quot;water star&quot;? So that the black area on the star is preserved to look like water and the surrounding transparent part is just left as transparent.</p><p>(That&#39;s just an example, it doesn&#39;t matter to me if the mask uses black, white, transparency, or whatever.)</p><p>For more information about what I&#39;m doing specifically: I&#39;m working on a game where you use colored stars to clear colored blocks (see screenshot). And I&#39;m tired of creating stars and blocks of different colors and animated in different ways. So instead, I&#39;d like to create just a couple of &quot;block masks&quot; and &quot;star masks&quot; and then a few dozen &quot;textures&quot; that can be generated in game (at startup) as star and blocks.</p><p>EDIT: I think I&#39;m making progress! Something like this, right?
</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/ALLEGRO_STATE"><span class="a">ALLEGRO_STATE</span></a> state<span class="k2">;</span>
<span class="number">  2</span>
<span class="number">  3</span><a href="http://www.allegro.cc/manual/al_store_state"><span class="a">al_store_state</span></a><span class="k2">(</span><span class="k3">&amp;</span>state, ALLEGRO_STATE_TARGET_BITMAP <span class="k3">|</span> ALLEGRO_STATE_BLENDER<span class="k2">)</span><span class="k2">;</span>
<span class="number">  4</span>
<span class="number">  5</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>bmp_mask<span class="k2">)</span><span class="k2">;</span>
<span class="number">  6</span><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_ONE<span class="k2">)</span><span class="k2">;</span>
<span class="number">  7</span><a href="http://www.allegro.cc/manual/al_draw_bitmap"><span class="a">al_draw_bitmap</span></a><span class="k2">(</span>bmp_texture, <span class="n">0</span>, <span class="n">0</span>, <span class="n">0</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  8</span>
<span class="number">  9</span><a href="http://www.allegro.cc/manual/al_restore_state"><span class="a">al_restore_state</span></a><span class="k2">(</span><span class="k3">&amp;</span>state<span class="k2">)</span><span class="k2">;</span>
</div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (David Couzelis)</author>
		<pubDate>Sat, 07 May 2016 20:19:54 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Shaders can do it. Without shaders, you could clone your water bitmap and then the star bitmap onto it with a blender that only draws the alpha channel, something like this:</p><div class="source-code snippet"><div class="inner"><pre><a href="http://www.allegro.cc/manual/al_set_separate_blender"><span class="a">al_set_separate_blender</span></a><span class="k2">(</span>ALLEGRO_ADD, ALLEGRO_ZERO, ALLEGRO_ONE, ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ZERO<span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

The resultant bitmap will have colors from your water bitmap, but alpha from your star bitmap.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SiegeLord)</author>
		<pubDate>Sun, 08 May 2016 03:47:09 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hm, that&#39;s a neat trick, SiegeLord.  I was looking for a way to implement a &quot;Complex&quot; primitive (basically a filled circle cut out of a rectangle, the circle is transparent), using the separate blenders seems like a good starting point.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Bruce Pascoe)</author>
		<pubDate>Sun, 08 May 2016 08:35:41 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Thank you for your ideas. I still have a few questions...</p><p>So, I&#39;m able to get a proper cutout, in the shape I need. So, alpha is all set.</p><p>Next, I can use <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_ONE<span class="k2">)</span><span class="k2">;</span></span> to lighten up part of the bitmap (by blending it with some light gray).</p><p>But, how can I darken part of the image, to add some shading??</p><p>It seems like no matter what parameters I set the blender to it always just lightens it up...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (David Couzelis)</author>
		<pubDate>Sat, 14 May 2016 07:40:45 +0000</pubDate>
	</item>
</rss>
