<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>How to draw pixels of bitmaps transparently upon collision</title>
		<link>http://www.allegro.cc/forums/view/617144</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Tue, 21 Nov 2017 13:16:46 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Making a game and attempting to create a light system with torches on a 2d rpg platformer and want to mask out pixels of a black allegro_bitmap wondering if yall know how its done or a similar method to achieve that effect</p><p>maybe changing the alpha channel on specific pixels could work but dont know the syntax to do that also dont know how costly that would be preciate your help
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Travis Peterson)</author>
		<pubDate>Tue, 21 Nov 2017 02:16:36 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;m gonna need some more details on what you&#39;re trying to do, and how you&#39;re thinking of implementing it.</p><p>Can you throw up a screenshot of a game with a similar effect?</p><p> - Are you trying for lightmaps (most likely?), or polygonal lighting?</p><p>Usually with lightmaps you just set the blending function to the correct one, and (IIRC) draw the light map on top of it. (IIRC) Or start with a full-screen black, draw your lightmaps onto it, and then merge that with the non-lit version at once. (Sorry, it&#39;s been years since I had to do this so my mind is a bit hazy.)</p><p>And you mention collision, and pixels. Are you making a TILE map game, or a PIXEL/bitmap game?</p><p>For lightmaps, you do the above, they&#39;re just &quot;lit&quot; bitmaps using known light patterns like a circle. </p><p>For polygonal lighting, you again draw to a &quot;shadow buffer&quot; or &quot;light buffer&quot; the size of your screen and merge in, but for &quot;collisions&quot; you&#39;re actually sending out rays from your light-sources and marking any spots they cover/hit.</p><p>There&#39;s tons of lighting tutorials for various game libraries on the internet. Try googling &quot;light maps 2d tutorial.&quot; If you can identify the type of lighting you&#39;re looking for, we can drill down more into the details of how to implement it. But right now, there&#39;s &quot;a thousand ways to skin a cat&quot; so the best/easiest way to implement it depends on <i>what</i> specifically you&#39;re looking to implement.</p><p>Here&#39;s some example quick googles:</p><p><a href="http://frankforce.com/?p=2614">http://frankforce.com/?p=2614</a></p><p><a href="http://ncase.me/sight-and-light/">http://ncase.me/sight-and-light/</a></p><p>Here&#39;s polygonal: (and you can fuzz/blur it to make it look softer)</p><p><span class="remote-thumbnail"><span class="json">{"name":"kFJyu.jpg","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/f\/1\/f1db1ffbb5a3ce36a75c004de535bb44.jpg","w":1280,"h":720,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/f\/1\/f1db1ffbb5a3ce36a75c004de535bb44"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/f/1/f1db1ffbb5a3ce36a75c004de535bb44-240.jpg" alt="kFJyu.jpg" width="240" height="135" /></span></p><p>Here&#39;s a lightmap (just lightmaps):</p><p><span class="remote-thumbnail"><span class="json">{"name":"3.jpg","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/b\/c\/bc0c03bbd3b14b947881c49b36313914.jpg","w":1021,"h":1025,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/b\/c\/bc0c03bbd3b14b947881c49b36313914"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/b/c/bc0c03bbd3b14b947881c49b36313914-240.jpg" alt="3.jpg" width="240" height="240" /></span></p><p>Here&#39;s a lightmap:</p><p><span class="remote-thumbnail"><span class="json">{"name":"2JEvm.jpg","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/e\/c\/ec6bfd7ba7e526bfa98113ae6c431fd3.jpg","w":1920,"h":1080,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/e\/c\/ec6bfd7ba7e526bfa98113ae6c431fd3"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/e/c/ec6bfd7ba7e526bfa98113ae6c431fd3-240.jpg" alt="2JEvm.jpg" width="240" height="135" /></span></p><p>Notice how the lights are all &quot;the same.&quot; They don&#39;t have to be, you can vary size, intensity, etc. But the key here is they&#39;re not polygonal. They&#39;re not &quot;rays&quot; sent out from a lightsource that collide. Which means you can run into artifacts where they don&#39;t get clipped by walls (unless you specifically add that check). </p><p>But there are no hard-and-fast rules. Lightmaps can be made more &quot;collision aware&quot; and vertex lighting can be made more like lightmaps. Again, it really depends on what you&#39;re looking for.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Chris Katko)</author>
		<pubDate>Tue, 21 Nov 2017 02:38:32 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Understand the logistics of what youre saying bout lightmaps and blenders but dont know the code to get started could you post a basic lightmap programs code</p><p>Ideally looking to light up circles on a black rectangle dark region with some of the light circles obstructed at certain walls <br />but just making a circle light system similar to your 3rd pic would be cool for now if thats too much<br />Btw its really cool how fast and knowledgable you guys are in this community
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Travis Peterson)</author>
		<pubDate>Tue, 21 Nov 2017 03:11:27 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Well in that case what you want to do is draw a shadow map, and you do that by drawing lights on shadow.</p><p>Draw a background buffer bitmap of RGBA(0,0,0,255) using a full copy blender.<br />Draw lights of RGBA(0,0,0,255-light) using an additive alpha blender. See <a href="http://liballeg.org/a5docs/trunk/graphics.html#al_set_separate_blender">al_set_separate_blender</a> and <a href="http://liballeg.org/a5docs/trunk/graphics.html#al_set_blender">al_set_blender</a> for details.</p><p>Then once you&#39;re done drawing your shadow map, you draw the shadows over your screen with an alpha blender.</p><p>EDIT<br />To draw a nice gradient alpha circle like above in Chris&#39; example, you can draw from radius to zero number of circles with varying alpha to make a gradient.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Tue, 21 Nov 2017 03:58:16 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>To get the (lightmap) shadows clipped, the easiest way would be to draw all your solid pieces INTO the shadow buffer and remove the lighting THEN merge the shadow buffer in like normal. </p><p>So you have this black buffer. You draw your lights onto it. Then you REMOVE those lights at places where there is a solid wall, by drawing black on those spaces (even just draw the same tile, into the shadow buffer, with a color set to black so transparent pixels don&#39;t get drawn.) </p><p>Now there&#39;s a caveat with that easiest method. If your lights are &quot;bigger&quot; than one tile (or is it 3x3?), the lights will be filled in by those black parts correctly, but beyond them won&#39;t be clipped. If your world has large blocks of &quot;filled&quot; tiles, then you&#39;ll be fine. If your world has many thin strips of solid walls with very large lights, then the lighting will just shoot passed them.</p><p>I can take a moment and draw a diagram if that&#39;s helpful...</p><p>[edit] Here we go.</p><p><span class="remote-thumbnail"><span class="json">{"name":"zLqNXf0.png","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/c\/a\/cab18b04db3ad7c890a27c37b91500bc.png","w":1382,"h":1824,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/c\/a\/cab18b04db3ad7c890a27c37b91500bc"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/c/a/cab18b04db3ad7c890a27c37b91500bc-240.jpg" alt="zLqNXf0.png" width="240" height="316" /></span></p><p>[edit] fixed typo
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Chris Katko)</author>
		<pubDate>Tue, 21 Nov 2017 04:30:43 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>So would the code be:</p><p>ALLEGRO_IMAGE *shadebackground;<br />shadebackground = al_load_bitmap(&quot;image.png&quot;);<br />al_set_separate_blender(shadebackground); al_set_blender(shadebackground);
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Travis Peterson)</author>
		<pubDate>Tue, 21 Nov 2017 05:01:17 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Nope. Try reading the manual like I linked to.</p><p>If you have a shadow map premade, you can draw it with :
