~mcfletch/openglcontext/trunk : /tests/glu_tess2.py (revision 351)

Line Revision Contents
1 1
# -*- coding: latin-1 -*-
2
"""Simple GLU Tess-object test w/out combine callback"""
3
from OpenGLContext import testingcontext
4 296
BaseContext = testingcontext.getInteractive()
5 1
from OpenGL.GL import *
6
from OpenGL.GLU import *
7 183
from OpenGLContext.arrays import array
8 1
9
10
outline = [
11 308
    [191,   0],
12
    [ 191, 1480],
13
    [ 191, 1480],
14
    [ 401, 1480],
15
    [ 401, 1480],
16
    [401,   856],
17
    [401,   856],
18
    [1105,  856],
19
    [1105,  856],
20
    [1105, 1480],
21
    [1105, 1480],
22
    [1315, 1480],
23
    [1315, 1480],
24
    [1315,    0],
25
    [1315,    0],
26
    [1105,    0],
27
    [1105,    0],
28
    [1105,  699],
29
    [1105,  699],
30
    [401,   699],
31
    [401,   699],
32
    [401,     0],
33
    [401,     0],
34
    [191,     0],
35
    [191,     0],
36
    [191,     0],
37 1
]
38
39
class TestContext( BaseContext ):
40 308
    scale = 400.0
41
    def OnInit( self ):
42
        self.tess = gluNewTess()
43
        print 'Python-callback-using version of tessellation test'
44
        
45
    def Render( self, mode = 0):
46
        BaseContext.Render( self, mode )
47
        # we get the tess'd geometry backward for some reason :(
48
        glDisable( GL_CULL_FACE )
49
        self.renderCap( self.scale )
50 1
51 308
    def renderCap( self, scale = 400.0):
52
        """The cap is generated with GLU tessellation routines...
53
        """
54
        gluTessCallback(self.tess, GLU_TESS_BEGIN, glBegin)
55
        def test( t, polyData=None ):
56
            glNormal( 0,0, -1 )
57
            glColor3f( t[0],t[1],t[2] )
58
            return glVertex3f( t[0],t[1],t[2])
59
        gluTessCallback(self.tess, GLU_TESS_VERTEX_DATA, test)
60
        gluTessCallback(self.tess, GLU_TESS_END, glEnd);
61
        def combine( points, vertices, weights ):
62
            #print 'combine called', points, vertices, weights
63
            return points
64
        gluTessCallback(self.tess, GLU_TESS_COMBINE, combine)
65
        gluTessBeginPolygon( self.tess, None )
66
        try:
67
            gluTessBeginContour( self.tess )
68
            try:
69
                for (x,y) in outline:
70
                    vertex = array((x/scale,y/scale,0.0),'d')
71
                    gluTessVertex(self.tess, vertex, vertex)
72
            finally:
73
                gluTessEndContour( self.tess )
74
        finally:
75
            gluTessEndPolygon(self.tess)
76 1
77
if __name__ == "__main__":
78 308
    TestContext.ContextMainLoop()

Loggerhead 1.10 is a web-based interface for Bazaar branches