I'm drawing an oddly shaped polygon and I'm having problems filling in the inside. Basically, another program is sending me a 2d array of points (x and y values). I'm taking these points, maping them to my own co-ordinate system, and storing them in a vertex. Once all the points have been put into a vetex, I close the polygon. Here is an example...
glBegin(GL_POLYGON);
for (int i=0;i<TotalPoints;i++){
glVertex2f(ArrayOfPoints[i
][0],Array
OfPoints[i
][1]);
}
glEnd();
Once all the points are plotted, I can connect them to form an enclosed area. I know it forms an enclosed area, because if I change the GL_POLYGON to GL_LINE_STRIP, it will draw the polygon correctly. Also, if I drew it as GL_POINTS I can see all the points plotted on the screen correctly. If I set my polygon mode to GL_LINE, it will also draw it as a non-filled polygon corrected
ex: glPolygonMode(GL_BACK, GL_LINE);
glPolygonMode(GL_FRONT, GL_LINE);
If I try to fill either the front or back, or both, I start getting weird shapes. Now I know that normally you should be plotting the points in a logical order (ex counter clockwise), unfortunately the array that's being given to me is not sorted like that. It's drawing the dots in a strange order.
Now I know I can go through the array, do a sort to arrange the points into a sorted order to draw them counter clockwise, etc. I know I could also go through the array, try and find the edges by looking at the max and min x and y values, then going up line by line and drawing dots to fill in the polygon. What I'm wondering is if there is a handy OpenGl tool/function that could detect the edges and fill in the object for me, or something similar. If it can connect all the dots properly, I'm hoping there's an easy way to fill in the enclosed area no matter what the order is that you plotted those dots.
Anyone know an easy way to do this?
Thanks in advance
Start Free Trial