Hi,
I’m working on drawing a 2D bpf (break point function) with jogl.
I’ve a problem with tessellation.
I’m not sure that the following code is ok but I believe I understood the principle (I’ve read the docs, the forums, the tuts… and Tess.java).
my GLUtessellatorCallbackAdapter always receives the same vertex, and I don’t understand why.
If someone could take a look at it…
The points I want to draw are Point2D.Float and are stored in a vector called points.
The coords of the vertex passed thru the gluTessVertex function are { X, Y, R, G, B, Alpha }
Here’s the code :
INIT
tessCallback = new TessCallback(gl,glu);
tobj = glu.gluNewTess();
glu.gluTessCallback(tobj, GLU.GLU_TESS_VERTEX, tessCallback);
glu.gluTessCallback(tobj, GLU.GLU_TESS_BEGIN, tessCallback);
glu.gluTessCallback(tobj, GLU.GLU_TESS_END, tessCallback);
glu.gluTessCallback(tobj, GLU.GLU_TESS_ERROR, tessCallback);
glu.gluTessCallback(tobj, GLU.GLU_TESS_COMBINE, tessCallback);
DISPLAY
if(!points.isEmpty())
{
double[] coords = new double[6];
// color initialisation
coords[2] = bgPolyColor[0];
coords[3] = bgPolyColor[1];
coords[4] = bgPolyColor[2];
coords[5] = bgPolyColor[3];
// maybe the following is enough (?)
glColor(gl,bgPolyColor);
// tesselation properties
glu.gluTessProperty(tobj, GLU.GLU_TESS_WINDING_RULE, GLU.GLU_TESS_WINDING_POSITIVE);
// begin
glu.gluTessBeginPolygon(tobj, null);
glu.gluTessBeginContour(tobj);
// first point
coords[0] = ((Point2D.Float)points.firstElement()).x;
coords[1] = 0;
glu.gluTessVertex(tobj, coords,0,coords);
System.out.println("i:-1 x:"+coords[0]+" y:"+coords[1]);
// intermediate points
for(int i = 0; i< points.size();i++)
{
Point2D.Float p2D = (Point2D.Float)points.get(i);
coords[0] = p2D.x;
coords[1] = p2D.y;
glu.gluTessVertex(tobj, coords,0,coords);
System.out.println("i:"+i+" x:"+coords[0]+" y:"+coords[1]);
}
// final point
coords[0] = ((Point2D.Float)points.lastElement()).x;
coords[1] = 0;
glu.gluTessVertex(tobj, coords,0,coords);
System.out.println("i:+1 x:"+coords[0]+" y:"+coords[1]);
// end
glu.gluTessEndContour(tobj);
glu.gluTessEndPolygon(tobj);
// delete
glu.gluDeleteTess(tobj);
}
finally my GLUtessellatorCallbackAdapter VERTEX method
public void vertex(Object data)
{
double[] d = (double[]) data;
if(d!=null)
{
if(d.length >= 6)
{
gl.glColor4f((float)d[0],(float)d[1],(float)d[2],(float)d[3]);
gl.glVertex2f((float)d[0],(float)d[1]);
}
System.out.println("Tess - vertex (" + d[0] + "," + d[1] + ")");
} else {
System.out.println("Tess - null vertex");
}
}
The result given with 5 points is :
i:-1 x:13.421874046325684 y:0.0
i:0 x:13.421874046325684 y:48.29257583618164
i:1 x:29.3359375 y:77.0611343383789
i:2 x:41.4765625 y:47.349342346191406
i:+1 x:41.4765625 y:0.0
Tess - begin FAN
Tess - vertex (41.4765625,0.0)
Tess - vertex (41.4765625,0.0)
Tess - vertex (41.4765625,0.0)
Tess - vertex (41.4765625,0.0)
Tess - vertex (41.4765625,0.0)
Tess - end
The vertex are always the same.
Where is the error ? What am I doing wrong here ?
Thanks
Léo