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)
25 win
= wxFrame(frame
, -1, "GL Cube", wxDefaultPosition
, wxSize(400,300))
26 canvas
= TestGLCanvas(win
)
33 class TestGLCanvas(wxGLCanvas
):
34 def __init__(self
, parent
):
35 wxGLCanvas
.__init
__(self
, parent
, -1)
36 EVT_ERASE_BACKGROUND(self
, self
.OnEraseBackground
)
38 EVT_CHAR(self
, self
.MyOnChar
)
40 def MyOnChar(self
, event
):
43 def OnEraseBackground(self
, event
):
44 pass # Do nothing, to avoid flashing.
47 def OnSize(self
, event
):
48 size
= self
.GetClientSize()
49 if self
.GetContext() != 'NULL':
51 glViewport(0, 0, size
.width
, size
.height
)
54 def OnPaint(self
, event
):
57 ctx
= self
.GetContext()
67 # clear color and depth buffers
68 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT
);
70 # draw six faces of a cube
72 glNormal3f( 0.0, 0.0, 1.0)
73 glVertex3f( 0.5, 0.5, 0.5)
74 glVertex3f(-0.5, 0.5, 0.5)
75 glVertex3f(-0.5,-0.5, 0.5)
76 glVertex3f( 0.5,-0.5, 0.5)
78 glNormal3f( 0.0, 0.0,-1.0)
79 glVertex3f(-0.5,-0.5,-0.5)
80 glVertex3f(-0.5, 0.5,-0.5)
81 glVertex3f( 0.5, 0.5,-0.5)
82 glVertex3f( 0.5,-0.5,-0.5)
84 glNormal3f( 0.0, 1.0, 0.0)
85 glVertex3f( 0.5, 0.5, 0.5)
86 glVertex3f( 0.5, 0.5,-0.5)
87 glVertex3f(-0.5, 0.5,-0.5)
88 glVertex3f(-0.5, 0.5, 0.5)
90 glNormal3f( 0.0,-1.0, 0.0)
91 glVertex3f(-0.5,-0.5,-0.5)
92 glVertex3f( 0.5,-0.5,-0.5)
93 glVertex3f( 0.5,-0.5, 0.5)
94 glVertex3f(-0.5,-0.5, 0.5)
96 glNormal3f( 1.0, 0.0, 0.0)
97 glVertex3f( 0.5, 0.5, 0.5)
98 glVertex3f( 0.5,-0.5, 0.5)
99 glVertex3f( 0.5,-0.5,-0.5)
100 glVertex3f( 0.5, 0.5,-0.5)
102 glNormal3f(-1.0, 0.0, 0.0)
103 glVertex3f(-0.5,-0.5,-0.5)
104 glVertex3f(-0.5,-0.5, 0.5)
105 glVertex3f(-0.5, 0.5, 0.5)
106 glVertex3f(-0.5, 0.5,-0.5)
113 # set viewing projection
114 glMatrixMode(GL_PROJECTION
);
115 glFrustum(-0.5, 0.5, -0.5, 0.5, 1.0, 3.0);
118 glMatrixMode(GL_MODELVIEW
);
119 glTranslatef(0.0, 0.0, -2.0);
122 glRotatef(30.0, 1.0, 0.0, 0.0);
123 glRotatef(30.0, 0.0, 1.0, 0.0);
125 glEnable(GL_DEPTH_TEST
);
126 glEnable(GL_LIGHTING
);
133 #----------------------------------------------------------------------
149 #----------------------------------------------------------------------
154 frame
= wxFrame(NULL
, -1, "GL Cube", wxDefaultPosition
, wxSize(400,300))
155 win
= TestGLCanvas(frame
)
157 self
.SetTopWindow(frame
)
163 if __name__
== '__main__':