Statistics
| Revision:

root / PyOpenGL-Demo / tom / checker.py @ 1

History | View | Annotate | Download (1.4 kB)

1
#!/usr/bin/python
2

    
3
# This is statement is required by the build system to query build info
4
if __name__ == '__build__':
5
        raise Exception
6

    
7

    
8
import string
9
__version__ = string.split('$Revision: 1.1.1.1 $')[1]
10
__date__ = string.join(string.split('$Date: 2007/02/15 19:25:38 $')[1:3], ' ')
11
__author__ = 'Tarn Weisner Burton <twburton@users.sourceforge.net>'
12

    
13
from OpenGL.GL import *
14
from OpenGL.GLUT import *
15
from OpenGL.Tk import *
16
import sys
17

    
18
def redraw(o):
19
        glClearColor(1, 0, 1, 0)
20
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
21
        glColor3f(0, 1, 0)
22
        #draw checkerboard
23
        N = 4
24
        glDisable(GL_LIGHTING)
25
        for x in range(-N, N):
26
                for y in range(-N, N):
27
                        if (x + y) % 2 == 0:
28
                                glColor3f(1, 1, 1)
29
                        else:
30
                                glColor3f(0, 0, 0)        
31
                        glRectf(x, y, x + 1, y + 1)
32
        glEnable(GL_LIGHTING)
33

    
34
        glPushMatrix()
35
        glTranslatef(0., 0., 1.)
36
        glutSolidSphere(1.0,20,20)
37
        glPopMatrix()
38

    
39
def main():
40
        f = Frame()
41
        f.pack(side = 'top')
42
        o = Opengl(width = 200, height = 200, double = 1, depth = 1)
43
        glutInit( [] )
44
        o.redraw = redraw
45
        quit = Button(f, text = 'Quit', command = sys.exit)
46
        quit.pack({'side':'top', 'side':'left'})
47
        help = Button(f, text = 'Help', command = o.help)
48
        help.pack({'side':'top', 'side':'left'})
49
        reset = Button(f, text = 'Reset', command = o.reset)
50
        reset.pack({'side':'top', 'side':'left'})
51
        o.pack(side = 'top', expand = 1, fill = 'both')
52
        o.set_eyepoint(20.)
53
        o.mainloop()
54

    
55
main()