<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Lighting and Allegro 5</title>
		<link>http://www.allegro.cc/forums/view/607967</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Sun, 07 Aug 2011 07:29:58 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I was looking at the Allegro 5 examples, some of which are very sexy, and I thought it would be cool to add a &#39;headlights&#39; effect to my game like so:</p><p><span class="remote-thumbnail"><span class="json">{"name":"one_headlight.png","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/3\/4\/343d78b66f23dbb6f3ccf7e52c2c93cd.png","w":641,"h":364,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/3\/4\/343d78b66f23dbb6f3ccf7e52c2c93cd"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/3/4/343d78b66f23dbb6f3ccf7e52c2c93cd-240.jpg" alt="one_headlight.png" width="240" height="136" /></span></p><p>Can it be done with Allegro, or would it require OpenGL? I&#39;d like the light to be as realistic as possible.</p><p>Also, would it be possible to use Allegro for the drawing, and OpenGL only for the lighting? Or, once you use OpenGL, do you have to use it for everything?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Myrdos)</author>
		<pubDate>Thu, 28 Jul 2011 22:44:46 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>If you just want to do what&#39;s in the screenshot, you can do that easily with primitives and blending. I don&#39;t know how realistic you want to go though... you can mix opengl and allegro calls no problem as long as you don&#39;t mess up opengl state and you know how allegro is affecting opengl state as well.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Trent Gamblin)</author>
		<pubDate>Thu, 28 Jul 2011 23:11:19 +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/607967/926305#target">Trent Gamblin</a> said:</div><div class="quote"><p> I don&#39;t know how realistic you want to go though...</p></div></div><p>Well, I&#39;d like to have the light fade with distance. The only blending function I see is &quot;al_set_blender&quot;. Would I have to set the blending function for every pixel in software, depending on how far the pixel is from light source(s)?</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p> as long as you don&#39;t mess up opengl state and you know how allegro is affecting opengl state as well</p></div></div><p>Sounds tricky, but doable.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Myrdos)</author>
		<pubDate>Thu, 28 Jul 2011 23:48:12 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Fading with distance shouldn&#39;t be a big problem if the light is a constant shape. You could have a bitmap that is a white triangle/trapezoid that fade from full alpha (or whatever you want) down to no alpha to the end. Then draw that with additive blending, maybe draw it more than once for a better effect. al_set_blender is all you need. You can achieve an additive blender with al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ONE).
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Trent Gamblin)</author>
		<pubDate>Fri, 29 Jul 2011 00:43:16 +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/607967/926320#target">Trent Gamblin</a> said:</div><div class="quote"><p> You could have a bitmap that is a white triangle/trapezoid that fade from full alpha (or whatever you want) down to no alpha to the end.</p></div></div><p>I like that! I think it might even be possible to add shadowing by blitting the terrain in front of the car onto the &#39;light triangle&#39;, such that the terrain areas have zero alpha.</p><p>Hmm... I could even pre-process my terrain so that the edges of the terrain are illuminated, but the interior remains dark.</p><p><span class="remote-thumbnail"><span class="json">{"name":"another_headlight.png","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/f\/a\/fa2c531a2279ea9733927c783005c6cf.png","w":530,"h":322,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/f\/a\/fa2c531a2279ea9733927c783005c6cf"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/f/a/fa2c531a2279ea9733927c783005c6cf-240.jpg" alt="another_headlight.png" width="240" height="145" /></span></p><p>[EDIT] Oops, forgot to ask: Why would applying the light triangle multiple times improve the results?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Myrdos)</author>
		<pubDate>Fri, 29 Jul 2011 02:18:17 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>The only reason it might help is to make it brighter. You could also draw it with less or more alpha, even modifying them in real time so that it looks like it&#39;s &quot;glowing&quot;. I don&#39;t recall what sort of transparency you&#39;ll see if you have say full alpha and draw additively... that&#39;s why I suggested drawing more than once. If it&#39;s 100% white at that point then drawing again wouldn&#39;t help but if was 50% you could get a brighter light by drawing more than once.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Trent Gamblin)</author>
		<pubDate>Fri, 29 Jul 2011 04:48:03 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I guess I&#39;ll experiment with it and see what it looks like.</p><p>Thanks for all the help!</p><p>[EDIT] Hmmm... no way to give cookies. <img src="http://www.allegro.cc/forums/smileys/undecided.gif" alt=":-/" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Myrdos)</author>
		<pubDate>Fri, 29 Jul 2011 21:38:24 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>That&#39;s ok, I need to watch my weight anyway <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" />.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Trent Gamblin)</author>
		<pubDate>Fri, 29 Jul 2011 21:51:22 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>It shouldn&#39;t brighten the area behind the hill as dramatically as your screenshot shows, although it may not really matter much in the context of the game.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Matthew Leverton)</author>
		<pubDate>Fri, 29 Jul 2011 22:08:07 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>See the last image in the thread. He plans to draw the &quot;scenery&quot; back over top of the light except for an edge which I think will work ok.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Trent Gamblin)</author>
		<pubDate>Fri, 29 Jul 2011 22:26:44 +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/607967/926385#target">Matthew Leverton</a> said:</div><div class="quote"><p> It shouldn&#39;t brighten the area behind the hill as dramatically as your screenshot shows, although it may not really matter much in the context of the game.</p></div></div><p>I know, if you can think of a way to add shadows I&#39;d be interested...</p><p>My attempt at a light so far has been of limited success:</p><p><span class="remote-thumbnail"><span class="json">{"name":"light1.png","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/5\/f\/5f1f05301f61f01d14e87401ebf8faf2.png","w":648,"h":485,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/5\/f\/5f1f05301f61f01d14e87401ebf8faf2"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/5/f/5f1f05301f61f01d14e87401ebf8faf2-240.jpg" alt="light1.png" width="240" height="179" /></span></p><p>It&#39;s creating a kind of &#39;fog&#39; effect, rather than illuminating anything. I&#39;m drawing it like so:</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_ONE<span class="k2">)</span><span class="k2">;</span>
         <a href="http://www.allegro.cc/manual/al_draw_scaled_bitmap"><span class="a">al_draw_scaled_bitmap</span></a><span class="k2">(</span>spotlight, <span class="n">0</span>, <span class="n">0</span>,
                               <a href="http://www.allegro.cc/manual/al_get_bitmap_width"><span class="a">al_get_bitmap_width</span></a><span class="k2">(</span>spotlight<span class="k2">)</span>, <a href="http://www.allegro.cc/manual/al_get_bitmap_height"><span class="a">al_get_bitmap_height</span></a><span class="k2">(</span>spotlight<span class="k2">)</span>,
                               <span class="n">50</span>, <span class="n">60</span>,
                               <a href="http://www.allegro.cc/manual/al_get_bitmap_width"><span class="a">al_get_bitmap_width</span></a><span class="k2">(</span>spotlight<span class="k2">)</span> <span class="k3">*</span> <span class="n">2</span>, <a href="http://www.allegro.cc/manual/al_get_bitmap_height"><span class="a">al_get_bitmap_height</span></a><span class="k2">(</span>spotlight<span class="k2">)</span> <span class="k3">*</span> <span class="n">2</span>,
                               <span class="n">0</span><span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

The spotlight bitmap is made of white pixels with varying amounts of alpha. Any ideas on how to improve this?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Myrdos)</author>
		<pubDate>Tue, 02 Aug 2011 07:35:09 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>What would really improve it is if you can somehow get the background image into a trapezoid and draw that with additive blending... I&#39;m not sure how you&#39;d do that without shaders except using the stencil buffer. Both are kind of &quot;exotic&quot;. To do it with the stencil buffer you&#39;d have a stencil the shape of the trapezoid and a translucent-&gt;black version of the trapezoid. You would draw from the display (or if that turns out to be too slow, you could have an intermediate buffer) to a bitmap with the stencil on so only the trapezoid gets drawn (the rest would be pure alpha or black) and then draw the black/alpha bitmap over that before drawing it with additive blending.</p><p>EDIT:<br />Scratch that, you could use have extra black in the black/alpha image wherever the trapezoid doesn&#39;t touch. So no need for stencil or anything exotic.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Trent Gamblin)</author>
		<pubDate>Tue, 02 Aug 2011 07:43:36 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hint: Lightmaps don&#39;t actually lighten pixels, they <i>darken</i> them.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (gnolam)</author>
		<pubDate>Tue, 02 Aug 2011 07:49:56 +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/607967/926811#target">gnolam</a> said:</div><div class="quote"><p> Hint: Lightmaps don&#39;t actually lighten pixels, they darken them.</p></div></div><p>So... I should selectively darken the terrain, except where the light is. Makes sense...</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607967/926809#target">Trent Gamblin</a> said:</div><div class="quote"><p> Scratch that, you could use have extra black in the black/alpha image wherever the trapezoid doesn&#39;t touch. So no need for stencil or anything exotic.</p></div></div><p>I not sure if I completely follow you here, but is that similar to what I have now? The parts of the spotlight that aren&#39;t &#39;light&#39; are black with 0 alpha.</p><p>Let me run this past you:</p><p>1) I fill the back buffer with black.</p><p>2) I draw my terrain to a bitmap, using 80% transparency.</p><p>3) I draw the light to the bitmap, but use blending such that the alpha value of the light pixels are added to the terrain, but not the colors.</p><p>4) I blit the result to the back buffer</p><p>Is that type of blending possible?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Myrdos)</author>
		<pubDate>Tue, 02 Aug 2011 07:56:57 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p><span class="remote-thumbnail"><span class="json">{"name":"604620","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/8\/4\/842ef10cbe84998c0a06ce138a69313f.png","w":646,"h":430,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/8\/4\/842ef10cbe84998c0a06ce138a69313f"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/8/4/842ef10cbe84998c0a06ce138a69313f-240.jpg" alt="604620" width="240" height="159" /></span></p><p>That&#39;s what I got with what I said above. Easier for me to post code than to describe it. The image I used is also attached.</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="p">#include &lt;allegro5/allegro.h&gt;</span>
<span class="number">  2</span><span class="p">#include &lt;allegro5/allegro_image.h&gt;</span>
<span class="number">  3</span>
<span class="number">  4</span><span class="k1">int</span> main<span class="k2">(</span><span class="k1">void</span><span class="k2">)</span>
<span class="number">  5</span><span class="k2">{</span>
<span class="number">  6</span>  <a href="http://www.allegro.cc/manual/al_init"><span class="a">al_init</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  7</span>  <a href="http://www.allegro.cc/manual/al_init_image_addon"><span class="a">al_init_image_addon</span></a><span class="k2">(</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/ALLEGRO_DISPLAY"><span class="a">ALLEGRO_DISPLAY</span></a> <span class="k3">*</span>display <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_create_display"><span class="a">al_create_display</span></a><span class="k2">(</span><span class="n">640</span>, <span class="n">400</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 10</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_rgb_f"><span class="a">al_map_rgb_f</span></a><span class="k2">(</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>
<span class="number"> 11</span>
<span class="number"> 12</span>  <a href="http://www.allegro.cc/manual/ALLEGRO_BITMAP"><span class="a">ALLEGRO_BITMAP</span></a> <span class="k3">*</span>allegro <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_load_bitmap"><span class="a">al_load_bitmap</span></a><span class="k2">(</span><span class="s">"allegro.pcx"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 13</span>  <a href="http://www.allegro.cc/manual/ALLEGRO_BITMAP"><span class="a">ALLEGRO_BITMAP</span></a> <span class="k3">*</span>trap <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_load_bitmap"><span class="a">al_load_bitmap</span></a><span class="k2">(</span><span class="s">"trap.png"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 14</span>  <a href="http://www.allegro.cc/manual/ALLEGRO_BITMAP"><span class="a">ALLEGRO_BITMAP</span></a> <span class="k3">*</span>buf <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">640</span>, <span class="n">400</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 15</span>  <a href="http://www.allegro.cc/manual/ALLEGRO_BITMAP"><span class="a">ALLEGRO_BITMAP</span></a> <span class="k3">*</span>tmp <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">320</span>, <span class="n">200</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 16</span>  
<span class="number"> 17</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>buf<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 18</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_f"><span class="a">al_map_rgba_f</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>
<span class="number"> 19</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>allegro, <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">0</span>.<span class="n">2</span>, <span class="n">0</span>.<span class="n">2</span>, <span class="n">0</span>.<span class="n">2</span>, <span class="n">1</span>.<span class="n">0</span><span class="k2">)</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="number"> 20</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>allegro, <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">0</span>.<span class="n">2</span>, <span class="n">0</span>.<span class="n">2</span>, <span class="n">0</span>.<span class="n">2</span>, <span class="n">1</span>.<span class="n">0</span><span class="k2">)</span>, <span class="n">320</span>, <span class="n">0</span>, <span class="n">0</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 21</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>allegro, <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">0</span>.<span class="n">2</span>, <span class="n">0</span>.<span class="n">2</span>, <span class="n">0</span>.<span class="n">2</span>, <span class="n">1</span>.<span class="n">0</span><span class="k2">)</span>, <span class="n">0</span>, <span class="n">200</span>, <span class="n">0</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 22</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>allegro, <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">0</span>.<span class="n">2</span>, <span class="n">0</span>.<span class="n">2</span>, <span class="n">0</span>.<span class="n">2</span>, <span class="n">1</span>.<span class="n">0</span><span class="k2">)</span>, <span class="n">320</span>, <span class="n">200</span>, <span class="n">0</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 23</span>  
<span class="number"> 24</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>tmp<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 25</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_f"><span class="a">al_map_rgba_f</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>
<span class="number"> 26</span>  <a href="http://www.allegro.cc/manual/al_draw_bitmap_region"><span class="a">al_draw_bitmap_region</span></a><span class="k2">(</span>buf, <span class="n">160</span>, <span class="n">100</span>, <span class="n">320</span>, <span class="n">200</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="number"> 27</span>  <a href="http://www.allegro.cc/manual/al_draw_bitmap"><span class="a">al_draw_bitmap</span></a><span class="k2">(</span>trap, <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"> 28</span>
<span class="number"> 29</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>buf<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 30</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"> 31</span>  <a href="http://www.allegro.cc/manual/al_draw_bitmap"><span class="a">al_draw_bitmap</span></a><span class="k2">(</span>tmp, <span class="n">160</span>, <span class="n">100</span>, <span class="n">0</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 32</span>  <a href="http://www.allegro.cc/manual/al_draw_bitmap"><span class="a">al_draw_bitmap</span></a><span class="k2">(</span>tmp, <span class="n">160</span>, <span class="n">100</span>, <span class="n">0</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 33</span>
<span class="number"> 34</span>  <a href="http://www.allegro.cc/manual/al_set_target_backbuffer"><span class="a">al_set_target_backbuffer</span></a><span class="k2">(</span>display<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 35</span>  <a href="http://www.allegro.cc/manual/al_draw_bitmap"><span class="a">al_draw_bitmap</span></a><span class="k2">(</span>buf, <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"> 36</span>  <a href="http://www.allegro.cc/manual/al_flip_display"><span class="a">al_flip_display</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 37</span>
<span class="number"> 38</span>  <a href="http://www.allegro.cc/manual/al_rest"><span class="a">al_rest</span></a><span class="k2">(</span><span class="n">10</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 39</span>
<span class="number"> 40</span>  <span class="k1">return</span> <span class="n">0</span><span class="k2">;</span>
<span class="number"> 41</span><span class="k2">}</span>
</div></div><p>

EDIT: I&#39;m going to explain what the code does so I can use it as a blog post or wiki article.</p><p>The key thing happening here is you have a completely rendered scene, except for the light(s), and you can quickly draw parts of that scene to a different destination bitmap. You need an image defining the shape and cutoff of the light as well.</p><p>In this example, our &quot;scene&quot; is just the allegro.pcx image drawn 4 times to fit a 640x400 window, at 20% brightness. That&#39;s what the first lines of code after loading bitmaps does.</p><p>After that&#39;s done, the area that will be lit is drawn to a &quot;temporary&quot;/work bitmap. Then the light-shape-definition bitmap is drawn over top of that, which gives us a bitmap with the colors we want (color directly from the scene) and the shape (due to drawing the trapezoid over top).</p><p>The last thing that needs to be done is to set the target back to your scene and draw the &quot;temporary&quot; image we made back over top of the scene at the same point we copied from earlier. We use additive blending to draw it, and draw it as many times as needed to give the desired brightness.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Trent Gamblin)</author>
		<pubDate>Tue, 02 Aug 2011 08:19:11 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;m confused.</p><p>1) draw scene<br />2) draw shadow layer with subtractive blender<br />3) problem???
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Mark Oates)</author>
		<pubDate>Tue, 02 Aug 2011 09:44:13 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>1) subtractive blending is not supported on all chips<br />2) you still have to do basically the same thing anyway. What am I missing?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Trent Gamblin)</author>
		<pubDate>Tue, 02 Aug 2011 09:58:35 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>The multiply blender would work, but it doesn&#39;t appear that that&#39;s available until 5.1.  Until then, I would then do it as thus:</p><div class="source-code snippet"><div class="inner"><pre><a href="http://www.allegro.cc/manual/al_draw_bitmap"><span class="a">al_draw_bitmap</span></a><span class="k2">(</span>af_get_image<span class="k2">(</span><span class="s">"scene.png"</span><span class="k2">)</span>, <span class="n">0</span>, <span class="n">0</span>, NULL<span class="k2">)</span><span class="k2">;</span> <span class="c">// &lt; draw scene</span>

