Exemple #1
0
def tessellate(contours):
    """ Returns a list of triangulated (x,y)-vertices from the given list of path contours,
        where each contour is a list of (x,y)-tuples.
        The vertices can be drawn with GL_TRIANGLES to render a complex polygon, for example:
        glBegin(GL_TRIANGLES)
        for x, y in tessellate(contours):
            glVertex3f(x, y, 0)
        glEnd()
    """
    id = repr(contours)
    if id in _tessellate.cache:
        return _tessellate.cache[id]
    # Push the given contours to C and call gluTessVertex().
    _tessellate.reset()
    contours = [[(GLdouble * 3)(x, y, 0) for x, y in points]
                for points in contours]
    gluTessBeginPolygon(_tessellator, None)
    for vertices in contours:
        gluTessBeginContour(_tessellator)
        for v in vertices:
            gluTessVertex(_tessellator, v, v)
        gluTessEndContour(_tessellator)
    gluTessEndPolygon(_tessellator)
    # Update the tessellation cache with the results.
    if len(_tessellate.cache) > TESSELLATION_CACHE:
        del _tessellate.cache[_tessellate.queue.pop(0)]
    _tessellate.queue.append(id)
    _tessellate.cache[id] = _tessellate.triangles
    return _tessellate.triangles
Exemple #2
0
def tessellate(contours):
    """ Returns a list of triangulated (x,y)-vertices from the given list of path contours,
        where each contour is a list of (x,y)-tuples.
        The vertices can be drawn with GL_TRIANGLES to render a complex polygon, for example:
        glBegin(GL_TRIANGLES)
        for x, y in tessellate(contours):
            glVertex3f(x, y, 0)
        glEnd()
    """
    id = repr(contours)
    if id in _tessellate.cache:
        return _tessellate.cache[id]
    # Push the given contours to C and call gluTessVertex().
    _tessellate.reset()
    contours = [[(GLdouble * 3)(x, y, 0) for x, y in points] for points in contours]
    gluTessBeginPolygon(_tessellator, None)
    for vertices in contours:
        gluTessBeginContour(_tessellator)
        for v in vertices:
            gluTessVertex(_tessellator, v, v)
        gluTessEndContour(_tessellator)
    gluTessEndPolygon(_tessellator)
    # Update the tessellation cache with the results.
    if len(_tessellate.cache) > TESSELLATION_CACHE:
        del _tessellate.cache[_tessellate.queue.pop(0)]
    _tessellate.queue.append(id)
    _tessellate.cache[id] = _tessellate.triangles
    return _tessellate.triangles
Exemple #3
0
 def perform_tessellation(self, data_lists):
     gluTessBeginPolygon(tess, None)
     for d_list in data_lists:
         gluTessBeginContour(tess)
         for v_data in d_list:
             gluTessVertex(tess, v_data, v_data)
         gluTessEndContour(tess)
     gluTessEndPolygon(tess)
     return self.tlist
 def perform_tessellation(self, data_lists):
     gluTessBeginPolygon(tess, None)
     for d_list in data_lists:
         gluTessBeginContour(tess)
         for v_data in d_list:
             gluTessVertex(tess, v_data, v_data)
         gluTessEndContour(tess)
     gluTessEndPolygon(tess)
     return self.tlist
Exemple #5
0
def tessellate(contours):
    """ Returns a list of triangulated (x,y)-vertices from the given list of path contours,
        where each contour is a list of (x,y)-tuples.
        The vertices can be drawn with GL_TRIANGLES to render a complex polygon, for example:
        glBegin(GL_TRIANGLES)
        for x, y in tessellate(contours):
            glVertex3f(x, y, 0)
        glEnd()
    """
    _tessellate.reset()
    contours = [[(GLdouble * 3)(x, y, 0) for x, y in points] for points in contours]
    gluTessBeginPolygon(_tessellator, None)
    for vertices in contours:    
        gluTessBeginContour(_tessellator)
        for v in vertices:
            gluTessVertex(_tessellator, v, v)
        gluTessEndContour(_tessellator)
    gluTessEndPolygon(_tessellator)
    return _tessellate.triangles