wxPython & PyOpenGL
Roel Schroeven
j4nff5m02 at sneakemail.com
Wed Apr 16 09:10:45 EDT 2003
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()
--
"Codito ergo sum"
Roel Schroeven
More information about the Python-list
mailing list