Polygon "holes"

Please Help,

I am trying to render a group of polygons that have “holes” cut-out in them using JOGL. I have been using the STENCIL Buffer and creating a mask but as the polygons got more numerous the performance has dropped. I am fairly new to JOGL, does anybody know of a way using JOGL that this can be accomplished without using the STENCIL Buffer? Some simple code would be great but at this point ANY help would be appreciated.

Thanks in advance.

you could try using alpha testing, with the holes defined by the alpha channel in the texture.

Hi,
you can also try to tesselate your polygons into triangles or quads (may be difficult depending on what kind of polygons and what kind of holes…)

Use the GLU tessellator and capture its rendering results into a display list. There’s a simple example in demos.tess.Tess in the jogl-demos workspace. You may be able to find more complex C examples online and port them to Java and JOGL.

Thanks for all the quick replies.

So using tessellation should up the performance - at least over multiple calls to the STENCIL Buffer?

Yes, once you have your polygon tesselated you can store the bunch of triangle in a display list and render it with just one call (as Ken suggested) it should speed up the rendering.

Thanks for the help guys.

I have been trying to implement the Tesselation but keep running into an error when I execute:
"Java.lang.ArrayOutOfBoundException: 6 " followed by “Tessellation Error: Out of Memory”. I have no idea what could be causing this. Samples of my code follow:

// Shape is a Class that contains Two Arrays: 
// 1 that has X, Y, Z Coordinates of Polygons that are to be "holes" and 
// 2. X, Y, Z Coordinates of Polygons that are Solid
// Get the Vector of Shape Objects
Vector vecHoles = this.dm.getFinalFaceHoleObjects();
for (int i = 0; i < vecHoles.size(); i++) {
    GLU glu = new GLU();
    tessellCallBack tessCallback = new tessellCallBack(gl, glu);
    GLUtessellator 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);
  
   // Get the double[][] for "holes" and "non-holes" respectively
  double[][] holePts = sp.getArrayHolePts();
  double[][] wholePts = sp.getArrayPts();

  glu.gluTessBeginPolygon(tobj, null);
  glu.gluTessBeginContour(tobj);
  for (int j = 0; j < wholePts.length; j++) {
      glu.gluTessVertex(tobj, wholePts[j], 0, wholePts[j]);
  }// End of FOR-LOOP
  glu.gluTessEndContour(tobj);
  glu.gluTessEndPolygon(tobj);
  glu.gluDeleteTess(tobj);

   ...
}// End of OUTER FOR-LOOP

// Here I implement the GLUtessellatorCallbackInterface --> Only showing methods I implemented
class tessellCallBack implements GLUtessellatorCallback {
    private GL gl;
    private GLU glu;

    public tessellCallBack(GL gl, GLU glu) {
      	this.gl = gl;
      	this.glu = glu;
    }

    public void begin(int type) {
      	gl.glBegin(type);
    }

    public void end() {
      	gl.glEnd();
    }

    public void vertex(Object vertexData) {
      	double[] pointer;
      	if (vertexData instanceof double[]) {
        		pointer = (double[])vertexData;
		gl.glVertex3dv(pointer, 0);
      	}
  }

  public void error(int errnum) {
      	String estring;
      	estring = glu.gluErrorString(errnum);
      	System.err.println("Tessellation Error: " + estring);
      	System.exit(0);
    }// End of error(int)
}// End of tessellCallBack
  

I am hoping it is something obvious but I just can’t see it at this point. I hope that one of you JOGL Gurus have an idea.

Once again, Thanks.

Never mind, I figured it out. It seems I forgot to define the combine method for Callbacks (stupid newbie mistake).