af_push_state<span class="k2">(</span>ALLEGRO_STATE_BLENDER<span class="k2">)</span><span class="k2">;</span> <span class="c">// &lt; obvious what this does, I guess</span>
<a href="http://www.allegro.cc/manual/al_set_blender"><span class="a">al_set_blender</span></a><span class="k2">(</span>ALLEGRO_DEST_MINUS_SRC, ALLEGRO_ONE, ALLEGRO_ONE<span class="k2">)</span><span class="k2">;</span>  <span class="c">// &lt; makeshift subtractive blender</span>
<a href="http://www.allegro.cc/manual/al_draw_bitmap"><span class="a">al_draw_bitmap</span></a><span class="k2">(</span>shadow_layer, <span class="n">0</span>, <span class="n">0</span>, NULL<span class="k2">)</span><span class="k2">;</span> <span class="c">// &lt; draw scene</span>
af_pop_state<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

The work-around being that you&#39;ll have to draw your shadow layer inverted.  Black is white and white is black - because the blender is subtracting <i>more</i> when the value is white.</p><p>scene:<br /><span class="remote-thumbnail"><span class="json">{"name":"604625","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/0\/8\/08948338172946a48c2856efb03cfa55.png","w":962,"h":723,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/0\/8\/08948338172946a48c2856efb03cfa55"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/0/8/08948338172946a48c2856efb03cfa55-240.jpg" alt="604625" width="240" height="180" /></span><br />shadows (drawn inverted):<br /><span class="remote-thumbnail"><span class="json">{"name":"604628","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/9\/0\/90812f9929357cb5da1cddf831d87512.png","w":962,"h":723,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/9\/0\/90812f9929357cb5da1cddf831d87512"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/9/0/90812f9929357cb5da1cddf831d87512-240.jpg" alt="604628" width="240" height="180" /></span><br />composite (drawn with ALLEGRO_DEST_MINUS_SRC, ALLEGRO_ONE, ALLEGRO_ONE):<br /><span class="remote-thumbnail"><span class="json">{"name":"604629","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/d\/5\/d5a6ac624bfa87c0c4c1043dc8dec8ec.png","w":962,"h":723,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/d\/5\/d5a6ac624bfa87c0c4c1043dc8dec8ec"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/d/5/d5a6ac624bfa87c0c4c1043dc8dec8ec-240.jpg" alt="604629" width="240" height="180" /></span><br />There&#39;s some really sexy color curves on the low-level shadows. <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /></p><p>[edit] er... is ALLEGRO_DEST_MINUS_SRC the part that&#39;s not supported on all chips?  Which chips are affected?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Mark Oates)</author>
		<pubDate>Tue, 02 Aug 2011 10:51:13 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Well, in DirectX you have to query a flag and in OpenGL it&#39;s an extension you check for. So there at least were chips at one point which did not support it. I&#39;d say all GPUs with shader support support it as it&#39;s now just a matter of shipping the right shader in the drivers for emulating the old fixed pipeline blending.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Tue, 02 Aug 2011 15:53:59 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Ok, now how do you move the light? You have to recreate the shadow layer each time it moves, and it will be constantly moving, so like I said, basically the same thing I posted but inverted, or am I still missing something?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Trent Gamblin)</author>
		<pubDate>Tue, 02 Aug 2011 16:07:12 +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/607967/926854#target">Trent Gamblin</a> said:</div><div class="quote"><p>Ok, now how do you move the light?</p></div></div><p>You just draw the light in a different place.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>basically the same thing I posted but inverted</p></div></div><p>
