<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>[A5] al_draw_rectangle bug? rectangle is drawn by 1 pixel off.</title>
		<link>http://www.allegro.cc/forums/view/606662</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Wed, 16 Mar 2011 23:18:25 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I am using the function al_draw_rectangle to create a rectangle from (200, 150) to (449, 349). The rectangle&#39;s width is 250 pixels, and the height is 200 pixels. Here is the drawing code:</p><div class="source-code snippet"><div class="inner"><pre><span class="c">//test draw</span>
<span class="k1">void</span> draw<span class="k2">(</span><span class="k2">)</span> <span class="k2">{</span>
    <a href="http://www.allegro.cc/manual/al_draw_filled_rectangle"><span class="a">al_draw_filled_rectangle</span></a><span class="k2">(</span><span class="n">0</span>, <span class="n">0</span>, <span class="n">640</span>, <span class="n">480</span>, <a href="http://www.allegro.cc/manual/al_map_rgb"><span class="a">al_map_rgb</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>
    <a href="http://www.allegro.cc/manual/al_draw_rectangle"><span class="a">al_draw_rectangle</span></a><span class="k2">(</span><span class="n">200</span>, <span class="n">150</span>, <span class="n">200</span><span class="k3">+</span><span class="n">250</span><span class="k3">-</span><span class="n">1</span>, <span class="n">150</span><span class="k3">+</span><span class="n">200</span><span class="k3">-</span><span class="n">1</span>, <a href="http://www.allegro.cc/manual/al_map_rgb"><span class="a">al_map_rgb</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="n">1</span><span class="k2">)</span><span class="k2">;</span>
<span class="k2">}</span>
</pre></div></div><p>

However, when I zoom into the picture, the rectangle starts from (199, 149) (the cursor is over the red pixel):</p><p><span class="remote-thumbnail"><span class="json">{"name":"Wvqcv.png","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/6\/a\/6a6255b35cf08de2c944c948838070f7.png","w":1280,"h":998,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/6\/a\/6a6255b35cf08de2c944c948838070f7"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/6/a/6a6255b35cf08de2c944c948838070f7-240.jpg" alt="Wvqcv.png" title="Hosted by imgur.com" width="240" height="187" /></span></p><p>The <a href="http://www.allegro.cc/manual/5/primitives.html">A5 manual says</a>:</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
The basic rule that determines which pixels are associated with which shape is then as follows: a pixel is treated to belong to a shape if the pixel&#39;s center is located in that shape. 
</p></div></div><p>

However, the center of pixel (199, 149) is not inside the shape. The center of this pixel is (199.5, 149.5), which is outside of the range (200.0-201.0, 150.0-151.0).</p><p>What gives? is this normal? is it an A5 bug?</p><p>If I use thickness = 0, then the rectangle still starts from the pixel (199, 149), with the exception that the pixel at that specific location is not drawn.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (axilmar)</author>
		<pubDate>Fri, 11 Mar 2011 19:57:37 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Outlined versions need the 0.5 offsets. See the second diagram + code here: <a href="http://www.allegro.cc/manual/5/primitives.html">http://www.allegro.cc/manual/5/primitives.html</a>.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SiegeLord)</author>
		<pubDate>Fri, 11 Mar 2011 20:54:01 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>So, when I draw an outlined shape, I need to add 0.5 to all the coordinates.</p><p>What about filled shapes? I draw a filled rectangle from (200,150) to (449, 349), but the rectangle is drawn up to (448, 348):</p><p><span class="remote-thumbnail"><span class="json">{"name":"eupaR.png","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/e\/2\/e2d2235e40e6dfff9015881b421ef495.png","w":1280,"h":998,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/e\/2\/e2d2235e40e6dfff9015881b421ef495"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/e/2/e2d2235e40e6dfff9015881b421ef495-240.jpg" alt="eupaR.png" title="Hosted by imgur.com" width="240" height="187" /></span></p><p>So I guess at for filled shapes, I need to add the offset 0.5 to the right and bottom coordinates. Am I correct?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (axilmar)</author>
		<pubDate>Fri, 11 Mar 2011 21:19:18 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>No, there is no offset for filled shapes. And outlined shapes also are filled - they simply specify the center and not the outer outline. So if you use a thickness of 1 that means the filled shape extends 0.5 in all directions and the offset is only to counter that - but in general there never is any extra offset.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Fri, 11 Mar 2011 21:23:07 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I think it is best to imagine what happens exactly instead of memorising the offsets. Study the second diagram + code in the link I gave you and it should be apparent why the output you get is what you get.</p><p>The short version is that integer pixel coordinates refer to the top-left corner of the pixel and not its centre.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SiegeLord)</author>
		<pubDate>Fri, 11 Mar 2011 21:27:39 +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/606662/907177#target">SiegeLord</a> said:</div><div class="quote"><p>I think it is best to imagine what happens exactly instead of memorising the offsets. Study the second diagram + code in the link I gave you and it should be apparent why the output you get is what you get.</p></div></div><p>

I have studied both diagrams and read the relevant documentation page many times, but I can&#39;t seem to pinpoint the exact rules of drawing. </p><p>So, let me write down the complete set of rules of drawing:</p><ul><li><p>if the shape is outlined, then the coordinates refer to the pixel center.
</p></li><li><p>if the shape is not outlined, then the coordinates refer to the pixel top-left corner.
</p></li><li><p>a pixel is drawn if its center is within the shape coordinates.</p></li></ul><p>Am I correct? are the above the only rules I need to remember for drawing?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (axilmar)</author>
		<pubDate>Fri, 11 Mar 2011 21:35:54 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>They always refer to the exact position (with 0.0/0.0 being the top-left corner of the top-most and left-most pixel). But when you draw an outlined shape, say the red line in the diagram from (2, 1) to (6, 1) then you need to take the thickness into account. It has a thickness of 2, so you really draw a rectangle from (2, 1 - 1) to (6, 1 + 1) so a rectangle from (2, 0) to (6, 2). Any any pixels who&#39;s pixel centers are within that mathematical shape will be lit.</p><p>[edit: thickness of al_draw_line only extends along the normal, fixed my numbers <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" />]
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Fri, 11 Mar 2011 21:58:49 +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/606662/907179#target">axilmar</a> said:</div><div class="quote"><p>
Am I correct? are the above the only rules I need to remember for drawing?
</p></div></div><p>

No. Understanding what pixels are drawn given the inputs you give to the functions is a two step process.</p><ol><li><p>Understanding how the actual polygon is formed
</p></li><li><p>Understanding what pixels are drawn given the actual polygon</p></li></ol><p>Combining the two steps into one rule is possible, but only after you understand the two steps above.</p><p>For a filled rectangle, the actual polygon is formed exactly from the coordinates you pass to the function:</p><p><span class="source-code"><a href="http://www.allegro.cc/manual/al_draw_filled_rectangle"><span class="a">al_draw_filled_rectangle</span></a><span class="k2">(</span><span class="n">0</span>, <span class="n">0</span>, <span class="n">100</span>, <span class="n">100</span>, c<span class="k2">)</span></span></p><p>will produce a rectangular polygon that spans from (0, 0) to (100, 100). Now given that the coordinate system is such that integer coordinates refer to the top left corner of the pixel, this means that pixels 0 through 99 will be shaded in a horizontal line. Pixel 100 has its center at 100.5 which is outside the polygon.</p><p>For an outlined rectangle, you have to imagine two borders being formed, the outer one and the inner one: the only pixels that will be drawn are those inside the outer border and outside the inner one. Both borders are in effect offset from the rectangle you pass by thickness/2. I.e. this call:</p><p><span class="source-code"><a href="http://www.allegro.cc/manual/al_draw_rectangle"><span class="a">al_draw_rectangle</span></a><span class="k2">(</span><span class="n">0</span>, <span class="n">0</span>, <span class="n">100</span>, <span class="n">100</span>, c, <span class="n">1</span><span class="k2">)</span></span></p><p>Will have an inner border of (0.5, 0.5) to (99.5, 99.5) and an outer border of (-0.5, -0.5, 100.5, 100.5). Those 0.5&#39;s are bad because it means that the borders lie on the centers of the pixels. What happens in that case is implementation defined. To avoid that, you introduce an offset:</p><p><span class="source-code"><a href="http://www.allegro.cc/manual/al_draw_rectangle"><span class="a">al_draw_rectangle</span></a><span class="k2">(</span><span class="n">0</span>.<span class="n">5</span>, <span class="n">0</span>.<span class="n">5</span>, <span class="n">99</span>.<span class="n">5</span>, <span class="n">99</span>.<span class="n">5</span>, c, <span class="n">1</span><span class="k2">)</span></span></p><p>This call will have these borders: inner: (1, 1, 99, 99), outer: (0, 0, 100, 100). Now you can see that the pixels that&#39;ll get drawn (again in a horizontal line) are pixel 0 (center at (0.5, 0.5) falls between 0 and 1) and pixel 99 (center at (99.5, 99.5) falls between 99 and 100).</p><p>So yeah... those are the &quot;rules&quot;. Makes sure you get what would happen if your thickness was 2 instead of 1.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SiegeLord)</author>
		<pubDate>Fri, 11 Mar 2011 22:08:29 +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/606662/907186#target">SiegeLord</a> said:</div><div class="quote"><p>
So yeah... those are the &quot;rules&quot;. 
</p></div></div><p>

To which rules are you referring to? to the ones you wrote or to the ones I wrote?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (axilmar)</author>
		<pubDate>Fri, 11 Mar 2011 22:16:06 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>The ones I wrote. They are in quotes because they are not at the same level of rules that the rules you wrote were.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SiegeLord)</author>
		<pubDate>Fri, 11 Mar 2011 22:19:57 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>So, are these the complete set of rules?</p><ul><li><p>if the shape is outlined, then the coordinates refer to the <b>line center</b>.
</p></li><li><p>if the shape is not outlined, then the coordinates refer to the pixel top-left corner.
</p></li><li><p>a pixel is drawn if its center is within the shape coordinates.</p></li></ul><p>I changed the &#39;pixel center&#39; to &#39;line center&#39; in the first rule, in order to account for the line thickness, as per your comment.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (axilmar)</author>
		<pubDate>Fri, 11 Mar 2011 22:26:57 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Well, the second rule is not quite right. What does it predict when you do this:</p><p><span class="source-code"><a href="http://www.allegro.cc/manual/al_draw_filled_rectangle"><span class="a">al_draw_filled_rectangle</span></a><span class="k2">(</span><span class="n">0</span>.<span class="n">25</span>, <span class="n">0</span>.<span class="n">25</span>, <span class="n">10</span>.<span class="n">25</span>, <span class="n">10</span>.<span class="n">25</span><span class="k2">)</span></span> ?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SiegeLord)</author>
		<pubDate>Fri, 11 Mar 2011 22:33:11 +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/606662/907192#target">SiegeLord</a> said:</div><div class="quote"><p>
