Java Code Examples for com.jogamp.opengl.glu.GLU#gluTessCallback()

The following examples show how to use com.jogamp.opengl.glu.GLU#gluTessCallback() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OpenGL.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
public OpenGL(final IOpenGLRenderer renderer) {
	super(renderer);
	glut = new GLUT();
	glu = new GLU();
	pickingState = renderer.getPickingHelper();
	geometryCache = new GeometryCache(renderer);
	glTesselatorDrawer = (final double[] ordinates) -> {
		tobj.gluTessVertex(ordinates, 0, ordinates);
	};
	GLU.gluTessCallback(tobj, GLU.GLU_TESS_VERTEX, this);
	GLU.gluTessCallback(tobj, GLU.GLU_TESS_BEGIN, this);
	GLU.gluTessCallback(tobj, GLU.GLU_TESS_END, this);
	GLU.gluTessProperty(tobj, GLU.GLU_TESS_TOLERANCE, 0.1);
	geometryDrawer = new GeometryDrawer(this);
	fieldDrawer = new FieldDrawer(this);
	stringDrawer = new StringDrawer(this);
	resourceDrawer = new ResourceDrawer(this);
}
 
Example 2
Source File: SimpleTess.java    From jaamsim with Apache License 2.0 5 votes vote down vote up
public void init() {
		gluTess = GLU.gluNewTess();

		GLU.gluTessCallback(gluTess, GLU.GLU_TESS_VERTEX, this);
		GLU.gluTessCallback(gluTess, GLU.GLU_TESS_BEGIN, this);
		GLU.gluTessCallback(gluTess, GLU.GLU_TESS_END, this);
		GLU.gluTessCallback(gluTess, GLU.GLU_TESS_COMBINE, this);
		GLU.gluTessCallback(gluTess, GLU.GLU_TESS_ERROR, this);

		GLU.gluTessProperty(gluTess, GLU.GLU_TESS_WINDING_RULE, GLU.GLU_TESS_WINDING_NONZERO);
}
 
Example 3
Source File: TessFont.java    From jaamsim with Apache License 2.0 4 votes vote down vote up
private TessOutput tesselateString(String s) {
	GlyphVector gv = _font.createGlyphVector(_frc, s);

    Shape shape = gv.getOutline();
	//
    AffineTransform at = new AffineTransform();
    at.scale(1, -1);
	PathIterator pIt = shape.getPathIterator(at, _font.getSize()/200.0);

	// Create a GLU tesselator
	GLUtessellator tess = GLU.gluNewTess();
	CharTesselator tessAdapt = new CharTesselator();

	GLU.gluTessCallback(tess, GLU.GLU_TESS_VERTEX, tessAdapt);
	GLU.gluTessCallback(tess, GLU.GLU_TESS_BEGIN, tessAdapt);
	GLU.gluTessCallback(tess, GLU.GLU_TESS_END, tessAdapt);
	GLU.gluTessCallback(tess, GLU.GLU_TESS_COMBINE, tessAdapt);
	GLU.gluTessCallback(tess, GLU.GLU_TESS_ERROR, tessAdapt);

	int winding = pIt.getWindingRule();

	if (winding == PathIterator.WIND_EVEN_ODD)
		GLU.gluTessProperty(tess, GLU.GLU_TESS_WINDING_RULE, GLU.GLU_TESS_WINDING_ODD);
	else if (winding == PathIterator.WIND_NON_ZERO)
		GLU.gluTessProperty(tess, GLU.GLU_TESS_WINDING_RULE, GLU.GLU_TESS_WINDING_NONZERO);
	else
		assert(false); // PathIterator should only return these two winding rules

	GLU.gluBeginPolygon(tess);
	GLU.gluTessNormal(tess, 0, 0, 1);
	double[] first = null;
	double[] v;
	while (!pIt.isDone()) {
		v = new double[3];
		int type = pIt.currentSegment(v);
		v[2] = 0.0;
		if (type == PathIterator.SEG_MOVETO) {
			first = v;
			GLU.gluNextContour(tess, GLU.GLU_UNKNOWN);
			GLU.gluTessVertex(tess, v, 0, v);
		}
		else if (type == PathIterator.SEG_LINETO) {
			GLU.gluTessVertex(tess, v, 0, v);
		}
		else if (type == PathIterator.SEG_CLOSE) {
			assert(first != null); // If this is true, there is an error in the AWT path iterator
			GLU.gluTessVertex(tess, first, 0, first);
			first = null;
		}
		else
		{
			assert(false); // The path itertor should not return other path types here
		}
		pIt.next();
	}
	GLU.gluEndPolygon(tess);

	int numVerts = tessAdapt.getVerts().size();
	double[] verts = new double[numVerts];
	int count = 0;
	for (double d : tessAdapt.getVerts()) {
		verts[count++] = d;
	}

	TessOutput ret = new TessOutput();
	ret.verts = verts;
	ret.bounds = gv.getVisualBounds();

	ret.advances = new double[s.length()];
	for (int i = 0; i < s.length(); ++i) {
		ret.advances[i] = gv.getGlyphMetrics(i).getAdvance();
	}
	return ret;
}