<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Line Drawing with OpenGL</title>
		<link>http://www.allegro.cc/forums/view/616739</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Tue, 14 Feb 2017 13:38:06 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hello again. I&#39;m sorry to make another thread so quickly, but this is really baffling me. In my game, I have a transparent minimap that&#39;s layered over gameplay. It worked fine in Direct3D, but immediately broke when I switched to OpenGL with al_set_new_display_flags(ALLEGRO_OPENGL).</p><p><span class="remote-thumbnail"><span class="json">{"name":"TIABOH9.png","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/4\/9\/4971d386b780e34bec199cea56f672d3.png","w":680,"h":223,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/4\/9\/4971d386b780e34bec199cea56f672d3"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/4/9/4971d386b780e34bec199cea56f672d3-240.jpg" alt="TIABOH9.png" width="240" height="78" /></span></p><p>Basically, I&#39;m doing a series of very fine pixel-perfect line drawing operations inside each cell. There&#39;s no scaling, rotating or even translations going on. Just drawing to a minimap texture then blitting that to the window with al_draw_bitmap(map_texture, 0, 0, 0). No changes were made to my code except switching to OpenGL rendering and everything else (rectangle drawing, texture blitting, pixel scaling) is working perfectly.</p><p>If you look at the lines in the north/south sides of cells sometimes they&#39;re 2-thick, 1-thick or not even drawn. Is this an issue with my code? Or a quirk with how allegro handles OpenGL?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (DragonDePlatino)</author>
		<pubDate>Tue, 14 Feb 2017 03:05:50 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>See <a href="http://liballeg.org/a5docs/trunk/primitives.html#pixel-precise-output">http://liballeg.org/a5docs/trunk/primitives.html#pixel-precise-output</a>.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SiegeLord)</author>
		<pubDate>Tue, 14 Feb 2017 09:50:38 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Oh...I figured as such. It&#39;s weird how that happens with OpenGL but not DirectX, though. Guess I&#39;ll implement all of my line drawing with al_draw_filled_rectangle() then.</p><p><span class="remote-thumbnail"><span class="json">{"name":"BmDgsQs.png","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/e\/a\/ea66e65a42b582a0c34907337fc633c4.png","w":340,"h":223,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/e\/a\/ea66e65a42b582a0c34907337fc633c4"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/e/a/ea66e65a42b582a0c34907337fc633c4-240.jpg" alt="BmDgsQs.png" width="240" height="157" /></span></p><p>Thanks for your help again.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (DragonDePlatino)</author>
		<pubDate>Tue, 14 Feb 2017 10:55:29 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>You can do <span class="source-code"><a href="http://www.allegro.cc/manual/al_draw_line"><span class="a">al_draw_line</span></a></span> with thickness &gt; 0 and it&#39;ll be consistent as well (assuming you set your coordinates appropriately as that link describes). There are two sources of differences between D3D and OpenGL. For thickness == 0, the drawing process is implementation dependent, so that can differ between D3D and OpenGL on the same system, and between OpenGL&#39;s on differen systems. For thickness &gt; 0, and if you&#39;re right on the boundary (e.g. you draw a line with thickness == 1 with a coordinate of 0, 0) then which pixel will get colored will also be somewhat implementation dependent.</p><p>If you just follow the recommendations in that link, it&#39;ll work the same anywhere.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SiegeLord)</author>
		<pubDate>Tue, 14 Feb 2017 13:05:44 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I think I&#39;ll just stick to the rectangle drawing. Following the advice of that link, this is how I&#39;d draw the lines on the south sides of pits (the red tiles):</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="c">/* Check for non-pit south of cell. */</span>
