<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Drawing Lines on different backgrounds</title>
		<link>http://www.allegro.cc/forums/view/590063</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Tue, 20 Feb 2007 18:56:05 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I am making a line using the following algorithm<br />The line starts from the point where I click the mouse and draws to wherever I point to. </p><p>	while(!key[KEY_ESC])<br />	{<br />    if (mouse_b&amp;1) {<br />int x = mouse_x;<br />int y = mouse_y;</p><p>                          <br />    while (mouse_b&amp;1)<br />    {<br />                              <br />line(bmp, x, y, mouse_x,mouse_y,makecol(255,255, 255)); <br />rest (10);</p><p>		draw_sprite(buffer, bmp, 0, 0);<br />		blit(buffer, screen, 0,0,0,0,1400,1050); <br />			clear_bitmap(buffer);<br />			clear_bitmap(bmp);<br />        }<br />        }<br />	}<br />	</p><p>	destroy_bitmap(buffer);<br />	return 0;<br />}</p><p>The problem I have is that all lines get erased every time I draw a new one. I also want to be able to draw this line on various backgrounds. Any help would be　greatly appreciated.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (fatboy2)</author>
		<pubDate>Wed, 14 Feb 2007 14:07:40 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>The simplest way to achieve the effect you&#39;re aiming for is to use two buffers:</p><p>1. A buffer which holds what you want to show on the screen.<br />2. A buffer which holds the line you are drawing.</p><p>You are effectively doing that now, but your method relies on erasing the screen every time you update the line, so naturally, when you start a new one the old one disappears because it&#39;s using the same buffer to update the new line, and erasing it on every update.</p><p>So what you could do is draw the line to one buffer, draw the background buffer to the screen, then masked-blit the line buffer overtop. When you release the mouse button, you then masked-blit the line buffer onto the background buffer to make the line permanent.</p><p>You can go one step further and use three buffers to eliminate any shearing which may occur as a result. Thus what you would have is:</p><p>1. A buffer which holds what you&#39;ve drawn so far.<br />2. A buffer which holds what you are currently drawing.<br />3. A buffer which holds the combination of the other two buffers so that the screen draw can be done in one operation.</p><p>If you&#39;re attempting to make a drawing program as I currently am, you&#39;re going to quickly gain an appreciation for how difficult they really are...</p><p>--- Kris Asick (Gemini)<br />--- <a href="http://www.pixelships.com">http://www.pixelships.com</a>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Kris Asick)</author>
		<pubDate>Wed, 14 Feb 2007 14:16:20 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I got rid of some of the things that were unnecessary<br />	<br />	while(!key[KEY_ESC])<br />	{<br />    if (mouse_b&amp;1) {<br />int x = mouse_x;<br />int y = mouse_y;<br />              <br />    while (mouse_b&amp;1)<br />    {                         <br />line(bmp, x, y, mouse_x,mouse_y,makecol(255,255, 255)); <br />rest (10);<br />blit(bmp,buffer,0,0,0,0,1400,1050);<br />masked_blit(bmp, screen, 0,0,0,0,1400,1050); <br />		 clear_bitmap(bmp);	<br />        }<br />        } <br />        blit(buffer,screen,0,0,0,0,1400,1050);<br />	}<br />I do not really get how to copy the line from bmp to screen. I also tried to create an intermediate bitmap that holds all the lines that I draw. I think that the problem with my code is that it stops copying when I release the mouse button.]</p><p>EDIT <br />blit(buffer,screen,0,0,0,0,1400,1050); - I think that this is supposed to make the line permanent on the screen. But for some reason it does not work
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (fatboy2)</author>
		<pubDate>Wed, 14 Feb 2007 14:56:03 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>use 2 buffers...<br />all the lines on one buffer and evrything including the line buffer on the main buffer.</p><p><b>bitmap to scrren--&gt;</b></p><p>draw_sprite(screen,<i>your buffername</i>,0,0);
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Lucid Nightmare)</author>
		<pubDate>Wed, 14 Feb 2007 15:03:44 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Please, use the code tags, they make your posts much easier to read. You can see how by clicking on &quot;Help&quot; where you write the post.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Indeterminatus)</author>
		<pubDate>Wed, 14 Feb 2007 17:26:56 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="source-code snippet"><div class="inner"><pre>Thank goodness someone said something about the help tab, which I never noticed.
