[SOLVED] problem with gluTessBeginContour function

Started by zik, February 12, 2010, 08:27:21

Previous topic - Next topic

zik

Hi,
In my program I'm doing this :

GLUtessellator tesselator = GLU.gluNewTess();
//tesselator.gluTessNormal(0, 0, 1);
tesselator.gluTessCallback(GLU.GLU_TESS_BEGIN, tesscallback);
tesselator.gluTessCallback(GLU.GLU_TESS_VERTEX, tesscallback);
tesselator.gluTessCallback(GLU.GLU_TESS_COMBINE, tesscallback);
tesselator.gluTessCallback(GLU.GLU_TESS_END, tesscallback);
tesselator.gluTessCallback(GLU.GLU_TESS_ERROR, tesscallback);
//tesselator.gluTessCallback(GLU.GLU_TESS_BEGIN_DATA,tesscallback );
//tesselator.gluTessCallback(GLU.GLU_TESS_COMBINE_DATA,tesscallback );
GL11.glDeleteLists(priority, 1);
GL11.glNewList(priority, GL11.GL_COMPILE);
GL11.glPolygonOffset(1.0f, 1.0f);
GL11.glEnable(GL11.GL_POLYGON_OFFSET_FILL);
GL11.glColor3f(color[0],color[1] ,color[2]);
GL11.glDisable(GL11.GL_POLYGON_SMOOTH);
GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_FILL );
GL11.glEnable(GL11.GL_LINE_SMOOTH);
GL11.glTranslatef(0.0f, 0.0f,0.01f);
tesselator.gluTessProperty(GLU.GLU_TESS_WINDING_RULE, GLU.GLU_TESS_WINDING_NONZERO);
tesselator.gluBeginPolygon();
for(List<double[]> poligons_list:vertex){
	tesselator.gluTessBeginContour();
	for(double[] vertex_list:poligons_list){
		tesselator.gluTessVertex(vertex_list, 0, vertex_list);
	}
	tesselator.gluTessEndContour();
}
tesselator.gluEndPolygon();

When it passes the function "gluTessBeginContour();", i got an error 100154:GLU_TESS_MISSING_END_CONTOUR.
And i don't know why i got this error ?

thanx for your help.


zik

It contains :
private GLUtessellatorCallback tesscallback = new GLUtessellatorCallback() {

		public void vertexData(Object vertexData, Object polygonData) {}
		
		public void vertex(Object vertexData) {
			double[] vertex = (double[]) vertexData;
			GL11.glVertex3d(vertex[0], vertex[1], vertex[2]);
		}
		
		public void errorData(int errnum, Object polygonData) {}
		
		public void error(int errnum) {
			 String estring;
		      estring = GLU.gluErrorString(errnum);
		      System.err.println("Tessellation Error Number: " + errnum);
		      System.err.println("Tessellation Error: " + estring);
		}
		
		public void endData(Object polygonData) {}
		
		public void end() {
			GL11.glEnd();
		}
		
		public void edgeFlagData(boolean boundaryEdge, Object polygonData) {}
		
		public void edgeFlag(boolean boundaryEdge) {}
		
		public void combineData(double[] coords, Object[] data, float[] weight, Object[] outData, Object polygonData) {}
		
		public void combine(double[] coords, Object[] data, float[] weight, Object[] outData) {
			double[] vertex = new double[6];
			vertex[0]=coords[0];
			vertex[1]=coords[1];
			vertex[2]=coords[2];
		    outData[0] = vertex;
		    //for (int i = 3; i < 6; i++)
	    	//vertex[i] = weight[0] * ((double[]) data[0])[i] + weight[1]
	    	//* ((double[]) data[1])[i] + weight[2] * ((double[]) data[2])[i] + weight[3]
	        //* ((double[]) data[3])[i];
		}
		
		public void beginData(int type, Object polygonData) {}
		
		public void begin(int type) {
			GL11.glBegin(type);
		}
	};

Edit:
NB : The list of polygons seem to be drawn correctly

broumbroum

