import sys
from OpenGL.GL import *
from OpenGL.GLU import *
from OpenGL.GLUT import *
from PyQt4.QtGui import *
from PyQt4.QtCore import *
from PyQt4.QtOpenGL import *
from PyQt4 import uic
class MyOGLWidget(QGLWidget):
def __init__(self, parent=None):
QGLWidget.__init__(self, parent)
self.spin = 0
def initializeGL(self):
print "init GL"
glClearColor(0.0, 0.0, 0.0, 0.0);
glShadeModel (GL_FLAT)
self.timer = QTimer(self)
self.timer.timeout.connect(self.spinDisplay)
self.timer.start(40)
print self.timer
def resizeGL(self, w, h):
print "resize: " + str(w ) + " x " +str(h)
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-50.0, 50.0, -50.0, 50.0, -1.0, 1.0);
def paintGL(self):
print "paint GL"
glClear (GL_COLOR_BUFFER_BIT );
glPushMatrix()
glRotatef(self.spin, 0, 0, 1)
glColor3f (1.0, 1.0, 1.0);
glRectf(-25.0, -25.0, 25.0, 25.0);
glPopMatrix()
glFlush();
def spinDisplay(self):
# print "spin display"
self.spin = self.spin + 2
self.spin = self.spin % 360
# print self.spin
#glutSwapBuffers()
self.updateGL()
app = QApplication(sys.argv)
window = MyOGLWidget()
window.resize(300, 300)
window.setWindowTitle("Testing OpenGL in PyQT")
window.show()
sys.exit(app.exec_())
Saturday, December 01, 2012
PyQT - OpenGL - Timer
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment