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()
Example #2
0
        def paintGL(self):
            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
            glLoadIdentity()
            gluLookAt(2.0, 4.0, 8.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)

            glEnable(GL_DEPTH_TEST)
            light = ZOpenGLLight(GL_LIGHT0)
            light.position(10.0, 10.0, 10.0, 1.0)

            material = ZOpenGLMaterial(GL_FRONT)
            material.specular(1.0, 1.0, 1.0, 1.0)
            material.shininess(100.0)

            geometry = ZOpenGLGeometry(None)
            glPushMatrix()
            material.diffuse(0.0, 0.0, 1.0, 1.0)
            glTranslate(-2.0, 1.0, -6.0)
            glRotate(-40.0, 1.0, 0.0, 0.0)
            geometry.solidTorus(1.0, 1.8, 10, 50)
            glPopMatrix()

            glPushMatrix()
            material.diffuse(1.0, 0.0, 0.0, 1.0)
            glTranslate(-2.2, -6.0, -6.0)
            glRotate(10.0, 1.0, 0.0, 0.0)
            geometry.wireTorus(1.0, 1.8, 10, 40)
            glPopMatrix()
Example #3
0
    class OpenGLView(ZOpenGLView):
        def __init__(self, parent=None):
            self.parent = parent
            super(ZOpenGLView, self).__init__(parent)

        def initializeGL(self):
            glEnable(GL_DEPTH_TEST)
            glMatrixMode(GL_PROJECTION)
            glLoadIdentity()
            glMatrixMode(GL_MODELVIEW)
            self.CUBES = 4
            self.cubes = []
            for i in range(self.CUBES):
                self.cubes.append(
                    ZOpenGLIndexedCube(1.0, -2.0 + 1.2 * i, -2.0 + 1.2 * i,
                                       1.0 - 0.5 * i))

            self.light = ZOpenGLLight(GL_LIGHT0)
            self.material = ZOpenGLMaterial(GL_FRONT)

        def paintGL(self):
            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
            glClearColor(0.2, 0.0, 0.2, 1.0)
            glLoadIdentity()
            glTranslatef(-0.5, -0.5, 0.0)

            gluLookAt(3.0, 6.0, 14.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0)

            glEnable(GL_LIGHTING)

            self.light.position(0.0, 6.0, 2.0, 0.0)

            self.material.diffuse(0.2, 1.0, 0.2, 0.0)
            self.material.specular(1.0, 1.0, 1.0, 0.0)
            self.material.shininess(100.0)

            for i in range(self.CUBES):
                self.cubes[i].draw()

            glFlush()

        def resizeGL(self, width, height):
            side = min(width, height)
            if side < 0: return
            glViewport(0, 0, width, height)
            glMatrixMode(GL_PROJECTION)
            glLoadIdentity()
            gluPerspective(16.0, width / height, 0.5, 40.0)

            glMatrixMode(GL_MODELVIEW)
Example #4
0
    class OpenGLView(ZOpenGLView):
        def __init__(self, parent=None):
            self.parent = parent
            super(ZOpenGLView, self).__init__(parent)

        def initializeGL(self):
            glEnable(GL_DEPTH_TEST)
            glMatrixMode(GL_PROJECTION)
            glLoadIdentity()
            glMatrixMode(GL_MODELVIEW)
            self.quadric = ZOpenGLQuadric()
            self.materia = ZOpenGLMateria()

            self.cylinder = ZOpenGLCylinder(self.quadric, self.materia)

            self.light = ZOpenGLLight(GL_LIGHT0)
            self.material = ZOpenGLMaterial(GL_FRONT)

        def paintGL(self):
            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
            glClearColor(0.2, 0.0, 0.2, 1.0)
            glLoadIdentity()
            glTranslatef(-0.5, 0.5, 0.0)

            gluLookAt(2.0, 4.0, 6.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.5)

            glEnable(GL_LIGHTING)

            self.light.position(10, 10, 10, 1.0)

            self.material.diffuse(1.0, 0.0, 0.0, 1.0)
            self.material.specular(1.0, 1.0, 1.0, 1.0)
            self.material.shininess(100.0)
            glRotate(60.0, 0.0, 1.0, 0.0)
            self.cylinder.reshape(0.4, 0.8, 3.0, 32, 32)
            self.cylinder.draw()

            glFlush()

        def resizeGL(self, width, height):
            side = min(width, height)
            if side < 0: return
            glViewport(0, 0, width, height)
            glMatrixMode(GL_PROJECTION)
            glLoadIdentity()
            gluPerspective(16.0, width / height, 0.5, 40.0)

            glMatrixMode(GL_MODELVIEW)