using the provided adapter should solve your problem :
GLUtessellatorCallbackAdapter tessCb = new GLUtessellatorCallbackAdapter() {

                                @Override
                                public void begin(int type) {
                                    GL11.glBegin(type);
                                }

                                @Override
                                public void vertex(Object vertexData) {
                                    float[] vert = (float[]) vertexData;
                                    GL11.glVertex2f(vert[0], vert[1]);
                                }

                                public void combine(double[] coords, Object[] data, float[] weight, Object[] outData) {
                                    for (int i = 0; i < outData.length; i++) {
                                        float[] combined = new float[6];
                                        combined[0] = (float) coords[0];
                                        combined[1] = (float) coords[1];
                                        /*combined[2] = (float) coords[2];
                                        for (int j = 3; j < 6; j++) {
                                        for(int d = 0; d < data.length; d++)
                                        combined[j] = weight[d] * data[d][j];
                                        }*/
                                        outData[i] = combined;
                                    }
                                }

                                @Override
                                public void end() {
                                    GL11.glEnd();
                                }
                            };

zik

My tessCallbackadapter is the same as yours.
The only differences are :
- i have implemented the error callback to check any arrors
- i'm not working with 2d vertex, but 3d vertex,

I don't think it's the problem...?

broumbroum

you dont use the lwgl glutesscallbackadapter whose source code is impl by default. And so data[] is lost within ur cbacks . have a look at lwgl src. :)

zik

Ok, sorry, i didn't see the difference between GLUtessellatorCallbackAdapter and GLUtessellatorCallback !
Now i'm using GLUtessellatorCallbackAdapter :

private GLUtessellatorCallbackAdapter tesscallback = new GLUtessellatorCallbackAdapter(){
@Override
public void begin(int type) {
   GL11.glBegin(type);
}

@Override
public void vertex(Object vertexData) {
   double[] vert = (double[]) vertexData;
   GL11.glVertex3d(vert[0], vert[1],vert[2]);
}

public void combine(double[] coords, Object[] data, float[] weight, Object[] outData) {
   for (int i = 0; i < outData.length; i++) {
      double[] combined = new double[6];
      combined[0] = (double) coords[0];
      combined[1] = (double) coords[1];
      combined[2] = (double) coords[2];
      outData[i] = combined;
   }
}

@Override
public void end() {
   GL11.glEnd();
}

public void error(int errnum) {
   String estring;
   estring = GLU.gluErrorString(errnum);
   System.err.println("Tessellation Error Number: " + errnum);
   System.err.println("Tessellation Error: " + estring);
}
};


I got now the same errors.
But if I use the function tesselator.gluNextContour(GLU.GLU_EXTERIOR);, I don't get any errors.
tesselator.gluBeginPolygon();
				for(List<double[]> poligons_list:vertex){
					tesselator.gluNextContour(GLU.GLU_EXTERIOR);
					//tesselator.gluTessBeginContour();
					for(double[] vertex_list:poligons_list){
						tesselator.gluTessVertex(vertex_list, 0, vertex_list);
					}
					//tesselator.gluTessEndContour();
				}
				tesselator.gluEndPolygon();

I don't understand why I can't use : tesselator.gluTessBeginContour(); and  tesselator.gluTessEndContour(); ?

broumbroum

try tesselator.gluBeginPolygon(null); instead of    tesselator.gluBeginPolygon();
and /or switch those two lines :
tesselator.gluTessProperty(GLU.GLU_TESS_WINDING_RULE, GLU.GLU_TESS_WINDING_NONZERO);
tesselator.gluBeginPolygon();

so do I :
tesselator.gluBeginPolygon(null);
tesselator.gluTessProperty(GLU.GLU_TESS_WINDING_RULE, GLU.GLU_TESS_WINDING_NONZERO);

zik

I can't call tesselator.gluBeginPolygon(null) because the function tesselator.gluBeginPolygon() with 1 argument doesn't exist.
And if I switch the 2 lines as you say :

tesselator.gluTessProperty(GLU.GLU_TESS_WINDING_RULE, GLU.GLU_TESS_WINDING_NONZERO);
tesselator.gluBeginPolygon();


by

tesselator.gluBeginPolygon();
tesselator.gluTessProperty(GLU.GLU_TESS_WINDING_RULE, GLU.GLU_TESS_WINDING_NONZERO);


I have the same result, and always the same errors.


Edit:
The problem was: I was using tesselator.gluBeginPolygon(); instead of tesselator.gluTessBeginPolygon(null);
and tesselator.gluEndPolygon(); instead of tesselator.gluTessEndPolygon(); !
I don't know the difference between this 2 functions.
Thanks a lot Broumbroum ! Now there is no error !