I guess mine has less code?... I dunno.  Right now I&#39;m brain-mush confus from trying to learn shaders. <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Mark Oates)</author>
		<pubDate>Wed, 03 Aug 2011 10:51:36 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>You can&#39;t just draw it in a different place. In your example is has to be drawn over the whole scene and thus fill the whole screen so moving it would make gaps in places. This is for a car. Imagine the car driving along then going up a hill. Now imagine there are 5 cars all with headlights on.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Trent Gamblin)</author>
		<pubDate>Wed, 03 Aug 2011 21:32:07 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Trent: I&#39;ve got your example working. \o/</p><p>I&#39;ve got some code that draws a spotlight onto a bitmap, with a variable angle, beam length, brightness and aperture size. Do you think it would be worth submitting it to the Allegro dev team? It requires math.h.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Myrdos)</author>
		<pubDate>Wed, 03 Aug 2011 22:23:53 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I don&#39;t personally think it fits in Allegro... seems too high level. You could post it on the wiki. I&#39;m sure that would be useful for someone.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Trent Gamblin)</author>
		<pubDate>Wed, 03 Aug 2011 22:48:28 +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/607967/926987#target">Trent Gamblin</a> said:</div><div class="quote"><p>You can&#39;t just draw it in a different place. In your example is has to be drawn over the whole scene and thus fill the whole screen so moving it would make gaps in places.</p></div></div><p>The shadow layer is a second buffer, just like the the display backbuffer.  In the normal backbuffer you draw your scene, the sprites, trees, enemies and whatnot.  As you draw their sprites (or in a separate process), you draw their shadows to that &quot;shadowbuffer.&quot;</p><p>Here&#39;s your light triangle (thumbnail doesn&#39;t render correctly because it has alpha:<br /><span class="remote-thumbnail"><span class="json">{"name":"604636","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/e\/6\/e624155cc668c4b6c3d2e6674ed83fa7.png","w":950,"h":605,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/e\/6\/e624155cc668c4b6c3d2e6674ed83fa7"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/e/6/e624155cc668c4b6c3d2e6674ed83fa7-240.jpg" alt="604636" width="240" height="152" /></span></p><p>Once all that&#39;s done you put the two together.</p><p>This is basically how I would do it, except I would try to see how many more features I could work in (except I would probably get frustrated and quit after I couldn&#39;t get them all in.)
