]> git.saurik.com Git - wxWidgets.git/blob - utils/wxPython/demo/wxGLCanvas.py
Added some test code...
[wxWidgets.git] / utils / wxPython / demo / wxGLCanvas.py
1
2 from wxPython.wx import *
3 try:
4 from wxPython.glcanvas import *
5 haveGLCanvas = true
6 except ImportError:
7 haveGLCanvas = false
8
9 #----------------------------------------------------------------------
10
11 if not haveGLCanvas:
12 def runTest(frame, nb, log):
13 dlg = wxMessageDialog(frame, 'The wxGLCanvas has not been included with this build of wxPython!',
14 'Sorry', wxOK | wxICON_INFORMATION)
15 dlg.ShowModal()
16 dlg.Destroy()
17
18 else:
19
20
21 def runTest(frame, nb, log):
22 #win = TestGLCanvas(nb)
23 #win.SetFocus()
24 #return win
25 win = wxFrame(frame, -1, "GL Cube", wxDefaultPosition, wxSize(400,300))
26 canvas = TestGLCanvas(win)
27 frame.otherWin = win
28 win.Show(true)
29 return None
30
31
32
33 class TestGLCanvas(wxGLCanvas):
34 def __init__(self, parent):
35 wxGLCanvas.__init__(self, parent, -1)
36 EVT_ERASE_BACKGROUND(self, self.OnEraseBackground)
37 self.init = false
38 EVT_CHAR(self, self.MyOnChar)
39
40 def MyOnChar(self, event):
41 print "MyOnChar"
42
43 def OnEraseBackground(self, event):
44 pass # Do nothing, to avoid flashing.
45
46
47 def OnSize(self, event):
48 size = self.GetClientSize()
49 if self.GetContext() != 'NULL':
50 self.SetCurrent()
51 glViewport(0, 0, size.width, size.height)
52
53
54 def OnPaint(self, event):
55 dc = wxPaintDC(self)
56
57 ctx = self.GetContext()
58 if not ctx: return
59
60 self.SetCurrent()
61
62
63 if not self.init:
64 self.InitGL()
65 self.init = true
66
67 # clear color and depth buffers
68 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
69
70 # draw six faces of a cube
71 glBegin(GL_QUADS)
72 glNormal3f( 0.0, 0.0, 1.0)
73 glVertex3f( 0.5, 0.5, 0.5)
74 glVertex3f(-0.5, 0.5, 0.5)
75 glVertex3f(-0.5,-0.5, 0.5)
76 glVertex3f( 0.5,-0.5, 0.5)
77
78 glNormal3f( 0.0, 0.0,-1.0)
79 glVertex3f(-0.5,-0.5,-0.5)
80 glVertex3f(-0.5, 0.5,-0.5)
81 glVertex3f( 0.5, 0.5,-0.5)
82 glVertex3f( 0.5,-0.5,-0.5)
83
84 glNormal3f( 0.0, 1.0, 0.0)
85 glVertex3f( 0.5, 0.5, 0.5)
86 glVertex3f( 0.5, 0.5,-0.5)
87 glVertex3f(-0.5, 0.5,-0.5)
88 glVertex3f(-0.5, 0.5, 0.5)
89
90 glNormal3f( 0.0,-1.0, 0.0)
91 glVertex3f(-0.5,-0.5,-0.5)
92 glVertex3f( 0.5,-0.5,-0.5)
93 glVertex3f( 0.5,-0.5, 0.5)
94 glVertex3f(-0.5,-0.5, 0.5)
95
96 glNormal3f( 1.0, 0.0, 0.0)
97 glVertex3f( 0.5, 0.5, 0.5)
98 glVertex3f( 0.5,-0.5, 0.5)
99 glVertex3f( 0.5,-0.5,-0.5)
100 glVertex3f( 0.5, 0.5,-0.5)
101
102 glNormal3f(-1.0, 0.0, 0.0)
103 glVertex3f(-0.5,-0.5,-0.5)
104 glVertex3f(-0.5,-0.5, 0.5)
105 glVertex3f(-0.5, 0.5, 0.5)
106 glVertex3f(-0.5, 0.5,-0.5)
107 glEnd()
108
109 self.SwapBuffers()
110
111
112 def InitGL(self):
113 # set viewing projection
114 glMatrixMode(GL_PROJECTION);
115 glFrustum(-0.5, 0.5, -0.5, 0.5, 1.0, 3.0);
116
117 # position viewer
118 glMatrixMode(GL_MODELVIEW);
119 glTranslatef(0.0, 0.0, -2.0);
120
121 # position object
122 glRotatef(30.0, 1.0, 0.0, 0.0);
123 glRotatef(30.0, 0.0, 1.0, 0.0);
124
125 glEnable(GL_DEPTH_TEST);
126 glEnable(GL_LIGHTING);
127 glEnable(GL_LIGHT0);
128
129
130
131
132
133 #----------------------------------------------------------------------
134
135
136
137
138
139
140
141
142 overview = """\
143 """
144
145
146
147
148
149 #----------------------------------------------------------------------
150
151 def _test():
152 class MyApp(wxApp):
153 def OnInit(self):
154 frame = wxFrame(NULL, -1, "GL Cube", wxDefaultPosition, wxSize(400,300))
155 win = TestGLCanvas(frame)
156 frame.Show(TRUE)
157 self.SetTopWindow(frame)
158 return TRUE
159
160 app = MyApp(0)
161 app.MainLoop()
162
163 if __name__ == '__main__':
164 _test()