It seems to work for me, at least with a trivial glut test:
from OpenGL.GL import *
import pyglet
pyglet.options['shadow_window'] = False
from pyglet import gl
class PygletContext(gl.Context):
class Controller(object):
def __init__(self):
self.test = False
def onResize(self, w, h):
glViewport(0, 0, w, h)
[…]
def onUpdate(self, d):
print 'onUpdate', d
def draw(self):
if self.test == False:
self.ctx = PygletContext()
self.ctx.set_current()
self.label = pyglet.text.Label('Hello, world',
font_name='Times New Roman',
font_size=36,
x=500, y=500,
anchor_x='center', anchor_y='center')
self.test = True
#glglue sample (PyOpenGL + glut)
glClearColor(0.9, 0.5, 0.0, 0.0)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
glBegin(GL_TRIANGLES)
glVertex(-1.0,-1.0)
glVertex( 1.0,-1.0)
glVertex( 0.0, 1.0)
glEnd()
# pyglet test here
gl.glMatrixMode( gl.GL_PROJECTION )
gl.glLoadIdentity()
gl.glMatrixMode( gl.GL_MODELVIEW )
gl.glLoadIdentity()
gl.glEnable(gl.GL_BLEND)
gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
gl.glClear( gl.GL_COLOR_BUFFER_BIT )
gl.glClearColor(0/255, 0/255, 0/255, 0)
gl.glOrtho(0, 1000, 0, 1000, 1, -1 )
gl.glBegin(gl.GL_TRIANGLES)
gl.glColor4f(1.,0.,1.,0.3)
gl.glVertex2f(0.0,0.0)
gl.glVertex2f(500.,500.)
gl.glVertex2f(1000., 0.)
gl.glEnd()
self.label.draw()
glFlush()
if __name__=="__main__":
controller=Controller()
import glglue.glut
glglue.glut.mainloop(controller, width=640, height=480, title="sample")
It also solved an issue with pyglet windowing on windows 7 (did not try other Windows versions…) with Intel chipset graphics, I was unable to open a simple window with pyglet on every PC without a "real" graphic card… After some debugging I guess it was a win32 issue, but only with some workstations having an Intel chipset (several versions), while the OpenGL stuffs seemed to run…
Thank you very much for your help.
I think there should be a section in pyglet documentation about how to use a custom OpenGL context, even if pyglet is intended to be library free this is very useful in some cases. I could not fix it without your hacking sample…
When you want to make an OpenGL application in Python without dealing with tricky stuffs like OpenGL "batch" programming, then pyglet contains just what you need.