<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Pixel question</title>
		<link>http://www.allegro.cc/forums/view/615563</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Mon, 20 Jul 2015 01:56:18 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hello</p><p>I&#39;m having fun with Allegro and &#39;D&#39; (thanks SiegeLord!) but have a question about pixel plotting.</p><p>Dumping a 2D array to the screen pixel-by-pixel works as expected but only if the window is square, eg 640 x 640 rather than say 800x600.</p><p>Having read the wiki about primitive pixel plotting I imagine this is something to do with drawing being related to the pixel centres being offset 0.5 &#39;pixel units&#39; (sorry I&#39;m struggling to put this into words clearly!), although it could be that integers are being supplied to the function (although the pattern of missing pixels in the output doesn&#39;t seem to indicate so).</p><p>I can fix the problem by adding 0.5 to the co-ords supplied to al_draw_pixel() so it will render correctly regardless of window proportions - see below - but I&#39;d like to know if this fix will work in all cases (proportions/resolution/hardware) or whether there&#39;s a better way to ensure that when I need pixel 100, 100 plotted that is what happens.</p><div class="source-code snippet"><div class="inner"><pre>  foreach<span class="k2">(</span>y<span class="k2">;</span> <span class="n">0</span>..MapSize<span class="k2">)</span>
  <span class="k2">{</span>
    foreach<span class="k2">(</span>x<span class="k2">;</span> <span class="n">0</span>..MapSize<span class="k2">)</span>
    <span class="k2">{</span>
        ......blah blah
        <a href="http://www.allegro.cc/manual/al_draw_pixel"><span class="a">al_draw_pixel</span></a><span class="k2">(</span>x<span class="k3">+</span><span class="n">0</span>.<span class="n">5</span>, y<span class="k3">+</span><span class="n">0</span>.<span class="n">5</span>, c<span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

Speed isn&#39;t a major concern as the plotting only happens during map generation.</p><p>This is on Linux/Allegro 5/DMD with a Radeon HD6400</p><p>Any help or advice welcome <img src="http://www.allegro.cc/forums/smileys/cheesy.gif" alt=":D" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (picnic)</author>
		<pubDate>Sun, 19 Jul 2015 21:48:14 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>If a pixel center is at 0.5 (0.5, 1.5, 2.5, ...), shouldn&#39;t you subtract 0.5 from all coordinates? Otherwise, you&#39;ll be off-by-one and missing the first row/column of the screen.</p><p>Someone correct me if I&#39;m wrong, I don&#39;t have Allegro 5 up at the moment.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Chris Katko)</author>
		<pubDate>Sun, 19 Jul 2015 22:58:07 +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/615563/1015204#target">Chris Katko</a> said:</div><div class="quote"><p> If a pixel center is at 0.5 (0.5, 1.5, 2.5, ...), shouldn&#39;t you subtract 0.5 from all coordinates? Otherwise, you&#39;ll be off-by-one and missing the first row/column of the screen.</p></div></div><p>Nope, you add 0.5.  Under the traditional approach, the top-left pixel is (0, 0), but with the new co-ordinate system, it&#39;s (0.5, 0.5).
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (LennyLen)</author>
		<pubDate>Sun, 19 Jul 2015 23:26:23 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>In A5 you want to center on .5 and draw outward from there using the thickness parameter. See <a href="https://www.allegro.cc/manual/5/primitives.html">https://www.allegro.cc/manual/5/primitives.html</a> for details.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Sun, 19 Jul 2015 23:39:23 +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/615563/1015207#target">LennyLen</a> said:</div><div class="quote"><p>
Nope, you add 0.5. Under the traditional approach, the top-left pixel is (0, 0), but with the new co-ordinate system, it&#39;s (0.5, 0.5).
</p></div></div><p>
Yeah, you&#39;re right. I had a brainfart because I was thinking 1,1 was the first pixel, being moved up-and-to-the-left.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Chris Katko)</author>
		<pubDate>Sun, 19 Jul 2015 23:49:15 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Thanks for the replies but I don&#39;t understand why the pixels aren&#39;t properly positioned when the window is anything other than square.</p><p>I read that wiki page which is why I suspected adding 0.5 might fix things BUT that page makes no mention of al_draw_pixel(), only the other primitive drawing routines (line, ellipse etc).</p><p>Just to recap my original question, will adding 0.5 to each co-ordinate passed to al_draw_pixel() fix things whatever the resolution/window proportions/display hardware?</p><p>Oh &#39;ang on, <a href="https://www.allegro.cc/manual/5/al_draw_pixel">https://www.allegro.cc/manual/5/al_draw_pixel</a> mentions al_put_pixel() - I didn&#39;t know about that routine, maybe it does what I need.</p><p>Testing...</p><p>EDIT: Yeah that works regardless of window proportions but it is horribly slow - no matter I like looking at a black screen during map generation <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (picnic)</author>
		<pubDate>Mon, 20 Jul 2015 00:07:10 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>The pixels are centered on 0.5,0.5, so yes.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Mon, 20 Jul 2015 00:26:33 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>You should use al_put_pixel(), which is in pixel coordinates of a bitmap target.</p><p>If you&#39;re using al_draw_pixel() then you aren&#39;t drawing pixel, but rather a 1x1 square, which could be affected by transforms, rotations, scaling, projection, etc.  With al_draw_pixel(), you&#39;re working with <i>screen</i> coordinates, rather that bitmap&#39;s pixel coordinates.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Mark Oates)</author>
		<pubDate>Mon, 20 Jul 2015 01:50:09 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Thanks Mark, that&#39;s clear.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (picnic)</author>
		<pubDate>Mon, 20 Jul 2015 01:56:18 +0000</pubDate>
	</item>
</rss>