Now I can use code tags<span class="k3">!</span> Yay<span class="k3">!</span>
</pre></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Neil Black)</author>
		<pubDate>Wed, 14 Feb 2007 19:42:18 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Here&#39;s one method that might work. Haven&#39;t tested it, only spent five minutes writing it...</p><div class="source-code"><div class="toolbar"></div><div class="inner"><table width="100%"><tbody><tr><td class="number">1</td><td><a href="http://www.allegro.cc/manual/BITMAP" target="_blank"><span class="a">BITMAP</span></a> draw_buffer, screen_buffer<span class="k2">;</span></td></tr><tr><td class="number">2</td><td>&#160;</td></tr><tr><td class="number">3</td><td><span class="k1">while</span><span class="k2">(</span><span class="k3">!</span><a href="http://www.allegro.cc/manual/key" target="_blank"><span class="a">key</span></a><span class="k2">[</span>KEY_ESC<span class="k2">]</span><span class="k2">)</span></td></tr><tr><td class="number">4</td><td><span class="k2">{</span></td></tr><tr><td class="number">5</td><td>  <span class="k1">int</span> initx <span class="k3">=</span> <span class="k3">-</span><span class="n">999</span>, inity <span class="k3">=</span> <span class="k3">-</span><span class="n">999</span><span class="k2">;</span></td></tr><tr><td class="number">6</td><td>&#160;</td></tr><tr><td class="number">7</td><td>  <a href="http://www.allegro.cc/manual/blit" target="_blank"><span class="a">blit</span></a><span class="k2">(</span>draw_buffer,screen_buffer,<span class="n">0</span>,<span class="n">0</span>,<span class="n">0</span>,<span class="n">0</span>,draw_buffer-&gt;w,draw_buffer-&gt;h<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">8</td><td>&#160;</td></tr><tr><td class="number">9</td><td>  <span class="k1">if</span> <span class="k2">(</span><a href="http://www.allegro.cc/manual/mouse_b" target="_blank"><span class="a">mouse_b</span></a> <span class="k3">&amp;</span> <span class="n">1</span><span class="k2">)</span></td></tr><tr><td class="number">10</td><td>  <span class="k2">{</span></td></tr><tr><td class="number">11</td><td>    <span class="k1">if</span> <span class="k2">(</span>initx <span class="k3">=</span><span class="k3">=</span> <span class="k3">-</span><span class="n">999</span><span class="k2">)</span></td></tr><tr><td class="number">12</td><td>    <span class="k2">{</span></td></tr><tr><td class="number">13</td><td>      initx <span class="k3">=</span> <a href="http://www.allegro.cc/manual/mouse_x" target="_blank"><span class="a">mouse_x</span></a><span class="k2">;</span></td></tr><tr><td class="number">14</td><td>      inity <span class="k3">=</span> <a href="http://www.allegro.cc/manual/mouse_y" target="_blank"><span class="a">mouse_y</span></a><span class="k2">;</span></td></tr><tr><td class="number">15</td><td>    <span class="k2">}</span></td></tr><tr><td class="number">16</td><td>&#160;</td></tr><tr><td class="number">17</td><td>    <a href="http://www.allegro.cc/manual/line" target="_blank"><span class="a">line</span></a><span class="k2">(</span>screen_buffer,initx,inity,<a href="http://www.allegro.cc/manual/mouse_x" target="_blank"><span class="a">mouse_x</span></a>,<a href="http://www.allegro.cc/manual/mouse_y" target="_blank"><span class="a">mouse_y</span></a>,<a href="http://www.allegro.cc/manual/makecol" target="_blank"><span class="a">makecol</span></a><span class="k2">(</span><span class="n">255</span>,<span class="n">255</span>,<span class="n">255</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">18</td><td>  <span class="k2">}</span></td></tr><tr><td class="number">19</td><td>  <span class="k1">else</span> <span class="k1">if</span> <span class="k2">(</span>initx <span class="k3">!</span><span class="k3">=</span> <span class="k3">-</span><span class="n">999</span><span class="k2">)</span></td></tr><tr><td class="number">20</td><td>  <span class="k2">{</span></td></tr><tr><td class="number">21</td><td>    <a href="http://www.allegro.cc/manual/line" target="_blank"><span class="a">line</span></a><span class="k2">(</span>screen_buffer,initx,inity,<a href="http://www.allegro.cc/manual/mouse_x" target="_blank"><span class="a">mouse_x</span></a>,<a href="http://www.allegro.cc/manual/mouse_y" target="_blank"><span class="a">mouse_y</span></a>,<a href="http://www.allegro.cc/manual/makecol" target="_blank"><span class="a">makecol</span></a><span class="k2">(</span><span class="n">255</span>,<span class="n">255</span>,<span class="n">255</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">22</td><td>    <a href="http://www.allegro.cc/manual/line" target="_blank"><span class="a">line</span></a><span class="k2">(</span>draw_buffer,initx,inity,<a href="http://www.allegro.cc/manual/mouse_x" target="_blank"><span class="a">mouse_x</span></a>,<a href="http://www.allegro.cc/manual/mouse_y" target="_blank"><span class="a">mouse_y</span></a>,<a href="http://www.allegro.cc/manual/makecol" target="_blank"><span class="a">makecol</span></a><span class="k2">(</span><span class="n">255</span>,<span class="n">255</span>,<span class="n">255</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">23</td><td>    initx <span class="k3">=</span> <span class="k3">-</span><span class="n">999</span><span class="k2">;</span></td></tr><tr><td class="number">24</td><td>  <span class="k2">}</span></td></tr><tr><td class="number">25</td><td>&#160;</td></tr><tr><td class="number">26</td><td>  <a href="http://www.allegro.cc/manual/blit" target="_blank"><span class="a">blit</span></a><span class="k2">(</span>screen_buffer,<a href="http://www.allegro.cc/manual/screen" target="_blank"><span class="a">screen</span></a>,<span class="n">0</span>,<span class="n">0</span>,<span class="n">0</span>,<span class="n">0</span>,draw_buffer-&gt;w,draw_buffer-&gt;h<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">27</td><td>  <a href="http://www.allegro.cc/manual/rest" target="_blank"><span class="a">rest</span></a><span class="k2">(</span><span class="n">1</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">28</td><td><span class="k2">}</span></td></tr></tbody></table></div></div><p>

