]>
Commit | Line | Data |
---|---|---|
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 | win = wxFrame(frame, -1, "GL Cube", wxDefaultPosition, wxSize(400,300)) | |
25 | canvas = TestGLCanvas(win) | |
26 | frame.otherWin = win | |
27 | win.Show(true) | |
28 | return None | |
29 | ||
30 | ||
31 | ||
32 | class TestGLCanvas(wxGLCanvas): | |
33 | def __init__(self, parent): | |
34 | wxGLCanvas.__init__(self, parent, -1) | |
35 | EVT_ERASE_BACKGROUND(self, self.OnEraseBackground) | |
36 | self.init = false | |
37 | ||
38 | def OnEraseBackground(self, event): | |
39 | pass # Do nothing, to avoid flashing. | |
40 | ||
41 | ||
42 | def OnSize(self, event): | |
43 | size = self.GetClientSize() | |
44 | if self.GetContext() != 'NULL': | |
45 | self.SetCurrent() | |
46 | glViewport(0, 0, size.width, size.height) | |
47 | ||
48 | ||
49 | def OnPaint(self, event): | |
50 | dc = wxPaintDC(self) | |
51 | ||
52 | ctx = self.GetContext() | |
53 | if ctx == "NULL": return | |
54 | ||
55 | self.SetCurrent() | |
56 | ||
57 | ||
58 | if not self.init: | |
59 | self.InitGL() | |
60 | self.init = true | |
61 | ||
62 | # clear color and depth buffers | |
63 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); | |
64 | ||
65 | # draw six faces of a cube | |
66 | glBegin(GL_QUADS) | |
67 | glNormal3f( 0.0, 0.0, 1.0) | |
68 | glVertex3f( 0.5, 0.5, 0.5) | |
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 | ||
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, 1.0, 0.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( 1.0, 0.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 | glEnd() | |
103 | ||
104 | self.SwapBuffers() | |
105 | ||
106 | ||
107 | def InitGL(self): | |
108 | # set viewing projection | |
109 | glMatrixMode(GL_PROJECTION); | |
110 | glFrustum(-0.5, 0.5, -0.5, 0.5, 1.0, 3.0); | |
111 | ||
112 | # position viewer | |
113 | glMatrixMode(GL_MODELVIEW); | |
114 | glTranslatef(0.0, 0.0, -2.0); | |
115 | ||
116 | # position object | |
117 | glRotatef(30.0, 1.0, 0.0, 0.0); | |
118 | glRotatef(30.0, 0.0, 1.0, 0.0); | |
119 | ||
120 | glEnable(GL_DEPTH_TEST); | |
121 | glEnable(GL_LIGHTING); | |
122 | glEnable(GL_LIGHT0); | |
123 | ||
124 | ||
125 | ||
126 | ||
127 | ||
128 | ||
129 | ||
130 | ||
131 | ||
132 | ||
133 | ||
134 | ||
135 | ||
136 | overview = """\ | |
137 | """ | |
138 | ||
139 | ||
140 | ||
141 | ||
142 | ||
143 | #---------------------------------------------------------------------- | |
144 | ||
145 | def _test(): | |
146 | class MyApp(wxApp): | |
147 | def OnInit(self): | |
148 | frame = wxFrame(NULL, -1, "GL Cube", wxDefaultPosition, wxSize(400,300)) | |
149 | win = TestGLCanvas(frame) | |
150 | frame.Show(TRUE) | |
151 | self.SetTopWindow(frame) | |
152 | return TRUE | |
153 | ||
154 | app = MyApp(0) | |
155 | app.MainLoop() | |
156 | ||
157 | if __name__ == '__main__': | |
158 | _test() |