Hey guys, I just saw this thread.
Last week I was able to get some basic integration between wxPython
and pyglet - some sample code is attached below. Although this
program runs just fine, my actual usage is more complex and I've
encountered some issues. Namely:
1. sometimes calling set_current() on both the pyglet Context and on
the wx.GLCanvas results in a GL "invalid operation" exception
(primarily on win32, not on OS X); however, I seem to need to call
both in order to get correct rendering. (For example, pyglet's text
rendering won't work until set_current has been called.)
2. sometimes the window is blank until I resize, regardless of how
many times I swap buffers (via pyglet or wx), or how many times I draw
into the window or interact with the GL area with my mouse.
If anyone has any suggestions or ideas on how best to fix/debug these
issues, I'd love to hear from them.
Thanks,
Peter
-----------------------------
from wx.glcanvas import GLCanvas
from wx import *
from OpenGL.GLUT import *
from OpenGL.GLU import *
from OpenGL.GL import *
from pyglet import window, gl
from pyglet.font import load, Text
class myGLCanvas(GLCanvas):
def __init__(self, parent):
GLCanvas.__init__(self, parent,-1)
EVT_PAINT(self, self.OnPaint)
self.init = 0
return
def OnPaint(self,event):
if not self.init:
self.InitGL()
self.init = 1
self.ctx.set_current()
self.SetCurrent()
self.OnDraw()
return
def InitGL(self):
self.init_pyglet()
size = self.GetSize()
glViewport(0, 0, size.width, size.height)
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
glOrtho(0, size.width, 0, size.height, 1, -1);
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
def OnDraw(self):
# Clear the background
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
size = self.GetSize()
glColor(0.827, 0.827, 0.827, 1.0)
glRectf(0, 0, size.width, size.height)
# draw a box
glColor(1, 0, 0, 1)
glLineWidth(2)
glBegin(GL_POLYGON)
glVertex2f(50, 50)
glVertex2f(50, 100)
glVertex2f(100, 100)
glVertex2f(100, 50)
glEnd()
# Draw the pyglet text
self.text.draw()
self.SwapBuffers()
def init_pyglet(self):
self.ctx = gl.Context()
self.ctx.set_current()
ft = load("Comic Sans MS", 24)
self.text = Text(ft, "Pyglet FTW!", x=150, y=50, color=(0,0,0,1))
def main():
app = wx.PySimpleApp()
frame = wx.Frame(None,-1,'wxPyglet',wx.DefaultPosition,wx.Size(400,400))
canvas = myGLCanvas(frame)
frame.Show()
app.MainLoop()
if __name__ == '__main__': main()
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"pyglet-users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/pyglet-users?hl=en
-~----------~----~----~----~------~----~------~--~---