Well, the second rule is not quite right. What does it predict when you do this:
</p></div></div><p>

It draws a filled rectangle from (0,0) to (9, 9). </p><p>The center of the pixel at the coordinate 0.25 is within the shape, and therefore the pixel 0 is drawn.</p><p>The center of the pixel at the coordinate 10.25 is not within the shape, and therefore the pixel 10 is not included into the shape.</p><p>How would you write the 2nd rule?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (axilmar)</author>
		<pubDate>Fri, 11 Mar 2011 22:43:48 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Well, thing is... the coordinate system A5 uses always has integer coordinates correspond to the top-left corner of a pixel. I&#39;d guess the second rule would be better put as coordinates refer to the shape edge, or something.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SiegeLord)</author>
		<pubDate>Sat, 12 Mar 2011 00:35:54 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Thanks!
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (axilmar)</author>
		<pubDate>Sat, 12 Mar 2011 00:51:18 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I came in late, but the first point I&#39;ll make is that it&#39;s <i>very</i> helpful to turn on sub-pixel rendering.  It makes it a lot clearer to see what&#39;s going on under there.  Not having sub-pixel rendering can really obfuscate what&#39;s happening, especially because it&#39;s at the unit level, and can lead to much confusion.</p><p>The second point, and the real key in my opinion, is that when drawing outlines, you&#39;re drawing with a <i>stroke aligned to the center</i> of the coordinates.</p><p>A filled rectangle, drawn at (3, 3) to (17, 16):<br /><span class="remote-thumbnail"><span class="json">{"name":"603584","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/2\/7\/27f1091587815b3ccf5c41f143a389f5.png","w":532,"h":504,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/2\/7\/27f1091587815b3ccf5c41f143a389f5"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/2/7/27f1091587815b3ccf5c41f143a389f5-240.jpg" alt="603584" width="240" height="227" /></span></p><p>The outline, using the same coordinates.  The stroke has a pixel width of 1 and is <i>centered</i> on the coordinates.  The is what allegro does when drawing strokes:<br /><span class="remote-thumbnail"><span class="json">{"name":"603585","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/3\/b\/3ba01788136cfe2eca1eebfe58072d10.png","w":532,"h":504,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/3\/b\/3ba01788136cfe2eca1eebfe58072d10"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/3/b/3ba01788136cfe2eca1eebfe58072d10-240.jpg" alt="603585" width="240" height="227" /></span></p><p>Here is an example of a different stroke alignment, where the stroke is <i>inside</i> the shape (stroke with of 1.5):<br /><span class="remote-thumbnail"><span class="json">{"name":"603586","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/8\/6\/861866a517208fede80ea51858341e76.png","w":532,"h":504,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/8\/6\/861866a517208fede80ea51858341e76"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/8/6/861866a517208fede80ea51858341e76-240.jpg" alt="603586" width="240" height="227" /></span></p><p>This is what people typically assume will happen.  In this case, it is a top and left aligned stroke:<br /><span class="remote-thumbnail"><span class="json">{"name":"603587","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/1\/0\/10682a9252e67b554d7c981fce6b4b3a.png","w":532,"h":504,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/1\/0\/10682a9252e67b554d7c981fce6b4b3a"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/1/0/10682a9252e67b554d7c981fce6b4b3a-240.jpg" alt="603587" width="240" height="227" /></span></p><p>Since the alignment is centered with allegro, putting a +0.5 on your coordinates (when drawing with a stroke-width of 1px) will tuck the centered stroke inside a whole pixel when plotted to the screen, assuming you have no transformations.  The result is that it will behave more like a pixel-coordinate rendering system rather than a position-coordinate.</p><p>And finally, my third point - The fact that the position-coordinates are also in pixel widths can erroneously make it seem like you are plotting directly to pixel-coordinates.  Don&#39;t let that confuse you.</p><p>That&#39;s the way I see it, anyway. <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Mark Oates)</author>
		<pubDate>Sat, 12 Mar 2011 01:23:56 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I thought the reason for all this was because particular video cards have some differences in how they render a line, and these &quot;rules&quot; are trying to achieve some sort of compromise that will do what you expected. <img src="http://www.allegro.cc/forums/smileys/huh.gif" alt="???" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Arthur Kalliokoski)</author>
		<pubDate>Sat, 12 Mar 2011 01:44:33 +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/606662/907222#target">Arthur Kalliokoski</a> said:</div><div class="quote"><p>I thought the reason for all this was because particular video cards have some differences in how they render a line, and these &quot;rules&quot; are trying to achieve some sort of compromise that will do what you expected.</p></div></div><p>

