Created
December 3, 2012 17:42
-
-
Save Qolt/4196642 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
from OpenGL.GL import * | |
from PyQt4 import QtGui, QtCore | |
from PyQt4.QtOpenGL import * | |
obj = "points" | |
class WfWidget(QGLWidget): | |
def __init__(self, parent = None): | |
super(WfWidget, self).__init__(parent) | |
def drawPoints(self): | |
glPointSize(6) | |
glBegin(GL_POINTS) | |
glColor3d(10,0,0) | |
glVertex3d(-30,30,-30) | |
glColor3d(0,10,0) | |
glVertex3d(30,30,0) | |
glColor3d(0,0,10) | |
glVertex3d(0,-30,-30) | |
glEnd() | |
def drawLines(self): | |
glBegin(GL_LINES) | |
glColor3d(10,0,0) | |
glVertex3d(0,0,0) | |
glVertex3d(40,-40,40) | |
glColor3d(0,10,0) | |
glVertex3d(0,0,0) | |
glVertex3d(-40,-40,40) | |
glEnd() | |
def drawStripLines (self): | |
glBegin(GL_LINE_STRIP) | |
glColor3d(10,0,0) | |
glVertex3d(0,0,0) | |
glVertex3d(0,10,0) | |
glColor3d(0,10,0) | |
glVertex3d(0,20,0) | |
glVertex3d(0,30,0) | |
glColor3d(0,0,10) | |
glVertex3d(0,30,0) | |
glVertex3d(0,40,0) | |
glEnd() | |
def drawLoopLines(self): | |
glBegin(GL_LINE_STRIP) | |
glColor3d(10,0,0) | |
glVertex3d(0,0,0) | |
glVertex3d(20,20,0) | |
glColor3d(0,10,0) | |
glVertex3d(20,20,0) | |
glVertex3d(40,0,0) | |
glColor3d(0,0,10) | |
glVertex3d(40,0,0) | |
glVertex3d(0,0,0) | |
glEnd() | |
def drawTriangles(self): | |
glBegin(GL_TRIANGLES) | |
glColor3d(1,0,0); | |
glVertex3d(-10,30,0); | |
glVertex3d(10,30,0); | |
glVertex3d(0,10,0); | |
glEnd() | |
def paintGL(self): | |
global obj | |
if obj == "points": | |
self.drawPoints() | |
if obj == "lines": | |
self.drawLines() | |
if obj == "strip_lines": | |
self.drawStripLines() | |
if obj == "loop_lines": | |
self.drawLoopLines() | |
if obj == "triangles": | |
self.drawTriangles() | |
def resizeGL(self, w, h): | |
glMatrixMode(GL_PROJECTION) | |
glLoadIdentity() | |
glOrtho(-50, 50, -50, 50, -50.0, 50.0) | |
glViewport(0, 0, w, h) | |
def initializeGL(self): | |
glClearColor(0.0, 0.0, 0.0, 1.0) | |
glClear(GL_COLOR_BUFFER_BIT) | |
def ShowPoints(self): | |
self.hide() | |
global obj | |
obj = "points" | |
print obj | |
self.show() | |
def ShowLines(self): | |
self.hide() | |
global obj | |
obj = "lines" | |
print obj | |
self.show() | |
def ShowStripLines(self): | |
self.hide() | |
global obj | |
obj = "strip_lines" | |
print obj | |
self.show() | |
def ShowLoopLines(self): | |
self.hide() | |
global obj | |
obj = "loop_lines" | |
print obj | |
self.show() | |
def ShowTriangles(self): | |
self.hide() | |
global obj | |
obj = "triangles" | |
print obj | |
self.show() | |
class ControlWindow(QtGui.QWidget): | |
def __init__ (self, parent=None): | |
QtGui.QWidget.__init__(self, parent) | |
self.label = QtGui.QLabel("Lab 1") | |
self.btnPoints= QtGui.QPushButton("&Draw points") | |
self.btnLines= QtGui.QPushButton("&Draw lines") | |
self.btnStripLines= QtGui.QPushButton("&Draw strip lines") | |
self.btnLoopLines= QtGui.QPushButton("&Draw loop lines") | |
self.btnTriangles= QtGui.QPushButton("&Draw triangles") | |
vbox = QtGui.QVBoxLayout() | |
vbox.addWidget(self.label) | |
vbox.addWidget(self.btnPoints) | |
vbox.addWidget(self.btnLines) | |
vbox.addWidget(self.btnStripLines) | |
vbox.addWidget(self.btnLoopLines) | |
vbox.addWidget(self.btnTriangles) | |
self.setLayout(vbox) | |
if __name__ == '__main__': | |
app = QtGui.QApplication(sys.argv) | |
GLWidget = WfWidget() | |
controlWidget = ControlWindow() | |
controlWidget.resize(300, 70) | |
controlWidget.connect (controlWidget.btnPoints, QtCore.SIGNAL("clicked ()"), | |
GLWidget.ShowPoints) | |
controlWidget.connect (controlWidget.btnLines, QtCore.SIGNAL("clicked ()"), | |
GLWidget.ShowLines) | |
controlWidget.connect (controlWidget.btnStripLines, QtCore.SIGNAL("clicked ()"), | |
GLWidget.ShowStripLines) | |
controlWidget.connect (controlWidget.btnLoopLines, QtCore.SIGNAL("clicked ()"), | |
GLWidget.ShowLoopLines) | |
controlWidget.connect (controlWidget.btnTriangles, QtCore.SIGNAL("clicked ()"), | |
GLWidget.ShowTriangles) | |
controlWidget.show() | |
app.exec_() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment