Example #1
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 #2
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 #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.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)
    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 #5
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()
Example #6
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()