No, sub-pixel rendering just looks way better (and is not possible with integer-only coordinates of course). Filled shapes are always rendered exactly no matter which video card draws them (except when the outline of your shape happens to hit the exact center of a pixel).
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Sat, 12 Mar 2011 01:52:54 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p><a href="http://wiki.allegro.cc/index.php?title=Drawing_Primitives_in_Grid_Coordinates">Drawing Primitives in Grid Coordinates</a> <img src="http://www.allegro.cc/forums/smileys/shocked.gif" alt=":o" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Mark Oates)</author>
		<pubDate>Sat, 12 Mar 2011 15:50:12 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;m bookmarking that page. I need to go over my GUI rendering code...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Trezker)</author>
		<pubDate>Sun, 13 Mar 2011 10:43:12 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>After quite a bit of searching I haven&#39;t found anything explaining how to enable sub-pixel rendering.  Given how lines are drawn now, I would think it would be on by default.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Neil Roy)</author>
		<pubDate>Sun, 13 Mar 2011 21:39:05 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>It&#39;s not supported by all cards, so enabling it by default seems tenuous. Anyway, you can look at &#39;ex_multisample&#39; to see how it is done. I don&#39;t know why wiki uses the &#39;sub-pixel rendering&#39; term... it&#39;d be easier to relate to the actual feature if it referred to it as multi-sampling.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SiegeLord)</author>
		<pubDate>Sun, 13 Mar 2011 21:45:05 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Ah okay, I was thinking about multisampling, but I wasn&#39;t sure if there was some feature that I just wasn&#39;t seeing.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Neil Roy)</author>
		<pubDate>Sun, 13 Mar 2011 22:11:33 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>The term &quot;sub pixel&quot; refers to antialiasing (drawing screen pixels according to how close they are to where they &quot;should&quot; be) and multisampling is &quot;sub texel&quot; which refers to grabbing source texels (bitmap pixels) according to how close, right?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Arthur Kalliokoski)</author>
		<pubDate>Sun, 13 Mar 2011 22:35:20 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I think Allegro should also offer a primitives add-on that draws pixel coordinates. It&#39;s hard to remember all these details. I had to read this thread again in order to be reminded of what I should do in each case, and perhaps I am not the only one. The primitives add-on is good for games, where it pixel coordinates do not matter, but it is not so appropriate for drawing UIs, where discrete coordinates are required. It would be quite helpful to a lot of people, I think.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (axilmar)</author>
		<pubDate>Tue, 15 Mar 2011 16:56:03 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I created macros for myself: <span class="source-code">algui_draw_hline<span class="k2">(</span><span class="k2">)</span></span>, etc.</p><p>But I&#39;m not sure that they really belong in Allegro.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Matthew Leverton)</author>
		<pubDate>Tue, 15 Mar 2011 23:52:46 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>This is harder than trying to understand the IE6 box model <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" /></p><p>Is all this complication due to the way opengl renders or something?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Neil Walker)</author>
		<pubDate>Wed, 16 Mar 2011 00:29:47 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Read Mark&#39;s article. It&#39;s supposed to clear this up.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Matthew Leverton)</author>
		<pubDate>Wed, 16 Mar 2011 00:38:08 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I have to agree with axilmar on this.  Having some sort of toggle would be nice.  Selecting what type of system you wish to use.</p><p>Although writing your own would be no big deal I guess.  I may write a few of my own functions for pixel co-ordinates.  I haven&#39;t used A5 that much yet, just getting started, there is a function to plot a pixel right?  So I could use that and create my own for lines, circles etc.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Neil Roy)</author>
		<pubDate>Wed, 16 Mar 2011 07:02:02 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I would also like to see compatibility functions for 2D drawing. Simple wrappers for the new al_draw calls that mimic the behaviour of A4&#39;s drawing functions. Once my GUI library is ready to be ported to A5, I would have to write them anyway, as that would be much simpler than replacing all the drawing function calls.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Wed, 16 Mar 2011 07:15:58 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Just created a nice line drawing function.  It&#39;s pretty fast if anyone wants to use it. <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /></p><p>I looked up Bresenham&#39;s line algorithm online and adopted what I found.  I plan on adding more to this for circles (using similar algorithm&#39;s as I find &#39;em).</p><p>There&#39;s nothing here specifying a particular bitmap or screen to draw on yet.</p><p>A5_PixelDraw.h...