Example #5
0
        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, color, eye, light):
            #self.parent = parent
            super(ZOpenGLView, self).__init__(parent)
            self.angle = 0
            self.vcolor = color
            self.veye = eye
            self.vlight = light

        def initializeGL(self):
            glEnable(GL_DEPTH_TEST)
            glMatrixMode(GL_PROJECTION)
            glLoadIdentity()
            glMatrixMode(GL_MODELVIEW)

            self.light = ZOpenGLLight()
            self.material = ZOpenGLMaterial(GL_FRONT)
            self.geometry = ZOpenGLGeometry(None)

        def paintGL(self):
            glFrustum(1, -1, -1, 1, 1, 10)

            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
            glLoadIdentity()
            glMatrixMode(GL_MODELVIEW)
            glClearColor(1.0, 1.0, 1.0, 1.0)
            glTranslate(-0.5, -0.5, 0.0)

            gluLookAt(self.veye[0], self.veye[1], self.veye[2], 0.0, 0.0, 0.0,
                      0.0, 1.0, 0.0)

            glRotate(0.0, 0.0, 1.0, 0.0)

            glEnable(GL_LIGHTING)
            self.light.position(self.vlight[0], self.vlight[1], self.vlight[2],
                                0.0)

            self.material.diffuse(self.vcolor[0] / 255.0,
                                  self.vcolor[1] / 255.0,
                                  self.vcolor[2] / 255.0, 0.0)

            self.material.specular(1.0, 1.0, 1.0, 0.0)
            self.material.shininess(100.0)

            glFrontFace(GL_CCW)

            glEnable(GL_CULL_FACE)
            glCullFace(GL_BACK)
            glEnable(GL_NORMALIZE)

            glPushMatrix()
            self.geometry.solidTeapot(2.0)
            glPopMatrix()

            glFlush()

        def resizeGL(self, width, height):
            side = min(width, height)
            if side < 0: return
            glViewport(0, 0, width, height)
            glMatrixMode(GL_PROJECTION)
            glLoadIdentity()
            gluPerspective(16.0, width / height, 0.5, 40.0)

            glMatrixMode(GL_MODELVIEW)

        def setColorPosition(self, color):
            self.vcolor = color
            self.update()

        def setEyePosition(self, eye):
            self.veye = eye
            self.update()

        def setLigtPosition(self, light):
            self.vlight = light
            self.update()
