gluTessVertex Problem

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

Ok I found the problem by myself

I was a bit tired yesterday

the problem is that I always write the vertex in the same double[]
the result is logical for C coding,
I expected this to work with Java

So the solution is :

DISPLAY

		
                   if(!points.isEmpty())
		{
			double[][] coords = new double[points.size()+2][6];
		
			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][0] = ((Point2D.Float)points.firstElement()).x;
			coords[0][1] = 0;
			glu.gluTessVertex(tobj, coords[0],0,coords[0]);
			
			// intermediate points
			for(int i = 0; i< points.size();i++)
			{
				Point2D.Float p2D = (Point2D.Float)points.get(i);
				coords[i+1][0] = p2D.x;
				coords[i+1][1] = p2D.y;
				glu.gluTessVertex(tobj, coords[i+1],0,coords[i+1]);
			}

			// final point
			coords[points.size()+1][0] = ((Point2D.Float)points.lastElement()).x;
			coords[points.size()+1][1] = 0;
			glu.gluTessVertex(tobj, coords[points.size()+1],0,coords[points.size()+1]);
			
			// end
			glu.gluTessEndContour(tobj);
			glu.gluTessEndPolygon(tobj);
			
			// delete
			glu.gluDeleteTess(tobj);

Hope this will avoid someone’s headaches

Now, to optimise, I should only render the part which just changed
Anyone knows if it will work with tessellation ?

I think I should memorize the double[][], modify and sort it when needed and manage the polygon with Lists.

Léo