2 from wxPython
.wx
import *
4 from wxPython
.glcanvas
import *
5 from OpenGL
.GL
import *
6 from OpenGL
.GLUT
import *
11 #----------------------------------------------------------------------
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
)
23 def runTest(frame
, nb
, log
):
24 win
= wxFrame(frame
, -1, "GL Demos", wxDefaultPosition
, wxSize(300,300))
32 class MySplitter(wxSplitterWindow
):
33 def __init__(self
, parent
):
34 wxSplitterWindow
.__init
__(self
, parent
, -1)
35 cube
= CubeCanvas(self
)
36 cone
= ConeCanvas(self
)
38 self
.SplitVertically(cube
, cone
)
39 self
.SetSashPosition(300)
43 class CubeCanvas(wxGLCanvas
):
44 def __init__(self
, parent
):
45 wxGLCanvas
.__init
__(self
, parent
, -1)
46 EVT_ERASE_BACKGROUND(self
, self
.OnEraseBackground
)
49 def OnEraseBackground(self
, event
):
50 pass # Do nothing, to avoid flashing.
52 def OnSize(self
, event
):
53 size
= self
.GetClientSize()
56 glViewport(0, 0, size
.width
, size
.height
)
59 def OnPaint(self
, event
):
68 # clear color and depth buffers
69 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT
);
71 # draw six faces of a cube
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)
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)
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)
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)
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)
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)
114 # set viewing projection
115 glMatrixMode(GL_PROJECTION
);
116 glFrustum(-0.5, 0.5, -0.5, 0.5, 1.0, 3.0);
119 glMatrixMode(GL_MODELVIEW
);
120 glTranslatef(0.0, 0.0, -2.0);
123 glRotatef(30.0, 1.0, 0.0, 0.0);
124 glRotatef(30.0, 0.0, 1.0, 0.0);
126 glEnable(GL_DEPTH_TEST
);
127 glEnable(GL_LIGHTING
);
132 class ConeCanvas(wxGLCanvas
):
133 def __init__(self
, parent
):
134 wxGLCanvas
.__init
__(self
, parent
, -1)
135 EVT_ERASE_BACKGROUND(self
, self
.OnEraseBackground
)
138 def OnEraseBackground(self
, event
):
139 pass # Do nothing, to avoid flashing.
141 def OnSize(self
, event
):
142 size
= self
.GetClientSize()
143 if self
.GetContext():
145 glViewport(0, 0, size
.width
, size
.height
)
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
)
163 glEnable(GL_DEPTH_TEST
)
164 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT
)
167 def OnPaint( self
, event
):
173 ### Tell system to use _this_ glcanvas for all commands
175 # clear color and depth buffers
176 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT
);
178 glMatrixMode(GL_MODELVIEW
);
179 # use a fresh transformation matrix
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);
187 glTranslate(0, -1, 0)
188 glRotate(250, 1, 0, 0)
189 glutSolidCone(1, 2, 50, 10)
191 # push into visible buffer
195 #----------------------------------------------------------------------
211 #----------------------------------------------------------------------
216 frame
= wxFrame(NULL
, -1, "GL Demos", wxDefaultPosition
, wxSize(600,300))
217 #win = ConeCanvas(frame)
220 self
.SetTopWindow(frame
)
226 if __name__
== '__main__':