def paintGL(self): glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glClearColor(1.0, 1.0, 1.0, 0.0) glLoadIdentity() glEnable(GL_CULL_FACE) glCullFace(GL_BACK) gluLookAt(2.0, 2.0, 4.0, 0.0, 0.0, 0.0, 0.0, 10.0, 0.0) glEnable(GL_LIGHTING) glTranslatef(0.0, 0.0, 0.0) glRotate(self.angle, self.axis[0], self.axis[1], self.axis[2]) light = ZOpenGLLight(GL_LIGHT0) lightPosition = [15.0, 25.0, -25.0, 1.0] light.positionv(lightPosition) white = [1.0, 1.0, 1.0, 1.0] blue = [0.0, 0.0, 1.0, 1.0] green = [0.0, 1.0, 0.0, 1.0] shininess = 100.0 material = ZOpenGLMaterial(GL_FRONT) material.diffusev(white) material.specularv(blue) material.shininess(shininess) if self.torus != None: self.torus.draw()
def paintGL(self): self.mutex.lock() if (self.angle < (self.CIRCLE_ANGLE - self.INCREMENT)): self.angle += self.INCREMENT else: self.angle = self.INCREMENT if (self.sphere != None): pos = self.circle.getOrbitPosition(self.angle) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glLoadIdentity() gluLookAt(-5.0, 10.0, 4.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0) glClearColor(0.0, 0.0, 0.0, 1.0) glEnable(GL_CULL_FACE) glEnable(GL_LIGHTING) glTranslate(0.0, 0.0, 0.0) glColor(1.0, 1.0, 1.0) #green self.circle.draw() glTranslate(pos[0], pos[1], pos[2]) light = ZOpenGLLight(GL_LIGHT0) lightPosition = [-2.0, 0.0, -1.0, 1.0] light.positionv(lightPosition) white = [1.0, 1.0, 1.0, 1.0] blue = [0.0, 0.0, 1.0, 1.0] green = [0.0, 1.0, 0.0, 1.0] shininess = 100.0 material = ZOpenGLMaterial(GL_FRONT) material.diffusev(green) material.specularv(white) material.shininess(shininess) self.sphere.draw() self.mutex.unlock()
class OpenGLView(ZOpenGLView): def __init__(self, parent=None): self.parent = parent super(ZOpenGLView, self).__init__(parent) self.angle = 120 def initializeGL(self): glEnable(GL_DEPTH_TEST) glEnable(GL_TEXTURE_2D) self.light = ZOpenGLLight(GL_LIGHT0) self.light.position(-10.0, -10.0, 20.0, 1.0) #self.light.position(10.0, 20.0, 0.0, 1.0) glFrontFace(GL_CCW) self.material = ZOpenGLMaterial(GL_BACK) white = [1.0, 1.0, 1.0, 1.0] blue = [0.0, 0.0, 1.0, 1.0] shininess = 100 self.material.diffusev(blue) self.material.specularv(white) self.material.shininess(shininess) self.sphere = None self.axis = [-10.0, -10.0, 80.0] filename = "../opengl/images/world.topo.bathy.200412.3x860x430.jpg" self.createTexture(filename) self.parent.set_filenamed_title(filename) def createTexture(self, filename): try: reader = ZOpenCVImageReader() image = reader.read(filename) alpha = 12.0 beta = 10.0 convertedImage = cv2.convertTo(image, -1, alpha, beta) cvImageInfo = ZOpenCVImageInfo() #Get ZOpenGLImageInfo from cv2.Mat convertedImage imageInfo = cvImageInfo.getImageInfo(convertedImage) self.sphere = ZOpenGLTexturedSphere(2.5, 40, 40) self.sphere.imageFromImageInfo(1, imageInfo) except: traceback.print_exc() def paintGL(self): glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glClearColor(0.0, 0.0, 0.0, 0.0) glLoadIdentity() glTranslatef(0.0, 0.0, -1.0) gluLookAt(0.0, -5.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0) glEnable(GL_CULL_FACE) glEnable(GL_LIGHTING) glTranslatef(0.0, 0.0, 0.0) glRotate(self.angle, self.axis[0], self.axis[1], self.axis[2]) if self.sphere != None: self.sphere.draw() glFlush() def resizeGL(self, width, height): if width == 0 or height == 0: return glViewport(0, 0, width, height) glMatrixMode(GL_PROJECTION) glLoadIdentity() gluPerspective(16.0, width / height, 0.5, 100) glMatrixMode(GL_MODELVIEW) def keyPressEvent(self, event): if event.key() == Qt.Key_Left: self.angle = self.angle - 2.0 if event.key() == Qt.Key_Right: self.angle = self.angle + 2.0 self.update() def createTexture(self, filename): self.sphere = ZOpenGLTexturedSphere(filename, None, 1.0, 40, 40)