Example #7
0
    class OpenGLView(ZOpenGLView):
        def __init__(self, parent, color, eye, light):
            #self.parent = parent
            super(ZOpenGLView, self).__init__(parent)
            self.angle = 0
            self.vcolor = color
            self.veye = eye
            self.vlight = light

        def initializeGL(self):
            glEnable(GL_DEPTH_TEST)
            glMatrixMode(GL_PROJECTION)
            glLoadIdentity()
            glMatrixMode(GL_MODELVIEW)

            self.light = ZOpenGLLight()
            self.material = ZOpenGLMaterial(GL_FRONT)

            self.vertices = [
                [-1.0, -1.0, 1.0],
                [1.0, -1.0, 1.0],
                [1.0, -1.0, -1.0],
                [-1.0, -1.0, -1.0],
                [0.0, 1.0, 0.0],
            ]

            self.indices = [
                [0, 1, 4],  #Triangle: face1
                [1, 2, 4],  #Triangle: face2
                [2, 3, 4],  #Triangle: face3
                [3, 0, 4],  #Triangle] face4
            ]

            self.surfaces = ZOpenGLTriangleSurfaces(self.vertices,
                                                    self.indices)
            self.normals = self.surfaces.calculateSurfaceNormals()

        def paintGL(self):
            glFrustum(1, -1, -1, 1, 1, 10)

            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
            glLoadIdentity()
            glMatrixMode(GL_MODELVIEW)
            glClearColor(1.0, 1.0, 1.0, 1.0)
            glTranslate(-0.5, -0.5, 0.0)

            gluLookAt(self.veye[0], self.veye[1], self.veye[2], 0.0, 0.0, 0.0,
                      0.0, 1.0, 0.0)

            glRotate(0.0, 0.0, 1.0, 0.0)

            #glTranslate(0.0, 0.0, -1.0)

            #glEnableClientState(GL_VERTEX_ARRAY)
            #glEnableClientState(GL_COLOR_ARRAY)

            #avertices =  np.array(self.vertices, dtype="float32")

            #glVertexPointer(3, GL_FLOAT, 0, self.avertices)
            #nindices     =  np.array(self.indices, dtype="uint32")

            glEnable(GL_LIGHTING)
            self.light.position(self.vlight[0], self.vlight[1], self.vlight[2],
                                0.0)
            self.material.diffuse(self.vcolor[0] / 255.0,
                                  self.vcolor[1] / 255.0,
                                  self.vcolor[2] / 255.0, 0.0)

            self.material.specular(1.0, 1.0, 1.0, 0.0)
            self.material.shininess(100.0)

            glFrontFace(GL_CCW)

            glEnable(GL_CULL_FACE)
            glCullFace(GL_BACK)
            glEnable(GL_NORMALIZE)
            for i in range(len(self.indices)):
                glBegin(GL_TRIANGLES)
                tri = self.indices[i]
                self.draw(self.normals[i], self.vertices[tri[0]],
                          self.vertices[tri[1]], self.vertices[tri[2]])
                glEnd()
                glFlush()

            #glDisableClientState(GL_VERTEX_ARRAY)
            #glDisableClientState(GL_COLOR_ARRAY)

            glFlush()

        def resizeGL(self, width, height):
            side = min(width, height)
            if side < 0: return
            glViewport(0, 0, width, height)
            glMatrixMode(GL_PROJECTION)
            glLoadIdentity()
            gluPerspective(16.0, width / height, 0.5, 40.0)

            glMatrixMode(GL_MODELVIEW)

        def draw(self, n, v1, v2, v3):
            glNormal3fv(n)
            glVertex3fv(v1)
            glVertex3fv(v2)
            glVertex3fv(v3)

        def setColorPosition(self, color):
            self.vcolor = color
            self.update()

        def setEyePosition(self, eye):
            self.veye = eye
            self.update()

        def setLigtPosition(self, light):
            self.vlight = light
            self.update()
    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)
