Extra Line in Polygon

Hi.

In my program I get the user to create a polygon. However, there is always an extra line in the beginning. It starts at the lower left corner and ends at the first vertex chosen by the user.

I store all the vertices in an array and I’ve checked the array but can’t find out why I’m getting that extra edge.

Has this occured to anyone before? Is there any particular function I should go over again?

It is probably your code. I think I remember seeing a snippet in a previous post by you. You need to have a way of saying this is the first point rather than draw line to here when mouse button is pressed. Then all successive mouse downs could draw line.

Hey shinpaughp.

Thanks for the reply. I went back and changed my code to only draw a line when multiple vertices are provided. It draws a point the first time around. However, the extra line is still there. I’ve included the code from the drawing function. I really don’t see anything wrong with it.

int i = 0, u;
glColor3f(1.0, 0.0, 0.0);
if (numVertices == 1)
{
glBegin(GL_POINTS);
glVertex2f(max[i][0], max[i][1]);
glEnd();
}
else if (numVertices > 1)
{
glBegin(GL_LINE_STRIP);
for (u = 0; u < numVertices; u++, i++)
{
// So I can tell what vertices have been picked.
cout << "Vertex " << u << ": " << max[i][0] << ", " << max[i][1] << endl;

glVertex2f(max[i][0], max[i][1]);
glVertex2f(max[i+1][0], max[i+1][1]);

}
glEnd();