Statistics
| Revision:

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

History | View | Annotate | Download (2.6 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.Tk import *
15

    
16
def new_file(self):
17
    print "opening new file"
18

    
19
def open_file(self):
20
    print "opening OLD file"
21

    
22
def print_something(self):
23
    print "picked a menu item"
24

    
25

    
26
class Demo:
27
        def __init__(self, root):
28
                self.mBar = Frame(root, relief=RAISED, borderwidth=2)
29
                self.mBar.pack(fill=X)
30
                demo = self.makeDemoMenu()
31
                self.mBar.tk_menuBar(demo)
32
                self.ogl = Opengl(width = 300, height = 300, double = 1, depth = 1)
33
                self.ogl.redraw = self.draw_lines
34
                self.ogl.set_centerpoint(30, 0, 0)
35
                self.ogl.set_eyepoint(140)
36
                self.ogl.pack(side = 'top', expand = 1, fill = 'both')
37
                self.ogl.grob = -1
38

    
39
        def makeDemoMenu(self):
40
                demo = Menubutton(self.mBar, text='Demos', underline=0)
41
                demo.pack(side=LEFT, padx="2m")
42
                demo.menu = Menu(demo)
43

    
44
                demo.menu.add_command(label='Blue', underline=0, command=self.set_blue)
45
                demo.menu.add_command(label='Lines', underline=0,command=self.set_lines)
46
                demo.menu.add_command(label='Text', underline=0,command=self.set_text)
47
   
48
                demo.menu.add('separator')
49
                demo.menu.add_command(label='Quit', underline=0, background='red', 
50
                                                                     activebackground='green',
51
                                                                         command=demo.quit)
52

    
53
                demo['menu'] = demo.menu
54
                return demo
55

    
56
        def draw_lines(self, ogl):
57
                glClearColor(0, 0, 0, 0)
58
                glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
59
                glDisable(GL_LIGHTING)
60
                glBegin(GL_LINES)
61
                glColor3f(1,1,0)
62
                glVertex2f(0,-30)
63
                glColor3f(1,0,1)
64
                glVertex2f(60,30)
65
                glColor3f(1,0,0)
66
                glVertex2f(60,-30)
67
                glColor3f(0,0,1)
68
                glVertex2f(0,30)
69
                glEnd()
70
                glEnable(GL_LIGHTING)
71

    
72
        def set_lines(self):
73
                self.ogl.redraw = self.draw_lines
74
                self.ogl.tkRedraw()
75

    
76
        def draw_blue(self, ogl):
77
                glClearColor(0, 0, 1, 0)
78
                glClear(GL_COLOR_BUFFER_BIT)
79

    
80
        def set_blue(self):
81
                self.ogl.redraw = self.draw_blue
82
                self.ogl.tkRedraw()
83

    
84
        def draw_text(self, ogl):
85
                glClearColor(0, 0, 0.5, 0)
86
                glClear(GL_COLOR_BUFFER_BIT)
87
                if ogl.grob == -1:
88
                        from logo import define_logo
89
                        ogl.grob = glGenLists(1);
90
                        glNewList(ogl.grob, GL_COMPILE_AND_EXECUTE);
91
                        glMaterialfv(GL_FRONT, GL_DIFFUSE, [1, 0, 0, 0])
92
                        define_logo()
93
                        glEndList()
94
                else:
95
                        glCallList(ogl.grob)
96

    
97
        def set_text(self):
98
                self.ogl.redraw = self.draw_text
99
                self.ogl.tkRedraw()
100

    
101
root = Tk()
102
d = Demo(root)
103
root.mainloop()