Hi there people,

So I started down the road to building a QT4.5 compatible pyglet
widget. I thought the first step would be to just get pyglet.gl OpenGL
calls working on a Qt OpenGL context.

What I found, at least under Mac OSX leopard, is that the calls
"work", but somehow, for some reason, importing pyglet.gl freezes the
QT app window. The app still works, and the buttons and QT events
inside the window still work, but you cannot drag the window, maximize
it, close it, or resize it. There is something strange happening the
minute the pyglet.gl namespace gets imported. In fact, if you import
pyglet.gl and then import OpenGL, to overwrite the pyglet GL call
namespace with the PyOpenGL namespace, the freeze still happens.

OK. heres some test code so you can see for yourself. To run using the
PyOpenGL API go "python test.py", and to run using the pyglet.gl api,
go "PYGLET=1 python test.py"

So now testing under OSX, the display DOES render, I get no error, and
the window is locked.
Testing under linux, the pyglet.gl does NOT render, but the window IS
draggable. It does spit out an error on linux that it doesn't on OSX.
The traceback on linux is

Traceback (most recent call last):
  File "test.py", line 45, in paintGL
    glClear(GL_COLOR_BUFFER_BIT)
  File "/var/lib/python-support/python2.5/pyglet/gl/lib.py", line 83,
in errcheck
    raise GLException('No GL context; create a Window first')
pyglet.gl.lib.GLException: No GL context; create a Window first

Anyone have any ideas how to "unlock" the window on OSX and use the
pyglet.gl calls? Or how to get the GL drawing on linux?

---------------------------------------------------
#!/usr/bin/env python

import sys, math, os
from PyQt4 import QtGui, QtCore, QtOpenGL

if 'PYGLET' in os.environ:
        from pyglet.gl import *

        def glmult(l):
                return glMultMatrixf( (GLfloat * len(l))(*l) )

else:
        from OpenGL.GL import *
        
        def glmult(l):
                return glMultMatrixf( l )

class GLWidget(QtOpenGL.QGLWidget):
        def __init__(self, parent=None):
                QtOpenGL.QGLWidget.__init__(self, parent)

        def initializeGL(self):
                glClearColor(0.0, 0.0, 0.0, 0.0)
                glShadeModel(GL_FLAT)
                
        def lookAt(self,ex,ey,ez,cx,cy,cz,ux,uy,uz):
                F = [cx-ex, cy-ey, cz-ez]
                Fmag = math.sqrt(sum([a*a for a in F]))
                fnorm = [a/Fmag for a in F]
                
                Up = [ux,uy,uz]
                Upmag = math.sqrt(sum([a*a for a in Up]))
                upnorm = [a/Upmag for a in Up]

                def cross(v1,v2):
                        return [v1[1]*v2[2] - v1[2]*v2[1], v1[2]*v2[0] - 
v1[0]*v2[2],
v1[0]*v2[1] - v1[1]*v2[0]]

                s = cross( fnorm, upnorm )
                u = cross( s, fnorm )
                
                glmult([ s[0], s[1], s[2], 0, u[0], u[1], u[2], 0, -fnorm[0],
-fnorm[1], -fnorm[2], 0, 0, 0, 0, 1 ])
                glTranslated(-ex, -ey, -ez)
                
        def paintGL(self):
                glClear(GL_COLOR_BUFFER_BIT)

                glColor3f(1.0,1.0,1.0)
                glLoadIdentity()
                self.lookAt(0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0)
                glScalef(1.0, 2.0, 1.0)
                glBegin(GL_TRIANGLES)
                glNormal3f(1,0,0)
                glVertex3f(1,0,0)
                glVertex3f(0,1,0)
                glVertex3f(1,1,0)
                glEnd()
                glFlush()

        def resizeGL(self, height, width):
           glViewport(0, 0, width, height)
           glMatrixMode(GL_PROJECTION)
           glLoadIdentity()
           glFrustum(-1.0, 1.0, -1.0, 1.0, 1.5, 20.0)
           glMatrixMode(GL_MODELVIEW)

        def mousePressEvent(self, event):
                print "mousePressEvent:",event.pos()

        def mouseMoveEvent(self, event):
                print "mouseMoveEvent:",event.pos()

class MainWindow(QtGui.QMainWindow):
        def __init__(self):
                QtGui.QMainWindow.__init__(self)

                self.resize(350, 400)
                self.setWindowTitle('Main Window')

                self.gl = glwidget = GLWidget()
                self.setCentralWidget(glwidget)

                exit = QtGui.QAction(QtGui.QIcon(), 'Exit', self)
                exit.setShortcut('Ctrl+Q')
                exit.setStatusTip('Exit application')
                self.connect(exit, QtCore.SIGNAL('triggered()'), 
QtCore.SLOT('close()'))

                self.statusBar()

                toolbar = self.addToolBar('Exit')
                toolbar.addAction(exit)
                
        def idle(self):
                pass

# QT app
app = QtGui.QApplication(sys.argv)
main = MainWindow()
main.show()

sys.exit(app.exec_())

---------------------------------------------------


Kind Regards

Crispin

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to