</p><div class="source-code snippet"><div class="inner"><pre><a href="http://www.allegro.cc/manual/ALLEGRO_BITMAP"><span class="a">ALLEGRO_BITMAP</span></a><span class="k3">*</span> shadows <span class="k3">=</span> ...<span class="k2">;</span>

<a href="http://www.allegro.cc/manual/al_draw_bitmap"><span class="a">al_draw_bitmap</span></a><span class="k2">(</span>background , <span class="n">0</span> , <span class="n">0</span><span class="k2">)</span><span class="k2">;</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_ALHPA , ALLEGRO_INVERSE_ALPHA<span class="k2">)</span><span class="k2">;</span>

<a href="http://www.allegro.cc/manual/al_draw_bitmap"><span class="a">al_draw_bitmap</span></a><span class="k2">(</span>shadows , <span class="n">0</span> , <span class="n">0</span><span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

If you want to draw light on your shadow map :
</p><div class="source-code snippet"><div class="inner"><pre><a href="http://www.allegro.cc/manual/ALLEGRO_BITMAP"><span class="a">ALLEGRO_BITMAP</span></a><span class="k3">*</span> shadows <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>buffer-&gt;W<span class="k2">(</span><span class="k2">)</span> , buffer-&gt;H<span class="k2">(</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<a href="http://www.allegro.cc/manual/al_clear_to_color"><span class="a">al_clear_to_color</span></a><span class="k2">(</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">0</span>,<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="k2">;</span>
<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_ONE , ALLEGRO_ZERO , ALLEGRO_ADD , ALLEGRO_ONE , ALLEGRO_ZERO<span class="k2">)</span><span class="k2">;</span>
<a href="http://www.allegro.cc/manual/al_draw_circle"><span class="a">al_draw_circle</span></a><span class="k2">(</span>buffer-&gt;W<span class="k2">(</span><span class="k2">)</span><span class="k3">/</span><span class="n">2</span> , buffer-&gt;H<span class="k2">(</span><span class="k2">)</span><span class="k3">/</span><span class="n">2</span> , buffer-&gt;W<span class="k2">(</span><span class="k2">)</span><span class="k3">/</span><span class="n">2</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">0</span>,<span class="n">0</span>,<span class="n">0</span>,light <span class="k3">-</span> <span class="n">255</span><span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

And when you&#39;re done, reset the normal blender :
</p><div class="source-code snippet"><div class="inner"><pre><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 class="k2">;</span>
</pre></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Tue, 21 Nov 2017 13:16:46 +0000</pubDate>
	</item>
</rss>
