]> git.saurik.com Git - wxWidgets.git/blob - utils/wxPython/demo/wxGLCanvas.py
more unused param warnings fixed
[wxWidgets.git] / utils / wxPython / demo / wxGLCanvas.py
1
2 from wxPython.wx import *
3 try:
4 from wxPython.glcanvas import *
5 from OpenGL.GL import *
6 from OpenGL.GLUT import *
7 haveGLCanvas = true
8 except ImportError:
9 haveGLCanvas = false
10
11 #----------------------------------------------------------------------
12
13 if not haveGLCanvas:
14 def runTest(frame, nb, log):
15 dlg = wxMessageDialog(frame, 'The wxGLCanvas has not been included with this build of wxPython!',
16 'Sorry', wxOK | wxICON_INFORMATION)
17 dlg.ShowModal()
18 dlg.Destroy()
19
20 else:
21
22
23 def runTest(frame, nb, log):
24 win = wxFrame(frame, -1, "GL Demos", wxDefaultPosition, wxSize(300,300))
25 CubeCanvas(win)
26 #MySplitter(win)
27 frame.otherWin = win
28 win.Show(true)
29 return None
30
31
32 class MySplitter(wxSplitterWindow):
33 def __init__(self, parent):
34 wxSplitterWindow.__init__(self, parent, -1)
35 cube = CubeCanvas(self)
36 cone = ConeCanvas(self)
37
38 self.SplitVertically(cube, cone)
39 self.SetSashPosition(300)
40
41
42
43 class CubeCanvas(wxGLCanvas):
44 def __init__(self, parent):
45 wxGLCanvas.__init__(self, parent, -1)
46 EVT_ERASE_BACKGROUND(self, self.OnEraseBackground)
47 self.init = false
48
49 def OnEraseBackground(self, event):
50 pass # Do nothing, to avoid flashing.
51
52 def OnSize(self, event):
53 size = self.GetClientSize()
54 if self.GetContext():
55 self.SetCurrent()
56 glViewport(0, 0, size.width, size.height)
57
58
59 def OnPaint(self, event):
60 dc = wxPaintDC(self)
61
62 self.SetCurrent()
63
64 if not self.init:
65 self.InitGL()
66 self.init = true
67
68 # clear color and depth buffers
69 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
70
71 # draw six faces of a cube
72 glBegin(GL_QUADS)
73 glNormal3f( 0.0, 0.0, 1.0)
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 glVertex3f( 0.5,-0.5, 0.5)
78
79 glNormal3f( 0.0, 0.0,-1.0)
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 glVertex3f( 0.5,-0.5,-0.5)
84
85 glNormal3f( 0.0, 1.0, 0.0)
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 glVertex3f(-0.5, 0.5, 0.5)
90
91 glNormal3f( 0.0,-1.0, 0.0)
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 glVertex3f(-0.5,-0.5, 0.5)
96
97 glNormal3f( 1.0, 0.0, 0.0)
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 glVertex3f( 0.5, 0.5,-0.5)
102
103 glNormal3f(-1.0, 0.0, 0.0)
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 glVertex3f(-0.5, 0.5,-0.5)
108 glEnd()
109
110 self.SwapBuffers()
111
112
113 def InitGL(self):
114 # set viewing projection
115 glMatrixMode(GL_PROJECTION);
116 glFrustum(-0.5, 0.5, -0.5, 0.5, 1.0, 3.0);
117
118 # position viewer
119 glMatrixMode(GL_MODELVIEW);
120 glTranslatef(0.0, 0.0, -2.0);
121
122 # position object
123 glRotatef(30.0, 1.0, 0.0, 0.0);
124 glRotatef(30.0, 0.0, 1.0, 0.0);
125
126 glEnable(GL_DEPTH_TEST);
127 glEnable(GL_LIGHTING);
128 glEnable(GL_LIGHT0);
129
130
131
132 class ConeCanvas(wxGLCanvas):
133 def __init__(self, parent):
134 wxGLCanvas.__init__(self, parent, -1)
135 EVT_ERASE_BACKGROUND(self, self.OnEraseBackground)
136 self.init = false
137
138 def OnEraseBackground(self, event):
139 pass # Do nothing, to avoid flashing.
140
141 def OnSize(self, event):
142 size = self.GetClientSize()
143 if self.GetContext():
144 self.SetCurrent()
145 glViewport(0, 0, size.width, size.height)
146
147 def GLInit( self ):
148 glMatrixMode(GL_PROJECTION);
149 # camera frustrum setup
150 glFrustum(-0.5, 0.5, -0.5, 0.5, 1.0, 3.0);
151 glMaterial(GL_FRONT, GL_AMBIENT, [0.2, 0.2, 0.2, 1.0])
152 glMaterial(GL_FRONT, GL_DIFFUSE, [0.8, 0.8, 0.8, 1.0])
153 glMaterial(GL_FRONT, GL_SPECULAR, [1.0, 0.0, 1.0, 1.0])
154 glMaterial(GL_FRONT, GL_SHININESS, 50.0)
155 glLight(GL_LIGHT0, GL_AMBIENT, [0.0, 1.0, 0.0, 1.0])
156 glLight(GL_LIGHT0, GL_DIFFUSE, [1.0, 1.0, 1.0, 1.0])
157 glLight(GL_LIGHT0, GL_SPECULAR, [1.0, 1.0, 1.0, 1.0])
158 glLight(GL_LIGHT0, GL_POSITION, [1.0, 1.0, 1.0, 0.0]);
159 glLightModel(GL_LIGHT_MODEL_AMBIENT, [0.2, 0.2, 0.2, 1.0])
160 glEnable(GL_LIGHTING)
161 glEnable(GL_LIGHT0)
162 glDepthFunc(GL_LESS)
163 glEnable(GL_DEPTH_TEST)
164 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
165
166
167 def OnPaint( self, event ):
168 dc = wxPaintDC(self)
169 if not self.init:
170 self.GLInit()
171 self.init = true
172
173 ### Tell system to use _this_ glcanvas for all commands
174 self.SetCurrent()
175 # clear color and depth buffers
176 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
177 # position viewer
178 glMatrixMode(GL_MODELVIEW);
179 # use a fresh transformation matrix
180 glPushMatrix()
181 # position object
182 glTranslate(0.0, 0.0, -2.0);
183 glRotate(30.0, 1.0, 0.0, 0.0);
184 glRotate(30.0, 0.0, 1.0, 0.0);
185
186 ### From cone.py
187 glTranslate(0, -1, 0)
188 glRotate(250, 1, 0, 0)
189 glutSolidCone(1, 2, 50, 10)
190 glPopMatrix()
191 # push into visible buffer
192 self.SwapBuffers()
193
194
195 #----------------------------------------------------------------------
196
197
198
199
200
201
202
203
204 overview = """\
205 """
206
207
208
209
210
211 #----------------------------------------------------------------------
212
213 def _test():
214 class MyApp(wxApp):
215 def OnInit(self):
216 frame = wxFrame(NULL, -1, "GL Demos", wxDefaultPosition, wxSize(600,300))
217 #win = ConeCanvas(frame)
218 MySplitter(frame)
219 frame.Show(TRUE)
220 self.SetTopWindow(frame)
221 return TRUE
222
223 app = MyApp(0)
224 app.MainLoop()
225
226 if __name__ == '__main__':
227 _test()