gluTessellator

Hello,

I am at a loss to determine why my tessellator is throwing errors of the nature a) array out of bounds b) out of memory.

Is there something obvious that I am missing? For example, must I provide all the methods in TessCallback (not just the four I have provided)? Or, must I provide explicit properties, such as the winding rule?

I appreciate your help very much. I am feeling very stuck.

Thanks!


// inside a render call....

GL gl = dc.getGL();
GLU glu = new GLU();
TessCallback tess = new TessCallback(gl, glu);
GLUtessellator tobj = glu.gluNewTess();
glu.gluTessCallback(tobj, GLU.GLU_TESS_VERTEX, tess);
glu.gluTessCallback(tobj, GLU.GLU_TESS_BEGIN, tess);
glu.gluTessCallback(tobj, GLU.GLU_TESS_END, tess);
glu.gluTessCallback(tobj, GLU.GLU_TESS_ERROR, tess);

// render details
gl.glPolygonMode(GL.GL_FRONT, GL.GL_FILL);
gl.glCullFace(GL.GL_BACK);
gl.glEnable(GL.GL_POLYGON_OFFSET_FILL);
gl.glPolygonOffset(1.0f,1.0f);
gl.glColor4d(this.r,this.g,this.b, this.a);

// begin tessellator
glu.gluTessBeginPolygon(tobj, null);
glu.gluTessBeginContour(tobj);
for (int i = 0; i < glcoords.length; i++) {
        double[] temp = new double[3];
	temp[0] = glcoords[i][0]; temp[1] = glcoords[i][1]; temp[2] = glcoords[i][2];
	glu.gluTessVertex(tobj, temp, 0, temp);
}
glu.gluTessEndContour(tobj);
glu.gluTessEndPolygon(tobj);
glu.gluDeleteTess(tobj);

// inner class
	public class TessCallback extends GLUtessellatorCallbackAdapter {
		private GL gl;
		private GLU glu;

		public TessCallback(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 data) {
			double[] a = (double[]) data;
			gl.glVertex3d(a[0],a[1],a[2]);
		}
		public void error(int errnum) {
			System.err.println("Tessellation Error: " + glu.gluErrorString(errnum));
		}
		public void combine(double[] coords, Object[] data, float[] weight, Object[] outData) {
			// doesn't combine anything for now
			double[] vertex = new double[3];
			vertex[0] = coords[0];
			vertex[1] = coords[1];
			vertex[2] = coords[2];
			outData[0] = vertex;
		}
	}

You seem to have forgottent to add the combine callback. Maybe it will help.

I’ve also write a code very similar to yours. I don’t get the “array out of bounds” error but always the “out of memory” one from GLU.
The “out of memory” error occurs even with very simple polygons. However, I get the right result even with the error.

Thank you so much. That was indeed the problem. Wow - my app looks great now!

I wish there was more written about using the tesselator. I have been all over the web and through both the RedBook and Angel’s book on OpenGL and I still don’t understand it very well.

But because of your help, it now works! Thanks!

Do you still get the “out of memory” error from Glu?

I don’t know if there is a mistake in my code or if it is a bug.