2 from wxPython
.wx
import *
4 from wxPython
.glcanvas
import *
9 #----------------------------------------------------------------------
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
)
21 def runTest(frame
, nb
, log
):
22 #win = TestGLCanvas(nb)
24 win
= wxFrame(frame
, -1, "GL Cube", wxDefaultPosition
, wxSize(400,300))
25 canvas
= TestGLCanvas(win
)
32 class TestGLCanvas(wxGLCanvas
):
33 def __init__(self
, parent
):
34 wxGLCanvas
.__init
__(self
, parent
, -1)
35 EVT_ERASE_BACKGROUND(self
, self
.OnEraseBackground
)
38 def OnEraseBackground(self
, event
):
39 pass # Do nothing, to avoid flashing.
42 def OnSize(self
, event
):
43 size
= self
.GetClientSize()
44 if self
.GetContext() != 'NULL':
46 glViewport(0, 0, size
.width
, size
.height
)
49 def OnPaint(self
, event
):
52 ctx
= self
.GetContext()
53 if ctx
== "NULL": return
62 # clear color and depth buffers
63 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT
);
65 # draw six faces of a cube
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)
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, 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)
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( 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)
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)
108 # set viewing projection
109 glMatrixMode(GL_PROJECTION
);
110 glFrustum(-0.5, 0.5, -0.5, 0.5, 1.0, 3.0);
113 glMatrixMode(GL_MODELVIEW
);
114 glTranslatef(0.0, 0.0, -2.0);
117 glRotatef(30.0, 1.0, 0.0, 0.0);
118 glRotatef(30.0, 0.0, 1.0, 0.0);
120 glEnable(GL_DEPTH_TEST
);
121 glEnable(GL_LIGHTING
);
143 #----------------------------------------------------------------------
148 frame
= wxFrame(NULL
, -1, "GL Cube", wxDefaultPosition
, wxSize(400,300))
149 win
= TestGLCanvas(frame
)
151 self
.SetTopWindow(frame
)
157 if __name__
== '__main__':