wxPython & PyOpenGL

Mike C. Fletcher mcfletch at rogers.com
Wed Apr 16 15:25:08 EDT 2003


wxPython definitely works with PyOpenGL on Win2K (it's the primary 
development platform for OpenGLContext :) ).  What's wrong with your 
code is that you never tell OpenGL the size of the window into which it 
should render.  Try this:

    def OnPaint(self, event):
        dc = wxPaintDC(self)
        self.SetCurrent()
        size = self.GetClientSize()
        glViewport( 0,0, *size )
        DrawGL()
        self.SwapBuffers()

HTH,
Mike

Roel Schroeven wrote:

> Hi,
>
> I'm trying to make a small application using wxPython to provide a GUI 
> and PyOpenGL hardware acceleration. I know I have to create a 
> wxGLCanvas, which will be used by PyOpenGL functions. I wrote some GUI 
> code and adapted the code from the first example in the Red Book to 
> fit in, and it works. Sorta. I can set the background color, but 
> nothing else. No exceptions are thrown, the canvas just doesn't 
> display anything (besides the background color).
>
> In case it has anything to do with it, I'm using ActivePython on 
> Windows 2000 (though I'm planning to do most of the development on 
> Linux).
>
> Am I doing something wrong? Is there a problem with 
> ActivePyton/Windows/wxPython/PyOpenGL? Any toughts are more than welcome.
>
> The code I have so far:
>
>
> from wxPython.wx import *
> from wxPython.glcanvas import *
> from OpenGL.GL import *
>
> def DrawGL():
>     glClearColor(0.8, 0.1, 0.1, 0.0)
>     glClear(GL_COLOR_BUFFER_BIT)
>     # (so far it works)
>
>     glColor3f(1.0, 1.0, 1.0)
>
>     glMatrixMode(GL_PROJECTION)
>     glLoadIdentity()
>     glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0)
>
>     glBegin(GL_POLYGON)
>     glVertex2f(-0.5, -0.5)
>     glVertex2f(-0.5, 0.5)
>     glVertex2f(0.5, 0.5)
>     glVertex2f(0.5, -0.5)
>     glEnd()
>     # (but all this has no effect whatsoever)
>
>     glFlush()
>
>
> class MyGL(wxGLCanvas):
>     def __init__(self, parent):
>         wxGLCanvas.__init__(self, parent)
>         EVT_PAINT(self, self.OnPaint)
>
>     def OnPaint(self, event):
>         dc = wxPaintDC(self)
>         self.SetCurrent()
>         DrawGL()
>         self.SwapBuffers()
>
> class MyFrame(wxFrame):
>     def __init__(self, parent, ID, title):
>         wxFrame.__init__(self, parent, ID, title, wxDefaultPosition, 
> wxSize(700, 500))
>         self.GLCanvas = MyGL(self)
>
>         MainSizer = wxBoxSizer(wxVERTICAL)
>         MainSizer.Add(wxButton(self, -1, "top"), 0, wxEXPAND)
>
>         MiddleSizer = wxBoxSizer(wxHORIZONTAL)
>         MiddleSizer.Add(wxButton(self, -1, "left"), 1, wxEXPAND)
>         MiddleSizer.Add(self.GLCanvas, 2, wxEXPAND)
>         MiddleSizer.Add(wxButton(self, -1, "right"), 1, wxEXPAND)
>         MainSizer.Add(MiddleSizer, 1, wxEXPAND)
>
>         MainSizer.Add(wxButton(self, -1, "bottom"), 0, wxEXPAND)
>
>         self.SetSizer(MainSizer)
>         self.SetAutoLayout(True)
>         #MainSizer.Fit(self)
>
> class MyApp(wxApp):
>     def OnInit(self):
>         frame = MyFrame(NULL, -1, "Python/OpenGL")
>         frame.Show(True)
>         self.SetTopWindow(frame)
>         return True
>
> app = MyApp(0)
> app.MainLoop()
>
>
>

-- 
_______________________________________
  Mike C. Fletcher
  Designer, VR Plumber, Coder
  http://members.rogers.com/mcfletch/








More information about the Python-list mailing list