Hello,
I hope someone can help me out. I added GLU tesselation for complex polygons to my renderer,
but it does not work for all cases.
It works for complex non-intersecting polygons,
I tried it with a VMAP0 data set - country boundaries for european states with 100k+ vertices. But once I try to tesselate this simple self-intersecting polygon:
0,0, 100,100, 0,100, 100,0
I get a complaint that the combine callback is not defined. Which is funny because this callback is called right before the error callback and it holds the correct new vertex position.
Also the begin, vertex and end callbacks are apparently not called at all…
I boiled this down into the following code, what am I doing wrong here?
private void drawTesselPoly(GL gl, GLU glu) {
if( this.tesselator == null)
{
tesselator = glu.gluNewTess();
glu.gluTessCallback(this.tesselator, GLU.GLU_TESS_VERTEX, this);
glu.gluTessCallback(this.tesselator, GLU.GLU_TESS_VERTEX_DATA, this);
glu.gluTessCallback(this.tesselator, GLU.GLU_TESS_BEGIN, this);
glu.gluTessCallback(this.tesselator, GLU.GLU_TESS_END, this);
glu.gluTessCallback(this.tesselator, GLU.GLU_TESS_ERROR, this);
glu.gluTessCallback(this.tesselator, GLU.GLU_TESS_COMBINE, this);
glu.gluTessCallback(this.tesselator, GLU.GLU_TESS_COMBINE_DATA, this);
}
glu.gluTessProperty(this.tesselator, GLU.GLU_TESS_WINDING_RULE, GLU.GLU_TESS_WINDING_NONZERO);
TessPoint3D vertex1 = new TessPoint3D(0.0,0.0,0.0);
glu.gluTessBeginPolygon( tesselator, vertex1);
glu.gluTessBeginContour(tesselator);
glu.gluTessVertex(tesselator, new double[]{0, 0, 0} , new TessPoint3D(0, 0, 0));
glu.gluTessVertex(tesselator, new double[]{100, 100, 0} , new TessPoint3D(100,100,0));
glu.gluTessVertex(tesselator, new double[]{0, 100, 0} , new TessPoint3D(0,100,0));
glu.gluTessVertex(tesselator, new double[]{100, 0, 0} , new TessPoint3D(100,0,0));
glu.gluTessEndContour(tesselator);
glu.gluTessEndPolygon(tesselator);
}
I defined the callbacks in my renderer class (which implements the
GLUtesselatorCallback) like this:
public void begin(int arg0) {
gl.glBegin( arg0);
}
public void beginData(int arg0, Object arg1) {
gl.glBegin( arg0);
}
public void vertex(Object arg0) {
TessPoint3D tessp = (TessPoint3D)arg0;
gl.glVertex3d( tessp.x, tessp.y, tessp.z);
}
public void vertexData(Object arg0, Object arg1) {
TessPoint3D tessp = (TessPoint3D)arg0;
gl.glVertex3d( tessp.x, tessp.y, tessp.z);
}
public void end() {
gl.glEnd();
}
public void endData(Object arg0) {
gl.glEnd();
}
public void combine(double[] arg0, Object[] arg1, float[] arg2, Object[] arg3) {
gl.glVertex3dv(arg0);
}
public void combineData(double[] arg0, Object[] arg1, float[] arg2, Object[] arg3, Object arg4) {
gl.glVertex3dv(arg0);
}
public void error(int arg0) {
System.out.println("tess error: "+glu.gluErrorString(arg0));
}
public void errorData(int arg0, Object arg1) {
System.out.println("tess errorData: "+glu.gluErrorString(arg0));
}
TessPoint is a small private class:
private class TessPoint3D
{
public double x;
public double y;
public double z;
public TessPoint3D(double p1, double p2, double p3) {
x = p1; y = p2; z = p3;
}
}
Best regards,
Greg