Beispiel #1
0
def runGluTesselator(nodes):
    from OpenGL import GL
    from OpenGL import GLU

    shapes = []
    vertexes = []

    def begin(shape):
        assert shape == GL.GL_LINE_LOOP
        shapes.append([])

    def vertex(vertex):
        if vertex is None:
            vertex = vertexes.pop()
        shapes[-1].append(vertex)

    def error(args):
        print "error", args

    def combine(coords, vertex_data, weight, theTuple):
        vertexes.append(coords)
        return coords

    #def end(*args, **kwargs):
    #    pass

    tess = GLU.gluNewTess()
    GLU.gluTessCallback(tess, GLU.GLU_TESS_BEGIN, begin)
    GLU.gluTessCallback(tess, GLU.GLU_TESS_VERTEX, vertex)
    GLU.gluTessCallback(tess, GLU.GLU_TESS_COMBINE_DATA, combine)
    GLU.gluTessCallback(tess, GLU.GLU_TESS_ERROR_DATA, error)
    #GLU.gluTessCallback(tess, GLU.GLU_TESS_END_DATA, end)
    GLU.gluTessProperty(tess, GLU.GLU_TESS_WINDING_RULE,
                        GLU.GLU_TESS_WINDING_NEGATIVE)
    #GLU.gluTessProperty(tess, GLU.GLU_TESS_WINDING_RULE, GLU.GLU_TESS_WINDING_NONZERO)
    GLU.gluTessProperty(tess, GLU.GLU_TESS_BOUNDARY_ONLY, GLU.GLU_TRUE)
    GLU.gluTessProperty(tess, GLU.GLU_TESS_TOLERANCE, 1.0 / 2048.0)
    GLU.gluTessNormal(tess, 0.0, 0.0, 1.0)
    GLU.gluBeginPolygon(tess, None)

    def tweaked(p):
        return (int(p.x() * 1024) / 1024.0, int(p.y() * 1024) / 1024.0, 0)

    for n in nodes:
        GLU.gluTessVertex(tess, (tweaked(n.start)), (n.start.x(), n.start.y()))
    GLU.gluEndPolygon(tess)
    res = []
    for s in shapes:
        nodes = []
        for i in range(len(s)):
            p1 = s[i]
            p2 = s[(i + 1) % len(s)]
            nodes.append(
                DrawingLine(QPointF(p1[0], p1[1]), QPointF(p2[0], p2[1])))
        res.append(DrawingPolyline(nodes))
    return res
Beispiel #2
0
 def end(self):
     if PolygonSet.in_poly:
         self.endContour()
         glu.gluEndPolygon(tess)
         PolygonSet.in_poly = False
Beispiel #3
0
 def end(self):
     if PolygonSet.in_poly:
         self.endContour()
         glu.gluEndPolygon(tess)
         PolygonSet.in_poly = False