</p><ol><li><p>cast rays and draw long shadows
</p></li><li><p>desaturate and blue-tint the shadows.
</p></li><li><p>introduce surface hilights and shine onto some sprites
</p></li><li><p>blur increases from their light sources
</p></li><li><p>overall amplify the light blending that&#39;s closest to the light source.
</p></li><li><p>put in a little mini lens-flair</p></li></ol><p>Most of these require shaders.  The end might look something like this (photoshop):</p><p><span class="remote-thumbnail"><span class="json">{"name":"604637","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/2\/5\/25aca9c4603800a22883474df0ba7228.png","w":958,"h":660,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/2\/5\/25aca9c4603800a22883474df0ba7228"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/2/5/25aca9c4603800a22883474df0ba7228-240.jpg" alt="604637" width="240" height="165" /></span>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Mark Oates)</author>
		<pubDate>Thu, 04 Aug 2011 02:44:17 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I just noticed something, you use the following tint when drawing the background: <span class="source-code"><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">0</span>.<span class="n">2</span>, <span class="n">0</span>.<span class="n">2</span>, <span class="n">0</span>.<span class="n">2</span>, <span class="n">1</span>.<span class="n">0</span><span class="k2">)</span></span></p><p>But I had thought pre-multiplied alpha worked like so: <span class="source-code"><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> alpha, g <span class="k3">*</span> alpha, b <span class="k3">*</span> alpha, alpha<span class="k2">)</span></span></p><p>Mark Oates: If you get that working with Allegro 5&#39;s graphics, you be sure to let me know. <img src="http://www.allegro.cc/forums/smileys/shocked.gif" alt=":o" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Myrdos)</author>
		<pubDate>Thu, 04 Aug 2011 22:30:14 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Yeah, it does work like that. Alpha is 100%, you don&#39;t want to make the image transparent, just darker (and that was just so you can more easily see the light.) The .2 makes is 20% brighness. So it&#39;s 0.2*1.0 = 0.2.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Trent Gamblin)</author>
		<pubDate>Thu, 04 Aug 2011 23:12:15 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>That makes sense. <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Myrdos)</author>
		<pubDate>Fri, 05 Aug 2011 01:28:06 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;ve used the method described by Mark multiple times. It works. <img src="http://www.allegro.cc/forums/smileys/cool.gif" alt="8-)" /> Probably the easiest way you can get to &quot;blend&quot; the lights, just draw them as simple objects into the &quot;shadow&quot; buffer and then flip it with a blender.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Dario ff)</author>
		<pubDate>Fri, 05 Aug 2011 18:33:23 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Not sure how to do quotes, but I&#39;m trying Mark Oates&#39; idea right now with this code:</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/al_draw_bitmap"><span class="a">al_draw_bitmap</span></a><span class="k2">(</span>testPng,<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">  2</span>