</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">#ifndef _A5_PixelDraw_h_</span>
<span class="number"> 2</span><span class="p">#define _A5_PixelDraw_h_</span>
<span class="number"> 3</span>
<span class="number"> 4</span><span class="k1">extern</span> <span class="k1">void</span> a5_line<span class="k2">(</span><span class="k1">int</span> start_x, <span class="k1">int</span> start_y, <span class="k1">int</span> dest_x, <span class="k1">int</span> dest_y, <a href="http://www.allegro.cc/manual/ALLEGRO_COLOR"><span class="a">ALLEGRO_COLOR</span></a> colour<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 5</span>
<span class="number"> 6</span><span class="p">#endif</span>
</div></div><p>

A5_PixelDraw.cpp...
</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;cstdlib&gt; // abs()</span>
<span class="number">  2</span><span class="p">#include &lt;allegro5/allegro.h&gt;</span>
<span class="number">  3</span><span class="p">#include "A5_PixelDraw.h"</span>
<span class="number">  4</span>
<span class="number">  5</span>
<span class="number">  6</span><span class="k1">void</span> a5_line<span class="k2">(</span><span class="k1">int</span> start_x, <span class="k1">int</span> start_y, <span class="k1">int</span> dest_x, <span class="k1">int</span> dest_y, <a href="http://www.allegro.cc/manual/ALLEGRO_COLOR"><span class="a">ALLEGRO_COLOR</span></a> colour<span class="k2">)</span>
<span class="number">  7</span><span class="k2">{</span>
<span class="number">  8</span>   <span class="c">// Bresenham's line algorithm</span>
<span class="number">  9</span>   <span class="k1">int</span> x0 <span class="k3">=</span> start_x<span class="k2">;</span>
<span class="number"> 10</span>   <span class="k1">int</span> x1 <span class="k3">=</span> dest_x<span class="k2">;</span>
<span class="number"> 11</span>   <span class="k1">int</span> y0 <span class="k3">=</span> start_y<span class="k2">;</span>
<span class="number"> 12</span>   <span class="k1">int</span> y1 <span class="k3">=</span> dest_y<span class="k2">;</span>
<span class="number"> 13</span>   <span class="k1">int</span> sx, sy, err, e2<span class="k2">;</span>
<span class="number"> 14</span>
<span class="number"> 15</span>   <span class="k1">int</span> dx <span class="k3">=</span> <a href="http://www.delorie.com/djgpp/doc/libc/libc_38.html" target="_blank">abs</a><span class="k2">(</span>x1-x0<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 16</span>   <span class="k1">int</span> dy <span class="k3">=</span> <a href="http://www.delorie.com/djgpp/doc/libc/libc_38.html" target="_blank">abs</a><span class="k2">(</span>y1-y0<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 17</span>
<span class="number"> 18</span>   <span class="k1">if</span><span class="k2">(</span>x0 <span class="k3">&lt;</span> x1<span class="k2">)</span> sx <span class="k3">=</span> <span class="n">1</span><span class="k2">;</span> <span class="k1">else</span> sx <span class="k3">=</span> <span class="k3">-</span><span class="n">1</span><span class="k2">;</span>
<span class="number"> 19</span>   <span class="k1">if</span><span class="k2">(</span>y0 <span class="k3">&lt;</span> y1<span class="k2">)</span> sy <span class="k3">=</span> <span class="n">1</span><span class="k2">;</span> <span class="k1">else</span> sy <span class="k3">=</span> <span class="k3">-</span><span class="n">1</span><span class="k2">;</span>
<span class="number"> 20</span>   err <span class="k3">=</span> dx-dy<span class="k2">;</span>
<span class="number"> 21</span>
<span class="number"> 22</span>   <span class="k1">while</span><span class="k2">(</span>x0 <span class="k3">!</span><span class="k3">=</span> x1 <span class="k1">and</span> y0 <span class="k3">!</span><span class="k3">=</span> y1<span class="k2">)</span> <span class="k2">{</span>
<span class="number"> 23</span>      <a href="http://www.allegro.cc/manual/al_put_pixel"><span class="a">al_put_pixel</span></a><span class="k2">(</span>x0, y0, colour<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 24</span>      e2 <span class="k3">=</span> <span class="n">2</span><span class="k3">*</span>err<span class="k2">;</span>
<span class="number"> 25</span>      <span class="k1">if</span><span class="k2">(</span>e2 <span class="k3">&gt;</span> <span class="k3">-</span>dy<span class="k2">)</span> <span class="k2">{</span>
<span class="number"> 26</span>         err <span class="k3">-</span><span class="k3">=</span> dy<span class="k2">;</span>
<span class="number"> 27</span>         x0 <span class="k3">+</span><span class="k3">=</span> sx<span class="k2">;</span>
<span class="number"> 28</span>      <span class="k2">}</span>
<span class="number"> 29</span>      <span class="k1">if</span><span class="k2">(</span>e2 <span class="k3">&lt;</span>  dx<span class="k2">)</span> <span class="k2">{</span>
<span class="number"> 30</span>         err <span class="k3">+</span><span class="k3">=</span> dx<span class="k2">;</span>
<span class="number"> 31</span>         y0 <span class="k3">+</span><span class="k3">=</span> sy<span class="k2">;</span>
<span class="number"> 32</span>      <span class="k2">}</span>
<span class="number"> 33</span>   <span class="k2">}</span>
<span class="number"> 34</span>
<span class="number"> 35</span>   <span class="k1">return</span><span class="k2">;</span>
<span class="number"> 36</span><span class="k2">}</span>
</div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Neil Roy)</author>
		<pubDate>Wed, 16 Mar 2011 09:36:20 +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/606662/908109#target">Neil Roy</a> said:</div><div class="quote"><p>I haven&#39;t used A5 that much yet, just getting started, there is a function to plot a pixel right?  So I could use that and create my own for lines, circles etc.</p></div></div><p>Just be sure to lock your bitmap first before drawing the pixels, then unlock it when you&#39;re done (drawing the pixels).  Otherwise you&#39;ll get a <i>really</i> slow render.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Mark Oates)</author>
		<pubDate>Wed, 16 Mar 2011 09:37:04 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Oh yeah!! I forgot about that, thanks Mark.  I&#39;ll modify my function.  I had that in mind before I started on this function and got so wrapped up in making it that I forgot about locking the bitmap! <img src="http://www.allegro.cc/forums/smileys/cheesy.gif" alt=";D" border="0" />.</p><p>Hmmm, I don&#39;t require a bitmap in my function... I s&#39;pose I should so I can lock it?</p><p>It runs REALLY fast, at least in a simple test I done as is.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Neil Roy)</author>
		<pubDate>Wed, 16 Mar 2011 09:40:24 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Either lock the target bitmap or tell the programmer to do it before calling any of the functions.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Matthew Leverton)</author>
		<pubDate>Wed, 16 Mar 2011 09:41:28 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>You&#39;re always drawing to a bitmap.  If you haven&#39;t explicitly defined a bitmap then it will be the <span class="source-code"><a href="http://www.allegro.cc/manual/ALLEGRO_BITMAP"><span class="a">ALLEGRO_BITMAP</span></a><span class="k3">*</span></span> you can get from <span class="source-code"><a href="http://www.allegro.cc/manual/al_get_backbuffer"><span class="a">al_get_backbuffer</span></a><span class="k2">(</span><span class="k2">)</span></span>.</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/606662/908131#target">Matthew Leverton</a> said:</div><div class="quote"><p>Either lock the target bitmap or tell the programmer to do it before calling any of the functions.</p></div></div><p>Yes, that.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Mark Oates)</author>
		<pubDate>Wed, 16 Mar 2011 09:42:47 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I overloaded the function so that you can pass a bitmap, display or nothing.  If you pass a display or bitmap, it will lock it.  If you pass nothing, you have to lock it.  I like this.  Should be fun to do up some more. <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" /></p><p><s>deleted old code</s></p><p>Edit: Fixed.  The above code now has both a working line and rect function, all overloaded and working properly.  When I tried the functions normally, without locking any bitmaps or displays, it still drew so many lines that my screen was almost solid colour from them after only a few seconds.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Neil Roy)</author>
		<pubDate>Wed, 16 Mar 2011 10:03:10 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>While such an add-on does not technically belong to the Allegro library itself, I think it would be very helpful if it is in the core distribution, and I don&#39;t think it would be such a great effort. A couple of days, perhaps, for a veteran Allegro developer.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (axilmar)</author>
		<pubDate>Wed, 16 Mar 2011 16:04:55 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Why not copy the functions from Allegro 4, if the goal is to emulate the behaviour of Allegro 4... Also, there is no overloading in C. </p><p>And thirdly, anyone advocating a mode switch please provide a floating point versions of both line drawing and circle drawing functions. I literally spent months trying to get them working, and failed. Separate functions are fine as long as they take integer coordinates though.</p><p>Another thing to check is if it is any faster to draw these things using ALLEGRO_PRIM_POINTS.</p><p>EDIT: Also, all rectangular shapes (rectangles and horizontal + vertical lines) should be implemented using al_draw calls. There&#39;s way too much FUD about the current al_draw functions.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SiegeLord)</author>
		<pubDate>Wed, 16 Mar 2011 19:00:08 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Wouldn&#39;t it be faster to just do all rendering to a memory bitmap instead? The A5 software line resterizer with width set to 0 is likely close to how A4 lines look anyway. Something like:
</p><div class="source-code snippet"><div class="inner"><pre><a href="http://www.allegro.cc/manual/al_set_new_bitmap_flags"><span class="a">al_set_new_bitmap_flags</span></a><span class="k2">(</span>ALLEGRO_MEMORY_BITMAP<span class="k2">)</span><span class="k2">;</span>
<a href="http://www.allegro.cc/manual/screen"><span class="a">screen</span></a> <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>
<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/screen"><span class="a">screen</span></a><span class="k2">)</span><span class="k2">;</span>
...
yay, i can use software rasterization <span class="k1">for</span> everything
...
</pre></div></div><p>

And then at the end of each frame just draw that bitmap. It means there wouldn&#39;t be any locking or texture up and down loading. You&#39;d even have direct pixel access to the screen, just like in A4.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Wed, 16 Mar 2011 19:37:39 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I just created those on the fly as I read this topic actually.  I have no desire to redo all the Allegro 4 functions.  I&#39;ll probably create a few useful functions for myself.  Using C++ for a change because I do like overloading for this type of thing. </p><p>I may just rename them so they can be interchanged with A4 functions. Would make porting some of my own stuff easier.  I may try my hand at wrapping them around the A5 line() functions etc... &lt;shrug&gt;  gives me something to do. <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" /></p><p>Edit: after more thinking, I may just redo these in C and leave the locking etc... up to the user.  Would make my life easier.  <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" /></p><p>Okay, I redone them in &#39;C&#39;.  There are 3 functions that all take a bitmap perimeter, they all lock the bitmap and draw very fast.  For example, I tested the a5_rectfill() from 10,10 - 790-590 and it was instant, at least on my machine. To draw to the display and not a bitmap, you simply get the bitmap from the backbuffer with <span class="source-code"><a href="http://www.allegro.cc/manual/ALLEGRO_BITMAP"><span class="a">ALLEGRO_BITMAP</span></a> <span class="k3">*</span>bitmap <span class="k3">=</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>.  This seems to be a nice compromise and matches the Allegro 4 functions.  I don&#39;t think I have the skill to duplicate Allegro 4 functions, but I can make some simple drawing functions to plot pixels like A4 did.</p><div class="source-code"><div class="toolbar"><span class="name">A5_PixeDraw.h</span><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">#ifndef _A5_PixelDraw_h_</span>
<span class="number">  2</span><span class="p">#define _A5_PixelDraw_h_</span>
<span class="number">  3</span>
<span class="number">  4</span><span class="p">#ifdef __cplusplus</span>
<span class="number">  5</span>   <span class="k1">extern</span> <span class="s">"C"</span> <span class="k2">{</span>
<span class="number">  6</span><span class="p">#endif</span>
<span class="number">  7</span>
<span class="number">  8</span><span class="k1">extern</span> <span class="k1">void</span> a5_line<span class="k2">(</span><a href="http://www.allegro.cc/manual/ALLEGRO_BITMAP"><span class="a">ALLEGRO_BITMAP</span></a> <span class="k3">*</span>bitmap, <span class="k1">int</span> start_x, <span class="k1">int</span> start_y, <span class="k1">int</span> dest_x, <span class="k1">int</span> dest_y, <a href="http://www.allegro.cc/manual/ALLEGRO_COLOR"><span class="a">ALLEGRO_COLOR</span></a> colour<span class="k2">)</span><span class="k2">;</span>
<span class="number">  9</span><span class="k1">extern</span> <span class="k1">void</span> a5_rect<span class="k2">(</span><a href="http://www.allegro.cc/manual/ALLEGRO_BITMAP"><span class="a">ALLEGRO_BITMAP</span></a> <span class="k3">*</span>bitmap, <span class="k1">int</span> start_x, <span class="k1">int</span> start_y, <span class="k1">int</span> dest_x, <span class="k1">int</span> dest_y, <a href="http://www.allegro.cc/manual/ALLEGRO_COLOR"><span class="a">ALLEGRO_COLOR</span></a> colour<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 10</span><span class="k1">extern</span> <span class="k1">void</span> a5_rectfill<span class="k2">(</span><a href="http://www.allegro.cc/manual/ALLEGRO_BITMAP"><span class="a">ALLEGRO_BITMAP</span></a> <span class="k3">*</span>bitmap, <span class="k1">int</span> start_x, <span class="k1">int</span> start_y, <span class="k1">int</span> dest_x, <span class="k1">int</span> dest_y, <a href="http://www.allegro.cc/manual/ALLEGRO_COLOR"><span class="a">ALLEGRO_COLOR</span></a> colour<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 11</span>
<span class="number"> 12</span><span class="p">#ifdef __cplusplus</span>
<span class="number"> 13</span>   <span class="k2">}</span>
<span class="number"> 14</span><span class="p">#endif</span>
<span class="number"> 15</span>
<span class="number"> 16</span><span class="p">#endif /*_A5_PixelDraw_h_ */</span>
</div></div><p>

</p><div class="source-code"><div class="toolbar"><span class="name">A5_PixeDraw.c</span><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;stdlib.h&gt; /* abs() */</span>
<span class="number">   2</span><span class="p">#include &lt;allegro5/allegro.h&gt;</span>
<span class="number">   3</span><span class="p">#include "A5_PixelDraw.h"</span>
<span class="number">   4</span>
<span class="number">   5</span>
<span class="number">   6</span><span class="k1">void</span> a5_line<span class="k2">(</span><a href="http://www.allegro.cc/manual/ALLEGRO_BITMAP"><span class="a">ALLEGRO_BITMAP</span></a> <span class="k3">*</span>bitmap, <span class="k1">int</span> start_x, <span class="k1">int</span> start_y, <span class="k1">int</span> dest_x, <span class="k1">int</span> dest_y, <a href="http://www.allegro.cc/manual/ALLEGRO_COLOR"><span class="a">ALLEGRO_COLOR</span></a> colour<span class="k2">)</span>
<span class="number">   7</span><span class="k2">{</span>
<span class="number">   8</span>   <span class="c">/* Bresenham's line algorithm */</span>
<span class="number">   9</span>   <span class="k1">int</span> x0 <span class="k3">=</span> start_x<span class="k2">;</span>
<span class="number">  10</span>   <span class="k1">int</span> x1 <span class="k3">=</span> dest_x<span class="k2">;</span>
<span class="number">  11</span>   <span class="k1">int</span> y0 <span class="k3">=</span> start_y<span class="k2">;</span>
<span class="number">  12</span>   <span class="k1">int</span> y1 <span class="k3">=</span> dest_y<span class="k2">;</span>
<span class="number">  13</span>   <span class="k1">int</span> sx, sy, err, e2<span class="k2">;</span>
<span class="number">  14</span>   <span class="k1">int</span> dx <span class="k3">=</span> <a href="http://www.delorie.com/djgpp/doc/libc/libc_38.html" target="_blank">abs</a><span class="k2">(</span>x1-x0<span class="k2">)</span><span class="k2">;</span>
<span class="number">  15</span>   <span class="k1">int</span> dy <span class="k3">=</span> <a href="http://www.delorie.com/djgpp/doc/libc/libc_38.html" target="_blank">abs</a><span class="k2">(</span>y1-y0<span class="k2">)</span><span class="k2">;</span>
<span class="number">  16</span>   <span class="k1">int</span> x,y<span class="k2">;</span>
<span class="number">  17</span>
<span class="number">  18</span>   <span class="k1">if</span><span class="k2">(</span>x0 <span class="k3">&lt;</span> x1<span class="k2">)</span> sx <span class="k3">=</span> <span class="n">1</span><span class="k2">;</span> <span class="k1">else</span> sx <span class="k3">=</span> <span class="k3">-</span><span class="n">1</span><span class="k2">;</span>
<span class="number">  19</span>   <span class="k1">if</span><span class="k2">(</span>y0 <span class="k3">&lt;</span> y1<span class="k2">)</span> sy <span class="k3">=</span> <span class="n">1</span><span class="k2">;</span> <span class="k1">else</span> sy <span class="k3">=</span> <span class="k3">-</span><span class="n">1</span><span class="k2">;</span>
<span class="number">  20</span>   err <span class="k3">=</span> dx-dy<span class="k2">;</span>
<span class="number">  21</span>
<span class="number">  22</span>   <a href="http://www.allegro.cc/manual/al_lock_bitmap"><span class="a">al_lock_bitmap</span></a><span class="k2">(</span>bitmap, <a href="http://www.allegro.cc/manual/al_get_bitmap_format"><span class="a">al_get_bitmap_format</span></a><span class="k2">(</span>bitmap<span class="k2">)</span>, ALLEGRO_LOCK_WRITEONLY<span class="k2">)</span><span class="k2">;</span>
<span class="number">  23</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>bitmap<span class="k2">)</span><span class="k2">;</span>
<span class="number">  24</span>
<span class="number">  25</span>   <span class="k1">if</span> <span class="k2">(</span>x0 <span class="k3">=</span><span class="k3">=</span> x1<span class="k2">)</span> <span class="k2">{</span>
<span class="number">  26</span>      <span class="k1">for</span> <span class="k2">(</span>y<span class="k3">=</span>y0<span class="k2">;</span> y<span class="k3">!</span><span class="k3">=</span>y1<span class="k2">;</span> y<span class="k3">+</span><span class="k3">=</span>sy<span class="k2">)</span> <a href="http://www.allegro.cc/manual/al_put_pixel"><span class="a">al_put_pixel</span></a><span class="k2">(</span>x0, y, colour<span class="k2">)</span><span class="k2">;</span>
<span class="number">  27</span>      <a href="http://www.allegro.cc/manual/al_put_pixel"><span class="a">al_put_pixel</span></a><span class="k2">(</span>x1, y1, colour<span class="k2">)</span><span class="k2">;</span>
<span class="number">  28</span>      <a href="http://www.allegro.cc/manual/al_unlock_bitmap"><span class="a">al_unlock_bitmap</span></a><span class="k2">(</span>bitmap<span class="k2">)</span><span class="k2">;</span>
<span class="number">  29</span>      <span class="k1">return</span><span class="k2">;</span>
<span class="number">  30</span>   <span class="k2">}</span>
<span class="number">  31</span>   <span class="k1">if</span> <span class="k2">(</span>y0 <span class="k3">=</span><span class="k3">=</span> y1<span class="k2">)</span> <span class="k2">{</span>
<span class="number">  32</span>      <span class="k1">for</span> <span class="k2">(</span>x<span class="k3">=</span>x0<span class="k2">;</span> x<span class="k3">!</span><span class="k3">=</span>x1<span class="k2">;</span> x<span class="k3">+</span><span class="k3">=</span>sx<span class="k2">)</span> <a href="http://www.allegro.cc/manual/al_put_pixel"><span class="a">al_put_pixel</span></a><span class="k2">(</span>x, y0, colour<span class="k2">)</span><span class="k2">;</span>
<span class="number">  33</span>      <a href="http://www.allegro.cc/manual/al_put_pixel"><span class="a">al_put_pixel</span></a><span class="k2">(</span>x1, y1, colour<span class="k2">)</span><span class="k2">;</span>
<span class="number">  34</span>      <a href="http://www.allegro.cc/manual/al_unlock_bitmap"><span class="a">al_unlock_bitmap</span></a><span class="k2">(</span>bitmap<span class="k2">)</span><span class="k2">;</span>
<span class="number">  35</span>      <span class="k1">return</span><span class="k2">;</span>
<span class="number">  36</span>   <span class="k2">}</span>
<span class="number">  37</span>
<span class="number">  38</span>   <span class="k1">while</span><span class="k2">(</span>x0 <span class="k3">!</span><span class="k3">=</span> x1 <span class="k3">&amp;</span><span class="k3">&amp;</span> y0 <span class="k3">!</span><span class="k3">=</span> y1<span class="k2">)</span> <span class="k2">{</span>
<span class="number">  39</span>      <a href="http://www.allegro.cc/manual/al_put_pixel"><span class="a">al_put_pixel</span></a><span class="k2">(</span>x0, y0, colour<span class="k2">)</span><span class="k2">;</span>
<span class="number">  40</span>      e2 <span class="k3">=</span> <span class="n">2</span><span class="k3">*</span>err<span class="k2">;</span>
<span class="number">  41</span>      <span class="k1">if</span><span class="k2">(</span>e2 <span class="k3">&gt;</span> <span class="k3">-</span>dy<span class="k2">)</span> <span class="k2">{</span>
<span class="number">  42</span>         err <span class="k3">-</span><span class="k3">=</span> dy<span class="k2">;</span>
<span class="number">  43</span>         x0 <span class="k3">+</span><span class="k3">=</span> sx<span class="k2">;</span>
<span class="number">  44</span>      <span class="k2">}</span>
<span class="number">  45</span>      <span class="k1">if</span><span class="k2">(</span>e2 <span class="k3">&lt;</span>  dx<span class="k2">)</span> <span class="k2">{</span>
<span class="number">  46</span>         err <span class="k3">+</span><span class="k3">=</span> dx<span class="k2">;</span>
<span class="number">  47</span>         y0 <span class="k3">+</span><span class="k3">=</span> sy<span class="k2">;</span>
<span class="number">  48</span>      <span class="k2">}</span>
<span class="number">  49</span>   <span class="k2">}</span>
<span class="number">  50</span>   <a href="http://www.allegro.cc/manual/al_unlock_bitmap"><span class="a">al_unlock_bitmap</span></a><span class="k2">(</span>bitmap<span class="k2">)</span><span class="k2">;</span>
<span class="number">  51</span>
<span class="number">  52</span>   <span class="k1">return</span><span class="k2">;</span>
<span class="number">  53</span><span class="k2">}</span>
<span class="number">  54</span>
<span class="number">  55</span><span class="c">/***************************************/</span>
<span class="number">  56</span>
<span class="number">  57</span><span class="k1">void</span> a5_rect<span class="k2">(</span><a href="http://www.allegro.cc/manual/ALLEGRO_BITMAP"><span class="a">ALLEGRO_BITMAP</span></a> <span class="k3">*</span>bitmap, <span class="k1">int</span> start_x, <span class="k1">int</span> start_y, <span class="k1">int</span> dest_x, <span class="k1">int</span> dest_y, <a href="http://www.allegro.cc/manual/ALLEGRO_COLOR"><span class="a">ALLEGRO_COLOR</span></a> colour<span class="k2">)</span>
<span class="number">  58</span><span class="k2">{</span>
<span class="number">  59</span>   <span class="k1">if</span> <span class="k2">(</span>start_x<span class="k3">=</span><span class="k3">=</span>dest_x <span class="k3">|</span><span class="k3">|</span> start_y<span class="k3">=</span><span class="k3">=</span>dest_y<span class="k2">)</span> <span class="k2">{</span>
<span class="number">  60</span>      a5_line<span class="k2">(</span>bitmap, start_x, start_y, dest_x, dest_y, colour<span class="k2">)</span><span class="k2">;</span>
<span class="number">  61</span>      <span class="k1">return</span><span class="k2">;</span>
<span class="number">  62</span>   <span class="k2">}</span>
<span class="number">  63</span>
<span class="number">  64</span>   <span class="k1">int</span> sx, sy, dx, dy<span class="k2">;</span>
<span class="number">  65</span>   <span class="k1">if</span> <span class="k2">(</span>start_x <span class="k3">&lt;</span> dest_x<span class="k2">)</span> <span class="k2">{</span>
<span class="number">  66</span>      sx <span class="k3">=</span> start_x<span class="k2">;</span>
<span class="number">  67</span>      dx <span class="k3">=</span> dest_x<span class="k2">;</span>
<span class="number">  68</span>   <span class="k2">}</span>
<span class="number">  69</span>   <span class="k1">else</span> <span class="k2">{</span>
<span class="number">  70</span>      sx <span class="k3">=</span> dest_x<span class="k2">;</span>
<span class="number">  71</span>      dx <span class="k3">=</span> start_x<span class="k2">;</span>
<span class="number">  72</span>   <span class="k2">}</span>
<span class="number">  73</span>
<span class="number">  74</span>   <span class="k1">if</span> <span class="k2">(</span>start_y <span class="k3">&lt;</span> dest_y<span class="k2">)</span> <span class="k2">{</span>
<span class="number">  75</span>      sy <span class="k3">=</span> start_y<span class="k2">;</span>
<span class="number">  76</span>      dy <span class="k3">=</span> dest_y<span class="k2">;</span>
<span class="number">  77</span>   <span class="k2">}</span>
<span class="number">  78</span>   <span class="k1">else</span> <span class="k2">{</span>
<span class="number">  79</span>      sy <span class="k3">=</span> dest_y<span class="k2">;</span>
<span class="number">  80</span>      dy <span class="k3">=</span> start_y<span class="k2">;</span>
<span class="number">  81</span>   <span class="k2">}</span>
<span class="number">  82</span>
<span class="number">  83</span>   a5_line<span class="k2">(</span>bitmap, sx, sy, dx, sy, colour<span class="k2">)</span><span class="k2">;</span>
<span class="number">  84</span>   a5_line<span class="k2">(</span>bitmap, dx, sy, dx, dy, colour<span class="k2">)</span><span class="k2">;</span>
<span class="number">  85</span>   a5_line<span class="k2">(</span>bitmap, dx, dy, sx, dy, colour<span class="k2">)</span><span class="k2">;</span>
<span class="number">  86</span>   a5_line<span class="k2">(</span>bitmap, sx, dy, sx, sy, colour<span class="k2">)</span><span class="k2">;</span>
<span class="number">  87</span>
<span class="number">  88</span>   <span class="k1">return</span><span class="k2">;</span>
<span class="number">  89</span><span class="k2">}</span>
<span class="number">  90</span>
<span class="number">  91</span><span class="c">/***************************************/</span>
<span class="number">  92</span>
<span class="number">  93</span><span class="k1">void</span> a5_rectfill<span class="k2">(</span><a href="http://www.allegro.cc/manual/ALLEGRO_BITMAP"><span class="a">ALLEGRO_BITMAP</span></a> <span class="k3">*</span>bitmap, <span class="k1">int</span> start_x, <span class="k1">int</span> start_y, <span class="k1">int</span> dest_x, <span class="k1">int</span> dest_y, <a href="http://www.allegro.cc/manual/ALLEGRO_COLOR"><span class="a">ALLEGRO_COLOR</span></a> colour<span class="k2">)</span>
<span class="number">  94</span><span class="k2">{</span>
<span class="number">  95</span>   <span class="k1">int</span> temp, y<span class="k2">;</span>
<span class="number">  96</span>
<span class="number">  97</span>   <span class="c">/* if start x is greater than destination x, swap them. */</span>
<span class="number">  98</span>   <span class="k1">if</span> <span class="k2">(</span>start_x <span class="k3">&gt;</span> dest_x<span class="k2">)</span> <span class="k2">{</span>
<span class="number">  99</span>      temp <span class="k3">=</span> start_x<span class="k2">;</span>
<span class="number"> 100</span>      start_x <span class="k3">=</span> dest_x<span class="k2">;</span>
<span class="number"> 101</span>      dest_x <span class="k3">=</span> temp<span class="k2">;</span>
<span class="number"> 102</span>   <span class="k2">}</span>
<span class="number"> 103</span>
<span class="number"> 104</span>   <span class="c">/* if start y is greater than destination y, swap them. */</span>
<span class="number"> 105</span>   <span class="k1">if</span> <span class="k2">(</span>start_y <span class="k3">&gt;</span> dest_y<span class="k2">)</span> <span class="k2">{</span>
<span class="number"> 106</span>      temp <span class="k3">=</span> start_y<span class="k2">;</span>
<span class="number"> 107</span>      start_y <span class="k3">=</span> dest_y<span class="k2">;</span>
<span class="number"> 108</span>      dest_y <span class="k3">=</span> temp<span class="k2">;</span>
<span class="number"> 109</span>   <span class="k2">}</span>
<span class="number"> 110</span>
<span class="number"> 111</span>   <span class="k1">if</span> <span class="k2">(</span>start_x<span class="k3">=</span><span class="k3">=</span>dest_x <span class="k3">|</span><span class="k3">|</span> start_y<span class="k3">=</span><span class="k3">=</span>dest_y<span class="k2">)</span> <span class="k2">{</span>
<span class="number"> 112</span>      a5_line<span class="k2">(</span>bitmap, start_x, start_y, dest_x, dest_y, colour<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 113</span>      <span class="k1">return</span><span class="k2">;</span>
<span class="number"> 114</span>   <span class="k2">}</span>
<span class="number"> 115</span>
<span class="number"> 116</span>   <span class="k1">for</span> <span class="k2">(</span>y<span class="k3">=</span>start_y<span class="k2">;</span> y<span class="k3">&lt;</span>dest_y<span class="k2">;</span> y<span class="k3">+</span><span class="k3">+</span><span class="k2">)</span> <span class="k2">{</span>
<span class="number"> 117</span>      a5_line<span class="k2">(</span>bitmap, start_x, y, dest_x, y, colour<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 118</span>   <span class="k2">}</span>
<span class="number"> 119</span>
<span class="number"> 120</span>   <span class="k1">return</span><span class="k2">;</span>
<span class="number"> 121</span><span class="k2">}</span>
</div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Neil Roy)</author>
		<pubDate>Wed, 16 Mar 2011 23:18:25 +0000</pubDate>
	</item>
</rss>