I don&#39;t like that code, but it should do exactly what you want it to do. The reason I don&#39;t like it is because the method I use in my drawing program is a lot better, but about 20 times more complicated.</p><p>--- Kris Asick (Gemini)<br />--- <a href="http://www.pixelships.com">http://www.pixelships.com</a>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Kris Asick)</author>
		<pubDate>Wed, 14 Feb 2007 22:45:39 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Your code does not work the way I want it to because it does not have a while loop in it. With the if statement the line does not draw continuously, and as a result all i get are dots on the screen. </p><p>I have tried adding an extra if statement:</p><p>if(!mouse_b&amp;1) {<br />blit(screen,screen_buffer,0,0,0,0,640,480);<br />blit(screen_buffer,screen,0,0,0,0,640,480);</p><p>}</p><p>This does not seem to work so please give some suggestions.<br />i really do not understand why the screen is cleared each time I start a new line</p><p>EDIT: I got it, the problem is with the way I copy things from one bitmap to the other. I did not really understand the stuff written in the manual about copying functions such as blit and masked_blit.<br />Please explain what blitting function I need to use to just copy pixels that are not black from one bitmap to the other.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (fatboy2)</author>
		<pubDate>Fri, 16 Feb 2007 19:20:04 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Black is subjective.</p><p>In 8-bit mode, palette entry #0 is almost always black, unless you change it. Thus if you change it, that becomes your new transparent colour.</p><p>In 15/16/24/32-bit mode, magic pink is the transparent colour. You can make this colour by calling makecol(255,0,255). If you want transparent areas on a bitmap in higher colour depths, it needs to be that colour.</p><p>To draw things onto the screen with transparent areas, you need to use masked_blit(), draw_sprite(), draw_character_ex(), or any of the other sprite-based drawing commands.</p><p>I checked the code I provided by the way. It&#39;s bugged, but very easy to fix. If you move the &quot;int initx = -999, inity = -999;&quot; line to just before the while loop begins, it works perfectly.</p><p>--- Kris Asick (Gemini)<br />--- <a href="http://www.pixelships.com">http://www.pixelships.com</a>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Kris Asick)</author>
		<pubDate>Sat, 17 Feb 2007 10:35:05 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I get it now, thanks a lot. <br />Is is possible to change the transparent color to something else instead of pink and how do I do it?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (fatboy2)</author>
		<pubDate>Sat, 17 Feb 2007 13:10:07 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Unfortunately, the mask colours are built from #define directives, which means the only way to make the transparency colour different is to create your own routine for blitting which accepts different transparency colours.</p><p>Though another method is to use 32-bit, alpha blended sprites, but Allegro&#39;s routines for doing that are not the fastest.</p><p>An old method for doing transparent blitting is to have two sprites, one which represents the sprite, another which represents the transparent areas called the mask. You then draw the mask to the screen using an AND binary operation and draw the sprite using an OR binary operation. Again though, Allegro doesn&#39;t have built-in features to accommodate this method of drawing.</p><p>--- Kris Asick (Gemini)<br />--- <a href="http://www.pixelships.com">http://www.pixelships.com</a>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Kris Asick)</author>
		<pubDate>Sun, 18 Feb 2007 00:23:42 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Again though, Allegro doesn&#39;t have built-in features to accommodate this method of drawing.
</p></div></div><p>
It sort of does, using custom blenders, but I wouldn&#39;t recommend it.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Tobias Dammers)</author>
		<pubDate>Tue, 20 Feb 2007 18:56:05 +0000</pubDate>
	</item>
</rss>
