X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/e7d0a4140bd616d07d67dbc3be0826d7b0342693..26b0b998042f7a87ebbf040c071b9748574290ba:/wxPython/demo/wxGLCanvas.py diff --git a/wxPython/demo/wxGLCanvas.py b/wxPython/demo/wxGLCanvas.py index 0374cf50ef..a4d0194cb0 100644 --- a/wxPython/demo/wxGLCanvas.py +++ b/wxPython/demo/wxGLCanvas.py @@ -1,19 +1,18 @@ - from wxPython.wx import * try: from wxPython.glcanvas import * - haveGLCanvas = true + haveGLCanvas = True except ImportError: - haveGLCanvas = false + haveGLCanvas = False try: # The Python OpenGL package can be found at # http://PyOpenGL.sourceforge.net/ from OpenGL.GL import * from OpenGL.GLUT import * - haveOpenGL = true + haveOpenGL = True except ImportError: - haveOpenGL = false + haveOpenGL = False #---------------------------------------------------------------------- @@ -57,15 +56,22 @@ else: box.Add(btn, 0, wxALIGN_CENTER|wxALL, 15) EVT_BUTTON(self, k, self.OnButton) - self.SetAutoLayout(true) + #** Enable this to show putting a wxGLCanvas on the wxPanel + if 0: + c = CubeCanvas(self) + c.SetSize((200, 200)) + box.Add(c, 0, wxALIGN_CENTER|wxALL, 15) + + self.SetAutoLayout(True) self.SetSizer(box) + def OnButton(self, evt): canvasClassName = buttonDefs[evt.GetId()][0] canvasClass = eval(canvasClassName) frame = wxFrame(None, -1, canvasClassName, size=(400,400)) canvas = canvasClass(frame) - frame.Show(true) + frame.Show(True) @@ -75,10 +81,11 @@ else: + class MyCanvasBase(wxGLCanvas): def __init__(self, parent): wxGLCanvas.__init__(self, parent, -1) - self.init = false + self.init = False # initial mouse position self.lastx = self.x = 30 self.lasty = self.y = 30 @@ -103,7 +110,7 @@ else: self.SetCurrent() if not self.init: self.InitGL() - self.init = true + self.init = True self.OnDraw() def OnMouseDown(self, evt): @@ -116,7 +123,7 @@ else: if evt.Dragging() and evt.LeftIsDown(): self.x, self.y = self.lastx, self.lasty self.x, self.y = evt.GetPosition() - self.Refresh(false) + self.Refresh(False) @@ -183,8 +190,8 @@ else: glVertex3f(-0.5, 0.5,-0.5) glEnd() - glRotatef(self.lasty - self.y, 1.0, 0.0, 0.0); - glRotatef(self.lastx - self.x, 0.0, 1.0, 0.0); + glRotatef((self.lasty - self.y)/100., 1.0, 0.0, 0.0); + glRotatef((self.lastx - self.x)/100., 0.0, 1.0, 0.0); self.SwapBuffers() @@ -211,13 +218,13 @@ else: glDepthFunc(GL_LESS) glEnable(GL_DEPTH_TEST) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) + # position viewer + glMatrixMode(GL_MODELVIEW); def OnDraw(self): # clear color and depth buffers glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - # position viewer - glMatrixMode(GL_MODELVIEW); # use a fresh transformation matrix glPushMatrix() # position object @@ -227,8 +234,10 @@ else: glTranslate(0, -1, 0) glRotate(250, 1, 0, 0) - glutSolidCone(1, 2, 50, 10) + glutSolidCone(0.5, 1, 30, 5) glPopMatrix() + glRotatef((self.lasty - self.y)/100., 0.0, 0.0, 1.0); + glRotatef(0.0, (self.lastx - self.x)/100., 1.0, 0.0); # push into visible buffer self.SwapBuffers() @@ -259,12 +268,13 @@ def _test(): frame = wxFrame(None, -1, "GL Demos", wxDefaultPosition, wxSize(600,300)) #win = ConeCanvas(frame) MySplitter(frame) - frame.Show(TRUE) + frame.Show(True) self.SetTopWindow(frame) - return TRUE + return True app = MyApp(0) app.MainLoop() if __name__ == '__main__': _test() +