Polygon rendering Issues

Hello All,

I am relatively new to the OpenGL graphics programming and I hope that someone can give me some assistance or shed some light on the problem I am having with rendering a polygon face.

I have a polygon made up of 12 vertices. The overall shape of the polygon is a representation of the letter H with specific parameters as follows:

  • Height
  • Width
  • WallThickness[ATTACH=CONFIG]873[/ATTACH]

These parameters should be self explanatory. I create 12 normalized vertices from the above information and I start a GL_POLYGON operation with the 12 vertices in clockwise order. This is a closed polygon. What happens is that I get something that is not rendered correctly as expected. See attached imagine. Additionally, to ensure that my vertices are in fact correct, I also perform a GL_LINE_LOOP with the same 12 vertices. They draw as expected for the given shape. See code below.

glLoadIdentity();
glTranslatef(FLocation.X,FLocation.Y,FLocation.Z);
// glRotatef(FAngle,Rotx,Roty,Rotz);
glColor3f(FNormSurfColor1.Red,FNormSurfColor1.Green,
FNormSurfColor1.Blue);
glBegin(GL_POLYGON);
for(LIndex=0;LIndex<12;LIndex++)
glVertex3f(FBackFace[LIndex].X,
FBackFace[LIndex].Y,
FBackFace[LIndex].Z);
glEnd();

	glLoadIdentity();
	glTranslatef(FLocation.X,FLocation.Y,FLocation.Z);
	//glRotatef(FAngle,Rotx,Roty,Rotz);
	//First render the backface wireframe
	glBegin(GL_LINE_LOOP);
	glColor3f(FNormWireFrameColor.Red,FNormWireFrameColor.Green,
			  FNormWireFrameColor.Blue);
	for(LIndex=0;LIndex&lt;12;LIndex++)
		glVertex3f(FBackFace[LIndex].X,
				   FBackFace[LIndex].Y,
				   FBackFace[LIndex].Z);
	glEnd();

Is there a particular reason for the way this object is rendering on the screen, and how can I fix this?

Thanks,

James

You’ll need to convex the shape first by, dividing it into triangles or quads. OpenGL implementations simply divide the polygon into triangles with no consideration for concave shapes. That particular shape can be represented by 3 quads (or 6 triangles), but generic convexing of concave polygons is a more complicated algorithm. An overview of the process can be found on wikipedia, with links to several algorithms. Polygon triangulation - Wikipedia

As malexander said, it’s best for performance if you can pre-triangulate your surface and just render that. If you can’t and are less concerned about performance, consider this.