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):
            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)
Example #4
0
    class OpenGLView(ZOpenGLView):

        ## Constructor
        def __init__(self, parent=None):
            self.parent = parent
            super(ZOpenGLView, self).__init__(parent)

        def initializeGL(self):

            glMatrixMode(GL_PROJECTION)
            glLoadIdentity()

            glEnable(GL_DEPTH_TEST)

            #  ColorNormalVertex<float,4,3,3>
            vertices = [
                [0.5, 0.0, 0.0, 0.5, -0.6, 0.6, 0.6, -0.5, 0.5, 0.5],
                [0.5, 0.0, 0.0, 0.5, -0.6, -0.6, 0.6, -0.5, -0.5, 0.5],
                [0.5, 0.0, 0.0, 0.5, 0.6, 0.6, 0.6, 0.5, 0.5, 0.5],
                [0.5, 0.0, 0.0, 0.5, 0.6, -0.6, 0.6, 0.5, -0.5, 0.5],
                [0.5, 0.0, 0.0, 0.5, 0.6, 0.6, -0.6, 0.5, 0.5, -0.5],
                [0.5, 0.0, 0.0, 0.5, 0.6, -0.6, -0.6, 0.5, -0.5, -0.5],
                [0.5, 0.0, 0.0, 0.5, -0.6, 0.6, -0.6, -0.5, 0.5, -0.5],
                [0.5, 0.0, 0.0, 0.5, -0.6, -0.6, -0.6, -0.5, -0.5, -0.5],
            ]

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

            self.n_vertices = len(vertices)

            self.vertexBuffer = ZOpenGLVertexBufferARB()

            self.vertexBuffer.bind()
            float32_bsize = 4
            data_size = self.n_vertices * (4 + 3 + 3) * float32_bsize
            varray = np.array(vertices, dtype="float32")
            self.vertexBuffer.data(data_size, varray, GL_STATIC_DRAW_ARB)
            self.vertexBuffer.unbind()

            self.n_indices = len(indices)

            self.indexBuffer = ZOpenGLIndexBufferARB()
            self.indexBuffer.bind()
            iarray = np.array(indices, dtype="int32")
            self.indexBuffer.data(self.n_indices * 4, iarray,
                                  GL_STATIC_DRAW_ARB)

            self.indexBuffer.unbind()
            self.light = ZOpenGLLight(GL_LIGHT0)
            self.material = ZOpenGLMaterial(GL_FRONT_AND_BACK)

        def paintGL(self):
            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
            glLoadIdentity()

            glTranslate(0.0, 0.0, -1.0)
            gluLookAt(2.0, 4.0, 6.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0)
            glClearColor(1.0, 0.8, 0.8, 1.0)

            state1 = ZOpenGLClientState(GL_VERTEX_ARRAY)
            state2 = ZOpenGLClientState(GL_COLOR_ARRAY)
            state3 = ZOpenGLClientState(GL_NORMAL_ARRAY)
            state1.enable()
            state2.enable()
            state3.enable()

            lightPosition = [5.0, 5.0, -8.0, 1.0]
            lightColor = [1.0, 0.0, 0.0, 1.0]
            materialColor = [0.8, 0.8, 0.4, 1.0]

            glEnable(GL_LIGHTING)
            self.light.positionv(lightPosition)
            self.light.diffusev(lightColor)
            self.light.enable()

            self.material.diffusev(materialColor)

            self.vertexBuffer.bind()
            self.indexBuffer.bind()

            glInterleavedArrays(GL_C4F_N3F_V3F, 0, None)
            glDrawElements(GL_QUADS, self.n_indices, GL_UNSIGNED_INT, None)

            state1.disable()
            state2.disable()
            state3.disable()

            self.vertexBuffer.unbind()
            self.indexBuffer.unbind()

        def resizeGL(self, w, h):
            if w == 0 or h == 0:
                return

            glMatrixMode(GL_PROJECTION)
            glLoadIdentity()
            gluPerspective(16.0, w / h, 0.5, 40.0)
            glMatrixMode(GL_MODELVIEW)