|
[OpenGL] Render a polygon outline with a fill |
Archon
Member #4,195
January 2004
|
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. See attachment: There are thick lines on the perimeter of the polygon, but the inside is shaded differently. |
Tobias Dammers
Member #2,604
August 2002
|
You need 2 dedicated primitives, there is no way around that. --- |
Archon
Member #4,195
January 2004
|
Alright. |
adam450
Member #5,460
January 2005
|
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. 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). |
Carrus85
Member #2,633
August 2002
|
Try the following: glEnable(GL_POLYGON_OFFSET_FILL); // Avoid Stitching! glPolygonOffset(1.0, 1.0); glCallList(yourPolygon); glDisable(GL_POLYGON_OFFSET_FILL); glColor3v(yourColorArray); // Color for your polygon border glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); glCallList(yourPolygon); // Call the same rendering routine for the previous polygon. glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); 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'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'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. You'll need to set the line width to something sane as well. EDIT: Hmm, interesting, the underscores in that last line of code are not rendering in Firefox 2.0
|
|