<span class="number">  3</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>lightLayer<span class="k2">)</span><span class="k2">;</span>
<span class="number">  4</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_rgb_f"><span class="a">al_map_rgb_f</span></a><span class="k2">(</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>
<span class="number">  5</span>            centered_draw_bitmap<span class="k2">(</span>lanternLight, <span class="n">300</span>,<span class="n">300</span>,<span class="n">0</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  6</span>
<span class="number">  7</span>            <a href="http://www.allegro.cc/manual/al_set_target_backbuffer"><span class="a">al_set_target_backbuffer</span></a><span class="k2">(</span>display<span class="k2">)</span><span class="k2">;</span>
<span class="number">  8</span>
<span class="number">  9</span>            push_allegro_state<span class="k2">(</span>ALLEGRO_STATE_BLENDER<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 10</span>            <a href="http://www.allegro.cc/manual/al_set_blender"><span class="a">al_set_blender</span></a><span class="k2">(</span>ALLEGRO_DEST_MINUS_SRC,ALLEGRO_ONE,ALLEGRO_ONE<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 11</span>
<span class="number"> 12</span>            <a href="http://www.allegro.cc/manual/al_draw_bitmap"><span class="a">al_draw_bitmap</span></a><span class="k2">(</span>lightLayer,<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"> 13</span>
<span class="number"> 14</span>            pop_allegro_state<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
</div></div><p>

Where I am trying to draw an 800x600 blank white space called lightLayer and draw lanternLight on top of it, which is just a black circle. </p><p>I&#39;m getting this (see attachment), in the image after blending, which I don&#39;t understand, since the edges of my lanternLight png square should have been mixed into the white of lightLayer. </p><p>Also, a bit off topic, but I don&#39;t understand what states are used for. Is it that I can&#39;t blend anything without toggling some kind of blending-mode on/off? </p><p>And do I need to make another buffer like in Allegro 4 if I can just use al_set_target_backbuffer and al_flip_display?</p><p>Thanks <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /></p><p>Edit: I just noticed the space outside the black square is brighter than the should-be-lit space inside the circle. That would imply what I&#39;m doing is completely faulty. Is there some understanding I am obviously missing by my codes?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (auamidium)</author>
		<pubDate>Sun, 07 Aug 2011 06:30:10 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>You&#39;re clearing to black:</p><p><span class="source-code"><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_rgb_f"><span class="a">al_map_rgb_f</span></a><span class="k2">(</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></span></p><p>You should clear to white:</p><p><span class="source-code"><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_rgb_f"><span class="a">al_map_rgb_f</span></a><span class="k2">(</span><span class="n">1</span>,<span class="n">1</span>,<span class="n">1</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span></span></p><p>(or, just <span class="source-code"><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_color_name"><span class="a">al_color_name</span></a><span class="k2">(</span><span class="s">"white"</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span></span>)</p><p>[edit:] also, if you use bitmaps for (black) lights, they should be on a clear alpha backdrop, that way you can add multiple lights together correctly without overlapping another light.<br /><span class="remote-thumbnail"><span class="json">{"name":"604647","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/2\/d\/2d4a104f19ecae662e9db43598aa53b5.png","w":1093,"h":557,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/2\/d\/2d4a104f19ecae662e9db43598aa53b5"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/2/d/2d4a104f19ecae662e9db43598aa53b5-240.jpg" alt="604647" width="240" height="122" /></span><br /><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/5/0/5053acebfd02fcb23822c14f4972d767.png" alt="604648" width="127" height="126" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Mark Oates)</author>
		<pubDate>Sun, 07 Aug 2011 07:29:58 +0000</pubDate>
	</item>
</rss>
