install PyOpenGL - http://pyopengl.sourceforge.net/
install QT - http://qt-project.org/downloads
install PyQT- http://www.riverbankcomputing.com/software/pyqt/download
for Mac OS X, install PyQTX - http://sourceforge.net/projects/pyqtx/files/
install QT - http://qt-project.org/downloads
install PyQT- http://www.riverbankcomputing.com/software/pyqt/download
for Mac OS X, install PyQTX - http://sourceforge.net/projects/pyqtx/files/
import sys
from OpenGL.GL import *
from OpenGL.GLU import *
from PyQt4.QtGui import *
from PyQt4.QtOpenGL import *
from PyQt4 import uic
class MyOGLWidget(QGLWidget):
def __init__(self, parent=None):
QGLWidget.__init__(self, parent)
def initializeGL(self):
print "init GL"
glClearColor(0.0, 0.0, 0.0, 0.0);
glShadeModel (GL_FLAT)
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 );
glColor3f (1.0, 1.0, 1.0);
glRectf(-25.0, -25.0, 25.0, 25.0);
glFlush();
app = QApplication(sys.argv)
window = MyOGLWidget()
window.resize(300, 300)
window.setWindowTitle("Testing OpenGL in PyQT")
window.show()
sys.exit(app.exec_())
No comments:
Post a Comment