Opengl Polygonoffset
Introduction
It is often quite useful to accentuate the edges of your objects by rendering your object once in fill mode and once in line mode. This often produces unsatisfactory results as the line may move into and out of the polygon. This effect is commonly known as stitching.
You may have also noticed in the past that when rendering two polygons that overlap each other, Z-fighting occurs and parts of each polygon are rendered.
The results of stitching and z-fighting can be seen in the figures below.
![Opengl Polygonoffset - wwweurope - wwweurope的博客 Stitching Effect](http://img.bimg.126.net/photo/kCXHnDG4VadrzH0fIFBu_Q==/5405726927745087761.jpg)
![Opengl Polygonoffset - wwweurope - wwweurope的博客 Stitching Effect](http://img.bimg.126.net/photo/usa-Qd1EWAWb3FYHmQYS9A==/5405726927745087763.jpg)
This tutorial expands on tutorial 13 and shows how you can overcome these effects by making use of polygon offsets.
-------------------------------------------------------------------my code:
if(this->glpickobj.pickFlag == 1)//pick face
{
glPushAttrib(GL_ENABLE_BIT | GL_CURRENT_BIT | GL_COLOR_BUFFER_BIT | GL_LIGHTING_BIT | GL_DEPTH_BUFFER_BIT );
glEnable(GL_POLYGON_OFFSET_FILL);
glDisable(GL_LIGHTING);
glDisable(GL_TEXTURE_2D);
//glEnable(GL_BLEND);
glDepthMask(GL_FALSE);
// glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) ;
glColor4f(1.0f,0.0,0.0,.3f);
//from http://www.zeuscmd.com/tutorials/opengl/15-PolygonOffset.php
//key!, A positive offset will push the object away from you whereas a negative offset will pull the //object towards you.
//when glPolygonOffset(1.0, 1); unseen selected red face!!!!
glPolygonOffset(-1.0, -1);
glPushMatrix();
for(int j=0;j<this->glpickobj.facePt.size();++j)
{
Facet * fpt = this->glpickobj.facePt[j];
HF_circulator h = fpt->facet_begin();
glBegin(GL_POLYGON);
do{
// glColor3f(color[0],color[1],color[2]);
Point& temp = h->vertex()->point();
glVertex3f(temp.x(),temp.y(),temp.z());
}
while(++h != fpt->facet_begin());
glEnd();
}
glPopMatrix();
glPopAttrib();
}//pick face