]> git.saurik.com Git - wxWidgets.git/blob - utils/wxPython/demo/wxGLCanvas.py
jconfig.h uses configures results
[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 return win
24
25
26
27 class TestGLCanvas(wxGLCanvas):
28 def __init__(self, parent):
29 wxGLCanvas.__init__(self, parent, -1)
30 EVT_ERASE_BACKGROUND(self, self.OnEraseBackground)
31 self.init = false
32
33 def OnEraseBackground(self, event):
34 pass # Do nothing, to avoid flashing.
35
36
37 def OnSize(self, event):
38 size = self.GetClientSize()
39 if self.GetContext() != 'NULL':
40 self.SetCurrent()
41 glViewport(0, 0, size.width, size.height)
42
43
44 def OnPaint(self, event):
45 dc = wxPaintDC(self)
46
47 ctx = self.GetContext()
48 if ctx == "NULL": return
49
50 self.SetCurrent()
51
52
53 if not self.init:
54 self.InitGL()
55 self.init = true
56
57 # clear color and depth buffers
58 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
59
60 # draw six faces of a cube
61 glBegin(GL_QUADS)
62 glNormal3f( 0.0, 0.0, 1.0)
63 glVertex3f( 0.5, 0.5, 0.5)
64 glVertex3f(-0.5, 0.5, 0.5)
65 glVertex3f(-0.5,-0.5, 0.5)
66 glVertex3f( 0.5,-0.5, 0.5)
67
68 glNormal3f( 0.0, 0.0,-1.0)
69 glVertex3f(-0.5,-0.5,-0.5)
70 glVertex3f(-0.5, 0.5,-0.5)
71 glVertex3f( 0.5, 0.5,-0.5)
72 glVertex3f( 0.5,-0.5,-0.5)
73
74 glNormal3f( 0.0, 1.0, 0.0)
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 glVertex3f(-0.5, 0.5, 0.5)
79
80 glNormal3f( 0.0,-1.0, 0.0)
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 glVertex3f(-0.5,-0.5, 0.5)
85
86 glNormal3f( 1.0, 0.0, 0.0)
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 glVertex3f( 0.5, 0.5,-0.5)
91
92 glNormal3f(-1.0, 0.0, 0.0)
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 glVertex3f(-0.5, 0.5,-0.5)
97 glEnd()
98
99 self.SwapBuffers()
100
101
102 def InitGL(self):
103 # set viewing projection
104 glMatrixMode(GL_PROJECTION);
105 glFrustum(-0.5, 0.5, -0.5, 0.5, 1.0, 3.0);
106
107 # position viewer
108 glMatrixMode(GL_MODELVIEW);
109 glTranslatef(0.0, 0.0, -2.0);
110
111 # position object
112 glRotatef(30.0, 1.0, 0.0, 0.0);
113 glRotatef(30.0, 0.0, 1.0, 0.0);
114
115 glEnable(GL_DEPTH_TEST);
116 glEnable(GL_LIGHTING);
117 glEnable(GL_LIGHT0);
118
119
120
121
122
123
124
125
126
127
128
129
130
131 overview = """\
132 """
133
134
135
136
137
138 #----------------------------------------------------------------------
139
140 def _test():
141 class MyApp(wxApp):
142 def OnInit(self):
143 frame = wxFrame(NULL, -1, "HELP ME!!")
144 win = TestGLCanvas(frame)
145 frame.Show(TRUE)
146 self.SetTopWindow(frame)
147 return TRUE
148
149 app = MyApp(0)
150 app.MainLoop()
151
152 if __name__ == '__main__':
153 _test()