POLYGON offset

How can i make decals, and render coplanar polygons using polygon offset?

Here’s my code

 
glPushMatrix();
	glTranslatef(6.5,0.05,6.5); 
	glScalef(3,0.1,3);
	glutSolidCube(1);
	glPopMatrix();

	glColor3f(0,0.5,0);
	glBegin(GL_POLYGON);
	glNormal3d(0,1,0); 
		glVertex3f(5.5,0.1,5.5);
		glVertex3f(5.5,0.1,2+5.5);
		glVertex3f(2+5.5,0.1,2+5.5);
		glVertex3f(2+5.5,0.1,5.5);
	glEnd();
 

I’d like someone to explain how can i set offset to avoid (u)nexpected visual artifacts!

Thanks in advance

hey kesh, it depends on how you go about things. say you want to draw a wall, then draw a decal on top. you have 3 basic choices here:

  1. you could push the wall away from the view, then draw the decal normally.
  2. you could draw the wall normally, then pull the decal towards the view.
  3. some combination of 1 and 2.

to push something away, use positive values for factor and/or units:

glPolygonOffset( factor = 1, units = 1 );
glEnable( GL_POLYGON_OFFSET_FILL );
// now draw the wall …

conversely, if you want to pull something toward the view, use negative values for factor and/or units:

glPolygonOffset( factor = -1, units = -1 );
glEnable( GL_POLYGON_OFFSET_FILL );
// now draw the decal …

the basic idea is that a combination of factor and units is ADDED to the depth value before the depth test. it’s important to experiment with actual values to get the best results for your world. it might be informative to setup your app so that you can modify these values dynamically.

spec:
http://pyopengl.sourceforge.net/documentation/manual/glPolygonOffset.3G.html