<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Can&#39;t make bitmap tinted</title>
		<link>http://www.allegro.cc/forums/view/615156</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Tue, 03 Mar 2015 10:55:55 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I have a freeze gun in my game, and I would like enemies that are frozen to be tinted light blue. I can&#39;t get it to work though. Nothing I try makes them blue. Frozen amount is just how many times they were hit by a freezing bullet. So it could be anywhere from 0 to like 20. Here is one of my attempts at getting it to work.
</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_BITMAP"><span class="a">ALLEGRO_BITMAP</span></a> <span class="k3">*</span>buffer2 <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_create_bitmap"><span class="a">al_create_bitmap</span></a><span class="k2">(</span><span class="n">128</span>, <span class="n">128</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 2</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>buffer2<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 3</span><a href="http://www.allegro.cc/manual/al_draw_rotated_bitmap"><span class="a">al_draw_rotated_bitmap</span></a><span class="k2">(</span>buffer, enemies<span class="k2">[</span>i<span class="k2">]</span>.radius, enemies<span class="k2">[</span>i<span class="k2">]</span>.radius, enemies<span class="k2">[</span>i<span class="k2">]</span>.radius, enemies<span class="k2">[</span>i<span class="k2">]</span>.radius, enemies<span class="k2">[</span>i<span class="k2">]</span>.dir, NULL<span class="k2">)</span><span class="k2">;</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><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"> 5</span><a href="http://www.allegro.cc/manual/al_draw_tinted_bitmap"><span class="a">al_draw_tinted_bitmap</span></a><span class="k2">(</span>buffer2, <a href="http://www.allegro.cc/manual/al_map_rgb"><span class="a">al_map_rgb</span></a><span class="k2">(</span><span class="k2">(</span><span class="k1">int</span><span class="k2">(</span>enemies<span class="k2">[</span>i<span class="k2">]</span>.frozenAmount<span class="k2">)</span> <span class="k3">*</span> <span class="n">10</span><span class="k2">)</span>, <span class="n">0</span>, <span class="k2">(</span><span class="k1">int</span><span class="k2">(</span>enemies<span class="k2">[</span>i<span class="k2">]</span>.frozenAmount<span class="k2">)</span> <span class="k3">*</span> <span class="n">10</span><span class="k2">)</span><span class="k2">)</span>, enemies<span class="k2">[</span>i<span class="k2">]</span>.x <span class="k3">-</span> enemies<span class="k2">[</span>i<span class="k2">]</span>.radius, enemies<span class="k2">[</span>i<span class="k2">]</span>.y <span class="k3">-</span> enemies<span class="k2">[</span>i<span class="k2">]</span>.radius, <span class="n">0</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 6</span><a href="http://www.allegro.cc/manual/al_destroy_bitmap"><span class="a">al_destroy_bitmap</span></a><span class="k2">(</span>buffer<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 7</span><a href="http://www.allegro.cc/manual/al_destroy_bitmap"><span class="a">al_destroy_bitmap</span></a><span class="k2">(</span>buffer2<span class="k2">)</span><span class="k2">;</span>
</div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Bingocat)</author>
		<pubDate>Mon, 02 Mar 2015 06:28:10 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="https://www.allegro.cc/manual/5/al_draw_tinted_bitmap">al_draw_tinted_bitmap</a> said:</div><div class="quote"><p>
Like al_draw_bitmap but multiplies all colors in the bitmap with the given color. For example:
</p></div></div><p>
Since it multiplies colors, it can only get darker. This is why you can&#39;t get a light blue color from using al_draw_tinted_bitmap.</p><p>You can either draw a light blue mask over your enemies, or you can pre-draw them light blue and then just draw those instead.</p><p>We need a different draw_tinted_bitmap that blends the tint color with the source pixels.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Mon, 02 Mar 2015 07:03:06 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>What about al_set_blender()? Is there any way to do it with that?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Bingocat)</author>
		<pubDate>Mon, 02 Mar 2015 07:14:51 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p><span class="source-code"><a href="http://www.allegro.cc/manual/al_set_blender"><span class="a">al_set_blender</span></a></span><br /><span class="source-code"><a href="http://www.allegro.cc/manual/al_set_separate_blender"><span class="a">al_set_separate_blender</span></a></span></p><p>No, neither of those really help you draw something lighter, unless you use additive blending, but that&#39;s not the same as tinting. You probably need a shader to do this without having some other kind of intermediate bitmap, such as a mask.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Mon, 02 Mar 2015 08:51:41 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>First of all, I wouldn&#39;t use buffers, I&#39;d render directly to the screen using al_draw_tinted_rotated_bitmap.</p><p>Secondly,the color mapping is wrong for a bluish tint. Ignoring rotation, I&#39;d go for this: 
</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><span class="k1">float</span> frost <span class="k3">=</span> <span class="k2">(</span><span class="k1">float</span><span class="k2">(</span>enemies<span class="k2">[</span>i<span class="k2">]</span>.frozenAmount<span class="k2">)</span><span class="k3">/</span> <span class="n">20</span>.<span class="n">0f</span><span class="k2">)</span> <span class="k3">*</span> <span class="n">0</span>.<span class="n">5f</span><span class="k2">;</span>
<span class="number"> 2</span><a href="http://www.allegro.cc/manual/al_draw_tinted_bitmap"><span class="a">al_draw_tinted_bitmap</span></a><span class="k2">(</span>sprite, <a href="http://www.allegro.cc/manual/al_map_rgba_f"><span class="a">al_map_rgba_f</span></a><span class="k2">(</span><span class="n">1</span>.<span class="n">0f</span> <span class="k3">-</span> frost, <span class="n">1</span>.<span class="n">0f</span> <span class="k3">-</span> frost, <span class="n">1</span>.<span class="n">0f</span>, <span class="n">1</span>.<span class="n">0f</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
</div></div><p>

It won&#39;t quite become <i>light</i> blue, but it should become blue nevertheless, since the r and g components are lowered progressively.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (beoran)</author>
		<pubDate>Mon, 02 Mar 2015 13:13:48 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Oh I had no idea there was an al_draw_tinted_rotated_bitmap(), but again adding the blue color to it just makes the bitmap look darker...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Bingocat)</author>
		<pubDate>Tue, 03 Mar 2015 10:37:15 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Like I said, it multiplies the two values together and then divides by 255, which is the same as multiplying by a fraction if you use floats, so it just gets darker. You could use additive blending, but that tends to white out large portions of the image.</p><p>It should be a fairly simple thing to make a function that creates a mask for your sprite. </p><p>Algorithm :<br />1. Create a mask bitmap the same size as your sprite.<br />2. Clear the mask bitmap to light blue zero alpha.<br />3. Draw the alpha layer of the mask bitmap. Look at the src bitmap and wherever it has alpha 0, you want alpha 0 on your mask bitmap (which you can get by leaving that pixel alone). Wherever it has non-zero alpha, you want to set the alpha to the percent they are frozen.<br />4. When you draw your sprite, draw the mask over the top of it using normal alpha blending (not the same as the default blending, which is pre-multiplied alpha).<br />5. Draw the sprite and the mask to a buffer to cache resulting bitmaps.</p><p>It would be hard to do dynamic freeze levels this way, but it would get you the effect you are looking for, tinting your sprite.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Tue, 03 Mar 2015 10:55:55 +0000</pubDate>
	</item>
</rss>