Example #9
0
    class OpenGLView(ZOpenGLView):
        def __init__(self, parent, color, eye, light):
            #self.parent = parent
            super(ZOpenGLView, self).__init__(parent)
            self.angle = 0
            self.vcolor = color
            self.veye = eye
            self.vlight = light
            print(self.vcolor)
            print(self.veye)
            print(self.vlight)

        def initializeGL(self):
            glEnable(GL_DEPTH_TEST)
            glMatrixMode(GL_PROJECTION)
            glLoadIdentity()
            glMatrixMode(GL_MODELVIEW)

            self.vertices = [
                [0.0, 0.0, 0.0],
                [1.0, 0.0, 0.0],
                [1.0, 1.0, 0.0],
                [0.0, 1.0, 0.0],
                [0.0, 0.0, -1.0],
                [1.0, 0.0, -1.0],
                [1.0, 1.0, -1.0],
                [0.0, 1.0, -1.0],
            ]

            self.indices = [[0, 1, 2, 3], [1, 5, 6, 2], [5, 4, 7, 6],
                            [4, 0, 3, 7], [4, 5, 1, 0], [3, 2, 6, 7]]

            self.surfaces = ZOpenGLQuadSurfaces(self.vertices, self.indices)
            #Printf("calculateSurfaceNormals");
            self.normals = self.surfaces.calculateSurfaceNormals()
            #surfaces->displayNormals();

            self.light = ZOpenGLLight()
            self.material = ZOpenGLMaterial(GL_FRONT)

        def paintGL(self):
            glFrustum(1, -1, -1, 1, 1, 10)

            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
            glLoadIdentity()
            glMatrixMode(GL_MODELVIEW)
            glClearColor(1.0, 1.0, 1.0, 1.0)
            glTranslate(-0.5, -0.5, 0.0)

            gluLookAt(self.veye[0], self.veye[1], self.veye[2], 0.0, 0.0, 0.0,
                      0.0, 1.0, 0.0)

            glRotate(0.0, 0.0, 1.0, 0.0)

            glEnable(GL_LIGHTING)
            self.light.position(self.vlight[0], self.vlight[1], self.vlight[2],
                                0.0)

            self.material.diffuse(self.vcolor[0] / 255.0,
                                  self.vcolor[1] / 255.0,
                                  self.vcolor[2] / 255.0, 0.0)

            self.material.specular(1.0, 1.0, 1.0, 0.0)
            self.material.shininess(100.0)

            glFrontFace(GL_CCW)

            glEnable(GL_CULL_FACE)
            glCullFace(GL_BACK)
            glEnable(GL_NORMALIZE)

            for i in range(len(self.indices)):
                glBegin(GL_QUADS)
                quad = self.indices[i]
                self.draw(self.normals[i], self.vertices[quad[0]],
                          self.vertices[quad[1]], self.vertices[quad[2]],
                          self.vertices[quad[3]])
                glEnd()

            glFlush()

        def resizeGL(self, width, height):
            side = min(width, height)
            if side < 0: return
            glViewport(0, 0, width, height)
            glMatrixMode(GL_PROJECTION)
            glLoadIdentity()
            gluPerspective(16.0, width / height, 0.5, 40.0)

            glMatrixMode(GL_MODELVIEW)

        def draw(self, n, v1, v2, v3, v4):
            glNormal3fv(n)
            glVertex3fv(v1)
            glVertex3fv(v2)
            glVertex3fv(v3)
            glVertex3fv(v4)

        def setColorPosition(self, color):
            self.vcolor = color
            self.update()

        def setEyePosition(self, eye):
            self.veye = eye
            self.update()

        def setLigtPosition(self, light):
            self.vlight = light
            self.update()
  class OpenGLView(ZOpenGLView):

    def __init__(self, parent,  color, eye, light):
      #self.parent = parent
      super(ZOpenGLView, self).__init__(parent)
      self.angle = 0
      self.vcolor = color
      self.veye   = eye
      self.vlight = light


    def initializeGL(self):
      glEnable(GL_DEPTH_TEST)      
      glMatrixMode(GL_PROJECTION)
      glLoadIdentity()                    
      glMatrixMode(GL_MODELVIEW)

      self.quadric = ZOpenGLQuadric();
      self.quadric.drawStyle(GLU_FILL);
      self.quadric.normals(GLU_SMOOTH);
      self.materia  = ZOpenGLMateria()
      
      self.sphere = ZOpenGLSphere(self.quadric, self.materia)
      self.sphere.reshape(1.0, 40, 40)    
    
      self.light    = ZOpenGLLight()
      self.material = ZOpenGLMaterial(GL_FRONT);


    def paintGL(self):
      glFrustum(1 , -1 , -1 , 1 , 1 , 10);

      glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
      glLoadIdentity();
      glMatrixMode(GL_MODELVIEW);
      glClearColor(1.0, 1.0, 1.0, 1.0);
      glTranslate(0.0, 0.0, 0.0); 

      gluLookAt(self.veye[0], self.veye[1], self.veye[2], 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); 

      glRotate(0.0, 0.0, 1.0, 0.0);
      
      glEnable(GL_LIGHTING);
      self.light.position(self.vlight[0], self.vlight[1], self.vlight[2], 0.0);  

      self.material.diffuse(self.vcolor[0]/255.0, self.vcolor[1]/255.0, self.vcolor[2]/255.0, 0.0);
   
      self.material.specular(1.0, 1.0, 1.0, 0.0);
      self.material.shininess(100.0);
  
      glFrontFace(GL_CCW);

      glEnable(GL_CULL_FACE);
      glCullFace(GL_BACK);
      glEnable(GL_NORMALIZE);

      self.sphere.draw()

      glFlush();


    def resizeGL(self, width, height):
      side = min(width, height)
      if side < 0: return
      glViewport(0, 0, width, height)
      glMatrixMode(GL_PROJECTION)
      glLoadIdentity()
      gluPerspective(16.0, width / height, 0.5, 40.0)

      glMatrixMode(GL_MODELVIEW);



    def setColorPosition(self, color):
      self.vcolor = color
      self.update()


    def setEyePosition(self, eye):
      self.veye = eye
      self.update()


    def setLigtPosition(self, light):
      self.vlight = light
      self.update()