Hello Guest

[SOLVED] problem with gluTessBeginContour function

  • 8 Replies
  • 12403 Views
*

Offline zik

  • *
  • 9
[SOLVED] problem with gluTessBeginContour function
« on: February 12, 2010, 08:27:21 »
Hi,
In my program I'm doing this :

Code: [Select]
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.
« Last Edit: February 23, 2010, 08:26:06 by zik »

Re: problem with gluTessBeginContour function
« Reply #1 on: February 14, 2010, 14:12:11 »
« Last Edit: February 14, 2010, 14:13:52 by broumbroum »

*

Offline zik

  • *
  • 9
Re: problem with gluTessBeginContour function
« Reply #2 on: February 15, 2010, 17:11:06 »
It contains :
Code: [Select]
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
« Last Edit: February 17, 2010, 14:59:25 by zik »

Re: problem with gluTessBeginContour function
« Reply #3 on: February 17, 2010, 22:08:23 »
using the provided adapter should solve your problem :
Code: [Select]
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();
                                }
                            };

*

Offline zik

  • *
  • 9
Re: problem with gluTessBeginContour function
« Reply #4 on: February 18, 2010, 09:53:10 »
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...?

Re: problem with gluTessBeginContour function
« Reply #5 on: February 19, 2010, 07:06:17 »
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. :)

*

Offline zik

  • *
  • 9
Re: problem with gluTessBeginContour function
« Reply #6 on: February 22, 2010, 13:59:19 »
Ok, sorry, i didn't see the difference between GLUtessellatorCallbackAdapter and GLUtessellatorCallback !
Now i'm using GLUtessellatorCallbackAdapter :

Code: [Select]
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.
Code: [Select]
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(); ?

Re: problem with gluTessBeginContour function
« Reply #7 on: February 22, 2010, 15:27:27 »
try tesselator.gluBeginPolygon(null); instead of    tesselator.gluBeginPolygon();
and /or switch those two lines :
Code: [Select]
tesselator.gluTessProperty(GLU.GLU_TESS_WINDING_RULE, GLU.GLU_TESS_WINDING_NONZERO);
tesselator.gluBeginPolygon();
so do I :
Code: [Select]
tesselator.gluBeginPolygon(null);
tesselator.gluTessProperty(GLU.GLU_TESS_WINDING_RULE, GLU.GLU_TESS_WINDING_NONZERO);
« Last Edit: February 22, 2010, 15:30:58 by broumbroum »

*

Offline zik

  • *
  • 9
Re: problem with gluTessBeginContour function
« Reply #8 on: February 22, 2010, 17:08:39 »
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 :

Code: [Select]
tesselator.gluTessProperty(GLU.GLU_TESS_WINDING_RULE, GLU.GLU_TESS_WINDING_NONZERO);
tesselator.gluBeginPolygon();

 by

Code: [Select]
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 !
« Last Edit: February 22, 2010, 19:14:18 by zik »