Package org.lwjgl.util.glu

Examples of org.lwjgl.util.glu.GLUtessellator


        return getCWrgbaColors(color, color, color, color, alpha);
    }
    private static GLUtessellator _tess = null;

    private static GLUtessellator _newTess() {
        GLUtessellator tess = GLUtessellatorImpl.gluNewTess();
        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]);
            }

            @Override
            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();
            }
        };
        tess.gluTessCallback(GLU.GLU_TESS_BEGIN, tessCb);
        tess.gluTessCallback(GLU.GLU_TESS_VERTEX, tessCb);
        tess.gluTessCallback(GLU.GLU_TESS_COMBINE, tessCb);
        tess.gluTessCallback(GLU.GLU_TESS_END, tessCb);
        return tess;
    }
View Full Code Here


     */
    public static void _renderShape(Shape s, int resolution) {
        PathIterator pi = s.getPathIterator(null);
        Point2D.Float current = new Point2D.Float();
        _beginTesselator();
        GLUtessellator tess = _tess;
        tess.gluTessBeginPolygon(null);
        switch (pi.getWindingRule()) {
            case PathIterator.WIND_EVEN_ODD:
                tess.gluTessProperty(GLU.GLU_TESS_WINDING_RULE, GLU.GLU_TESS_WINDING_ODD);
                break;
            case PathIterator.WIND_NON_ZERO:
                tess.gluTessProperty(GLU.GLU_TESS_WINDING_RULE, GLU.GLU_TESS_WINDING_NONZERO);
                break;
            default:
                if (JXAenvUtils._debug) {
                    System.err.println(JXAenvUtils.log("no winding rule", JXAenvUtils.LVL.APP_WRN));
                }
                break;
        }
        while (!pi.isDone()) {
            float[] coords = new float[6];
            int path = pi.currentSegment(coords);
            switch (path) {
                case PathIterator.SEG_MOVETO:
                    /*
                     * if (JXAenvUtils._debug) { System.err.println(">>> GL TESS
                     * >>> begin move"); }
                     */
                    tess.gluTessBeginContour();
                    tess.gluTessVertex(new double[]{coords[0], coords[1], 0.}, 0, new float[]{coords[0], coords[1], 0f});
                    current.x = coords[0];
                    current.y = coords[1];
                    break;
                case PathIterator.SEG_CLOSE:
                    /*
                     * if (JXAenvUtils._debug) { System.err.println(">>> GL TESS
                     * >>> close"); }
                     */
                    tess.gluTessEndContour();
                    break;
                case PathIterator.SEG_LINETO:
                    /*
                     * if (JXAenvUtils._debug) { System.err.println(">>> GL TESS
                     * >>> line"); }
                     */
                    tess.gluTessVertex(new double[]{coords[0], coords[1], 0.}, 0, new float[]{coords[0], coords[1], 0f});
                    current.x = coords[0];
                    current.y = coords[1];
                    break;
                case PathIterator.SEG_CUBICTO:
                    /*
                     * if (JXAenvUtils._debug) { System.err.println(">>> GL TESS
                     * >>> cubic"); }
                     */
                    for (Point2D.Float p : GLGeom._computeBezierCurve(new Point2D.Float[]{current, new Point2D.Float(coords[0], coords[1]), new Point.Float(coords[2], coords[3]), new Point.Float(coords[4], coords[5])}, resolution)) {
                        tess.gluTessVertex(new double[]{p.x, p.y, 0.}, 0, new float[]{p.x, p.y, 0f});
                    }
                    current.x = coords[4];
                    current.y = coords[5];
                    break;
                case PathIterator.SEG_QUADTO:
                    /*
                     * if (JXAenvUtils._debug) { System.err.println(">>> GL TESS
                     * >>> quad"); }
                     */
                    for (Point2D.Float p : GLGeom._computeBezierCurve(new Point2D.Float[]{current, new Point2D.Float(coords[0], coords[1]), new Point.Float(coords[2], coords[3])}, resolution)) {
                        tess.gluTessVertex(new double[]{p.x, p.y, 0.}, 0, new float[]{p.x, p.y, 0f});
                    }
                    current.x = coords[2];
                    current.y = coords[3];
                    break;
                default:
                    break;
            }
            pi.next();
        }
        tess.gluTessEndPolygon();
        _endTesselator();
    }
View Full Code Here

TOP

Related Classes of org.lwjgl.util.glu.GLUtessellator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.