<span class="number"> 2</span><span class="k1">if</span> <span class="k2">(</span>level_solidity<span class="k2">(</span>pos_add<span class="k2">(</span>cell, dir_pos<span class="k2">[</span>DIR_SOUTH<span class="k2">]</span><span class="k2">)</span><span class="k2">)</span> <span class="k3">!</span><span class="k3">=</span> SOL_PIT<span class="k2">)</span> <span class="k2">{</span>
<span class="number"> 3</span>  <a href="http://www.allegro.cc/manual/al_draw_line"><span class="a">al_draw_line</span></a><span class="k2">(</span>  cell.x <span class="k3">*</span> cell_size.x <span class="k3">+</span> <span class="n">0</span>.<span class="n">5</span>,
<span class="number"> 4</span>          cell.y <span class="k3">*</span> cell_size.y <span class="k3">+</span> cell_size.y <span class="k3">-</span> <span class="n">0</span>.<span class="n">5</span>,
<span class="number"> 5</span>          cell.x <span class="k3">*</span> cell_size.x <span class="k3">+</span> cell_size.x <span class="k3">+</span> <span class="n">0</span>.<span class="n">5</span>,
<span class="number"> 6</span>          cell.y <span class="k3">*</span> cell_size.y <span class="k3">+</span> cell_size.y <span class="k3">-</span> <span class="n">0</span>.<span class="n">5</span>,
<span class="number"> 7</span>          pit_edge_color, <span class="n">1</span>
<span class="number"> 8</span>  <span class="k2">)</span><span class="k2">;</span>
<span class="number"> 9</span><span class="k2">}</span>
</div></div><p>

and with rectangle drawing:</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="c">/* Check for non-pit south of cell. */</span>
<span class="number"> 2</span><span class="k1">if</span> <span class="k2">(</span>level_solidity<span class="k2">(</span>pos_add<span class="k2">(</span>cell, dir_pos<span class="k2">[</span>DIR_SOUTH<span class="k2">]</span><span class="k2">)</span><span class="k2">)</span> <span class="k3">!</span><span class="k3">=</span> SOL_PIT<span class="k2">)</span> <span class="k2">{</span>
<span class="number"> 3</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>  cell.x <span class="k3">*</span> cell_size.x,
<span class="number"> 4</span>                cell.y <span class="k3">*</span> cell_size.y <span class="k3">+</span> cell_size.y <span class="k3">-</span> <span class="n">1</span>,
<span class="number"> 5</span>                cell.x <span class="k3">*</span> cell_size.x <span class="k3">+</span> cell_size.x,
<span class="number"> 6</span>                cell.y <span class="k3">*</span> cell_size.y <span class="k3">+</span> cell_size.y,
<span class="number"> 7</span>                pit_edge_color
<span class="number"> 8</span>  <span class="k2">)</span><span class="k2">;</span>
<span class="number"> 9</span><span class="k2">}</span>
</div></div><p>

Both of these methods work perfectly with both DirectX and OpenGL. However, the line drawing feels a little more verbose. It would be neat if allegro had macros for drawing straight pixel-perfect lines that pre-calculated all of the middle-pixel-fragment-rubbish for you. Something like:</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">#define    al_draw_hline(x, y, dx, color)    al_draw_line(x + 0.5, y + 0.5, x + dx + 0.5, y + 0.5, color, 0)</span>
<span class="number"> 2</span><span class="p">#define    al_draw_vline(x, y, dy, color)    al_draw_line(x + 0.5, y + 0.5, x + 0.5, y + dy + 0.5, color, 0)</span>
</div></div><p>

So then the drawing operation would become...</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="c">/* Check for non-pit south of cell. */</span>
<span class="number"> 2</span><span class="k1">if</span> <span class="k2">(</span>level_solidity<span class="k2">(</span>pos_add<span class="k2">(</span>cell, dir_pos<span class="k2">[</span>DIR_SOUTH<span class="k2">]</span><span class="k2">)</span><span class="k2">)</span> <span class="k3">!</span><span class="k3">=</span> SOL_PIT<span class="k2">)</span> <span class="k2">{</span>
<span class="number"> 3</span>al_draw_hline<span class="k2">(</span>  cell.x <span class="k3">*</span> cell_size.x, cell.y <span class="k3">*</span> cell_size.y <span class="k3">+</span> cell_size.y <span class="k3">-</span> <span class="n">1</span>,
<span class="number"> 4</span>        cell_size.x, pit_edge_color<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 5</span><span class="k2">}</span>
</div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (DragonDePlatino)</author>
		<pubDate>Tue, 14 Feb 2017 13:38:06 +0000</pubDate>
	</item>
</rss>
