I have looked at some sample code for polygon tesselation over here (I’m using their implementation of the callback class too) and gave it a shot for my own polygons (can reach up to 60.000 points). The problem is that for small polygons which I enter exactly like the example, everything is fine, but for the generated ones I get some errors.
First of all, the error string lookup seems in the callback class seems bugged
(see this link) but I don’t mind much for that since I’ll simply google the integer error codes.
My error function from the callback which crashes because error code lookups fail;
public void error(int errnum) {
try {
System.err.println("Tesselation Error(errnum): " + errnum);
String estring = glu.gluErrorString(errnum);
System.err.println("Tesselation Error: " + estring);
} catch (Exception e) {
e.printStackTrace();
}
}
my debug statement containing the error code;
Tesselation Error(errnum): 100156
stacktrace;
java.lang.ArrayIndexOutOfBoundsException: 6
at com.sun.opengl.impl.error.Error.gluErrorString(Error.java:95)
at javax.media.opengl.glu.GLU.gluErrorString(GLU.java:240)
But my concern is that calling glu.gluTessEndPolygon in the end yields error code 100156 for my code. The code works if I comment out my own loop. I’m clueless as to what is wrong, could anyone provide a hint?
tessellCallBack tessCallback = new tessellCallBack(gl, glu);
listid = gl.glGenLists(1);
GLUtessellator tobj = glu.gluNewTess();
glu.gluTessCallback(tobj, GLU.GLU_TESS_VERTEX, tessCallback);// glVertex3dv);
glu.gluTessCallback(tobj, GLU.GLU_TESS_BEGIN, tessCallback);// beginCallback);
glu.gluTessCallback(tobj, GLU.GLU_TESS_END, tessCallback);// endCallback);
glu.gluTessCallback(tobj, GLU.GLU_TESS_ERROR, tessCallback);// errorCallback);
double tri[][] = new double[][]{// [3][3]
{0.75, 1.80, 1},
{1.75, 0.75, 1},
{1.25, 1.75, 1}
};
gl.glNewList(listid, GL.GL_COMPILE);
gl.glShadeModel(GL.GL_FLAT);
glu.gluTessBeginPolygon(tobj, null);
glu.gluTessBeginContour(tobj);
glu.gluTessVertex(tobj, tri[0], 0, tri[0]);
glu.gluTessVertex(tobj, tri[1], 0, tri[1]);
glu.gluTessVertex(tobj, tri[2], 0, tri[2]);
glu.gluTessEndContour(tobj);
glu.gluTessBeginContour(tobj);
for (int i = 0; i < len; i++) {
//get x/y/z values
double[] tmp = new double[]{x, y, z};
glu.gluTessVertex(tobj, tmp, 0, tmp);
}
glu.gluTessEndContour(tobj);
glu.gluTessEndPolygon(tobj); //crash, error code 100156
gl.glEndList();
glu.gluDeleteTess(tobj);