<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>[OpenGL] Render a polygon outline with a fill</title>
		<link>http://www.allegro.cc/forums/view/590317</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Thu, 01 Mar 2007 15:25:25 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Is it possible to draw a polygon, whether it be a triangle or a 100-vertex irregular shape, and have it fill up with a texture, or a different RGBA colour; without iterating twice with 2 different glBegin/glEnds (or equivilent) and sending in the same coordinates.</p><p>See attachment: There are thick lines on the perimeter of the polygon, but the inside is shaded differently.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Archon)</author>
		<pubDate>Wed, 28 Feb 2007 19:00:48 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>You need 2 dedicated primitives, there is no way around that.<br />You could use vertex arrays or other optimizations to avoid sending the vertex data twice.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Tobias Dammers)</author>
		<pubDate>Wed, 28 Feb 2007 19:04:09 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Alright.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Archon)</author>
		<pubDate>Thu, 01 Mar 2007 07:37:22 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Probably wrong here with what your looking for but if you just want to render an outline, Draw the first object, translate back (into the screen) by a small amount and render using GL_LINE and change the line width.</p><p>And rather than vertex arrays, if you support opengl 2.0??? Then you can use the VBO gl extension which saves the vertex data on the GPU rather in RAM (which is what vertex arrays do... pretty sure).
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (adam450)</author>
		<pubDate>Thu, 01 Mar 2007 13:59:23 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Try the following:</p><div class="source-code snippet"><div class="inner"><pre>glEnable<span class="k2">(</span>GL_POLYGON_OFFSET_FILL<span class="k2">)</span><span class="k2">;</span> <span class="c">// Avoid Stitching!</span>
glPolygonOffset<span class="k2">(</span><span class="n">1</span>.<span class="n">0</span>, <span class="n">1</span>.<span class="n">0</span><span class="k2">)</span><span class="k2">;</span>
glCallList<span class="k2">(</span>yourPolygon<span class="k2">)</span><span class="k2">;</span>
glDisable<span class="k2">(</span>GL_POLYGON_OFFSET_FILL<span class="k2">)</span><span class="k2">;</span>

glColor3v<span class="k2">(</span>yourColorArray<span class="k2">)</span><span class="k2">;</span> <span class="c">// Color for your polygon border</span>
glPolygonMode<span class="k2">(</span>GL_FRONT_AND_BACK, GL_LINE<span class="k2">)</span><span class="k2">;</span>
glCallList<span class="k2">(</span>yourPolygon<span class="k2">)</span><span class="k2">;</span> <span class="c">// Call the same rendering routine for the previous polygon.</span>
glPolygonMode<span class="k2">(</span>GL_FRONT_AND_BACK, GL_FILL<span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

The code is slightly modified from an example from the OpenGL Redbook 5th edition.  GL_POLYGON_OFFSET munges the Z-values for all polygon rendering (in this case, all polygon fill operations) so you don&#39;t see stitching from two Z-values too close together for the renderer to differentiate (in short, it ensures that the line actually comes out on top of the filled portion of the polygon, as opposed to fading in/out or stitching around the polygon).  Of course, this code segment is currently untested, I&#39;m probably going to test it tonight just to ensure it actually works.  The values passed to glPolygonOffset might need to be tweaked, for example.</p><p>You&#39;ll need to set the line width to something sane as well.</p><p>EDIT:  Hmm, interesting, the underscores in that last line of code are not rendering in Firefox 2.0 <img src="http://www.allegro.cc/forums/smileys/undecided.gif" alt=":-/" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Carrus85)</author>
		<pubDate>Thu, 01 Mar 2007 15:25:25 +0000</pubDate>
	</item>
</rss>
