2 from wxPython
.wx
import *
4 from wxPython
.glcanvas
import *
10 # The Python OpenGL package can be found at
11 # http://PyOpenGL.sourceforge.net/
12 from OpenGL
.GL
import *
13 from OpenGL
.GLUT
import *
18 #----------------------------------------------------------------------
21 def runTest(frame
, nb
, log
):
22 dlg
= wxMessageDialog(frame
, 'The wxGLCanvas has not been included with this build of wxPython!',
23 'Sorry', wxOK | wxICON_INFORMATION
)
28 def runTest(frame
, nb
, log
):
29 dlg
= wxMessageDialog(frame
,
30 'The OpenGL package was not found. You can get it at\n'
31 'http://PyOpenGL.sourceforge.net/',
32 'Sorry', wxOK | wxICON_INFORMATION
)
38 def runTest(frame
, nb
, log
):
39 win
= wxFrame(frame
, -1, "GL Demos", wxDefaultPosition
, wxSize(300,300))
47 class MySplitter(wxSplitterWindow
):
48 def __init__(self
, parent
):
49 wxSplitterWindow
.__init
__(self
, parent
, -1)
50 cube
= CubeCanvas(self
)
51 cone
= ConeCanvas(self
)
53 self
.SplitVertically(cube
, cone
)
54 self
.SetSashPosition(300)
58 class CubeCanvas(wxGLCanvas
):
59 def __init__(self
, parent
):
60 wxGLCanvas
.__init
__(self
, parent
, -1) #,
61 #attribList=[GL_RED_BITS, 4, GL_DOUBLEBUFFER] )
62 EVT_ERASE_BACKGROUND(self
, self
.OnEraseBackground
)
63 EVT_SIZE(self
, self
.OnSize
)
64 EVT_PAINT(self
, self
.OnPaint
)
67 def OnEraseBackground(self
, event
):
68 pass # Do nothing, to avoid flashing.
70 def OnSize(self
, event
):
71 size
= self
.GetClientSize()
74 glViewport(0, 0, size
.width
, size
.height
)
77 def OnPaint(self
, event
):
86 # clear color and depth buffers
87 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT
);
89 # draw six faces of a cube
91 glNormal3f( 0.0, 0.0, 1.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( 0.0, 0.0,-1.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( 0.0, 1.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)
109 glNormal3f( 0.0,-1.0, 0.0)
110 glVertex3f(-0.5,-0.5,-0.5)
111 glVertex3f( 0.5,-0.5,-0.5)
112 glVertex3f( 0.5,-0.5, 0.5)
113 glVertex3f(-0.5,-0.5, 0.5)
115 glNormal3f( 1.0, 0.0, 0.0)
116 glVertex3f( 0.5, 0.5, 0.5)
117 glVertex3f( 0.5,-0.5, 0.5)
118 glVertex3f( 0.5,-0.5,-0.5)
119 glVertex3f( 0.5, 0.5,-0.5)
121 glNormal3f(-1.0, 0.0, 0.0)
122 glVertex3f(-0.5,-0.5,-0.5)
123 glVertex3f(-0.5,-0.5, 0.5)
124 glVertex3f(-0.5, 0.5, 0.5)
125 glVertex3f(-0.5, 0.5,-0.5)
132 # set viewing projection
133 glMatrixMode(GL_PROJECTION
);
134 glFrustum(-0.5, 0.5, -0.5, 0.5, 1.0, 3.0);
137 glMatrixMode(GL_MODELVIEW
);
138 glTranslatef(0.0, 0.0, -2.0);
141 glRotatef(30.0, 1.0, 0.0, 0.0);
142 glRotatef(30.0, 0.0, 1.0, 0.0);
144 glEnable(GL_DEPTH_TEST
);
145 glEnable(GL_LIGHTING
);
150 class ConeCanvas(wxGLCanvas
):
151 def __init__(self
, parent
):
152 wxGLCanvas
.__init
__(self
, parent
, -1)
153 EVT_ERASE_BACKGROUND(self
, self
.OnEraseBackground
)
154 EVT_SIZE(self
, self
.OnSize
)
155 EVT_PAINT(self
, self
.OnPaint
)
158 def OnEraseBackground(self
, event
):
159 pass # Do nothing, to avoid flashing.
161 def OnSize(self
, event
):
162 size
= self
.GetClientSize()
163 if self
.GetContext():
165 glViewport(0, 0, size
.width
, size
.height
)
168 glMatrixMode(GL_PROJECTION
);
169 # camera frustrum setup
170 glFrustum(-0.5, 0.5, -0.5, 0.5, 1.0, 3.0);
171 glMaterial(GL_FRONT
, GL_AMBIENT
, [0.2, 0.2, 0.2, 1.0])
172 glMaterial(GL_FRONT
, GL_DIFFUSE
, [0.8, 0.8, 0.8, 1.0])
173 glMaterial(GL_FRONT
, GL_SPECULAR
, [1.0, 0.0, 1.0, 1.0])
174 glMaterial(GL_FRONT
, GL_SHININESS
, 50.0)
175 glLight(GL_LIGHT0
, GL_AMBIENT
, [0.0, 1.0, 0.0, 1.0])
176 glLight(GL_LIGHT0
, GL_DIFFUSE
, [1.0, 1.0, 1.0, 1.0])
177 glLight(GL_LIGHT0
, GL_SPECULAR
, [1.0, 1.0, 1.0, 1.0])
178 glLight(GL_LIGHT0
, GL_POSITION
, [1.0, 1.0, 1.0, 0.0]);
179 glLightModel(GL_LIGHT_MODEL_AMBIENT
, [0.2, 0.2, 0.2, 1.0])
180 glEnable(GL_LIGHTING
)
183 glEnable(GL_DEPTH_TEST
)
184 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT
)
187 def OnPaint( self
, event
):
193 ### Tell system to use _this_ glcanvas for all commands
195 # clear color and depth buffers
196 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT
);
198 glMatrixMode(GL_MODELVIEW
);
199 # use a fresh transformation matrix
202 glTranslate(0.0, 0.0, -2.0);
203 glRotate(30.0, 1.0, 0.0, 0.0);
204 glRotate(30.0, 0.0, 1.0, 0.0);
207 glTranslate(0, -1, 0)
208 glRotate(250, 1, 0, 0)
209 glutSolidCone(1, 2, 50, 10)
211 # push into visible buffer
215 #----------------------------------------------------------------------
231 #----------------------------------------------------------------------
236 frame
= wxFrame(NULL
, -1, "GL Demos", wxDefaultPosition
, wxSize(600,300))
237 #win = ConeCanvas(frame)
240 self
.SetTopWindow(frame
)
246 if __name__
== '__main__':