PDA

View Full Version : Polygon rendering Issues



williajl40
01-20-2015, 08:14 AM
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
- WallThickness1599

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.Gree n,
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,FNormWireFrameCo lor.Green,
FNormWireFrameColor.Blue);
for(LIndex=0;LIndex<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

malexander
01-20-2015, 11:45 AM
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. http://en.wikipedia.org/wiki/Polygon_triangulation

Dark Photon
01-20-2015, 07:16 PM
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 (http://www.glprogramming.com/red/chapter14.html#name13).