Hi,
I’m having some trouble with tesselating polygons with GLU_TESS. I want to send in x-number of vertices and tesselate. I am using this code:
double coord[3];
vector<double>::iterator PolyIter = polygon.begin();
double temp = *PolyIter;
//vector<double[3]>::iterator PolyIter = Polygon.begin();
while (PolyIter != polygon.end())
{
temp = *PolyIter;
coord[0] = temp;
++PolyIter;
temp = *PolyIter;
coord[1] = temp;
++PolyIter;
temp = *PolyIter;
coord[2] = temp;
++PolyIter;
gluTessVertex(tess,coord, coord);
}
The problem here is that only the last vertex coordinate is stored, the rest are overwritten. I am aware that this is a common problem, as it is stated in the documentation;
NOTES
It is a common error to use a local variable for location or
data and store values into it as part of a loop. For
example: for (i = 0; i < NVERTICES; ++i) {
GLdouble data[3];
data[0] = vertex[i][0];
data[1] = vertex[i][1];
data[2] = vertex[i][2];
gluTessVertex(tobj, data, data);
}
This doesn't work. Because the pointers specified by location and data might not be dereferenced until gluTessEndPolygon is executed, all the vertex coordinates but the very last set could be overwritten before tessellation begins.
Two common symptoms of this problem are consists of a single point (when a local variable is used for data) and a GLU_TESS_NEED_COMBINE_CALLBACK error (when a local variable is used for location).
Is there any way to solve this problem, as I can’t predefine how many vertices are going to be tesselated each time.
Thanks in advance
/Jacob