示例#1
0
    def RedoDisplayList(self):
        #print "Common2d3dObject.RedoDisplayList", self

        if hasattr(self, 'dpyList') and self.dpyList is not None:
            lNewList = self.dpyList[0]
        else:
            lNewList = GL.glGenLists(1)
            self.viewer.deleteOpenglList()

        #lNewList = self.newList
        lContext = self.viewer.currentCamera.tk.call(
            self.viewer.currentCamera._w, 'contexttag')
        #print "lNewList Common2d3dObject.RedoDisplayList", lNewList, lContext, self.name
        self.dpyList = (lNewList,
                        self.viewer.currentCamera.tk.call(
                            self.viewer.currentCamera._w, 'contexttag'))
        GL.glNewList(self.dpyList[0], GL.GL_COMPILE)
        #print '+%d'%self.dpyList[0], lContext, "glNewList Common2d3dObject"
        if hasattr(self, 'Draw'):
            status = self.Draw()
        else:
            status = 0
        #print '*%d'%GL.glGetIntegerv(GL.GL_LIST_INDEX), "glEndList Common2d3dObject"
        GL.glEndList()
        if status == 0:
            self.deleteOpenglList()
    def RedoDisplayList(self):
        #print "Common2d3dObject.RedoDisplayList", self

        if hasattr(self, 'dpyList') and self.dpyList is not None:
            lNewList = self.dpyList[0]
        else:
            lNewList = GL.glGenLists(1)
            self.viewer.deleteOpenglList()

        #lNewList = self.newList
        lContext = self.viewer.currentCamera.tk.call(self.viewer.currentCamera._w, 'contexttag')
        #print "lNewList Common2d3dObject.RedoDisplayList", lNewList, lContext, self.name
        self.dpyList = ( lNewList,
                         self.viewer.currentCamera.tk.call(self.viewer.currentCamera._w, 'contexttag')
                       )
        GL.glNewList(self.dpyList[0], GL.GL_COMPILE)
        #print '+%d'%self.dpyList[0], lContext, "glNewList Common2d3dObject"
        if hasattr(self, 'Draw'):
            status = self.Draw()
        else:
            status = 0
        #print '*%d'%GL.glGetIntegerv(GL.GL_LIST_INDEX), "glEndList Common2d3dObject"
        GL.glEndList()
        if status == 0:
            self.deleteOpenglList()
示例#3
0
    def redoDisplayListCSG(self):
        if self.dpyListCSG is not None:
            GL.glDeleteLists(1, self.dpyListCSG)

        g = self.geom
        self.dpyListCSG = GL.glGenLists(1)
        GL.glNewList(self.dpyListCSG, GL.GL_COMPILE)
        ##         if isinstance(g, Spheres):
        ##             g.DisplayFunction()
        ##         else:
        self.drawpolygons()
        GL.glEndList()
示例#4
0
    def redoDisplayListCSG(self):
        if self.dpyListCSG is not None:
            GL.glDeleteLists(1, self.dpyListCSG)
        
        g = self.geom
        self.dpyListCSG = GL.glGenLists(1)
        GL.glNewList(self.dpyListCSG, GL.GL_COMPILE)
##         if isinstance(g, Spheres):
##             g.DisplayFunction()
##         else:
        self.drawpolygons()
        GL.glEndList()
示例#5
0
 def chooseTemplate(self):
     GL.glNewList(self.templateDSPL[0], GL.GL_COMPILE)
     #print '+%d'%self.templateDSPL[0], "glNewList Ellipsoids0"
     if self.invertNormals:
         #print "GLU_INSIDE reversed normals"
         #print '#%d'%(self.templateDSPL[0]+2), "glCallList Ellipsoids2"
         GL.glCallList(self.templateDSPL[0]+2)
     else:
         #print "GLU_OUTSIDE regular normals"
         #print '#%d'%(self.templateDSPL[0]+1), "glCallList Ellipsoids1"
         GL.glCallList(self.templateDSPL[0]+1)
     #print '*%d'%GL.glGetIntegerv(GL.GL_LIST_INDEX), "glEndList Ellipsoids0"
     GL.glEndList()
示例#6
0
 def chooseTemplate(self):
     if __debug__:
         if hasattr(DejaVu, 'functionName'): DejaVu.functionName()
     # make sure we are not already in a newlist
     if GL.glGetIntegerv(GL.GL_LIST_INDEX) == [0]:
         GL.glNewList(self.templateDSPL[0], GL.GL_COMPILE)
         #print '+%d'%self.templateDSPL[0], "glNewList Spheres0"
         if self.invertNormals:
             #print "GLU_INSIDE reversed normals"
             #print '#%d'%(self.templateDSPL[0]+2), "glCallList Spheres2"
             GL.glCallList(self.templateDSPL[0] + 2)
         else:
             #print "GLU_OUTSIDE regular normals"
             #print '#%d'%(self.templateDSPL[0]+1), "glCallList Spheres1"
             GL.glCallList(self.templateDSPL[0] + 1)
         #print '*%d'%GL.glGetIntegerv(GL.GL_LIST_INDEX), "glEndList Spheres0"
         GL.glEndList()
示例#7
0
 def chooseTemplate(self):
     if __debug__:
      if hasattr(DejaVu, 'functionName'): DejaVu.functionName()
     # make sure we are not already in a newlist
     if GL.glGetIntegerv(GL.GL_LIST_INDEX) == [0]:
         GL.glNewList(self.templateDSPL[0], GL.GL_COMPILE)
         #print '+%d'%self.templateDSPL[0], "glNewList Spheres0"
         if self.invertNormals:
             #print "GLU_INSIDE reversed normals"
             #print '#%d'%(self.templateDSPL[0]+2), "glCallList Spheres2"
             GL.glCallList(self.templateDSPL[0]+2)
         else:
             #print "GLU_OUTSIDE regular normals"
             #print '#%d'%(self.templateDSPL[0]+1), "glCallList Spheres1"
             GL.glCallList(self.templateDSPL[0]+1)
         #print '*%d'%GL.glGetIntegerv(GL.GL_LIST_INDEX), "glEndList Spheres0"
         GL.glEndList()
示例#8
0
    def makeTemplate(self):
        #print "Ellipsoids.makeTemplate"
        # it is asumed the right OpenGL context is active
        assert self.templateDSPL is None
        lFirstList = GL.glGenLists(3)
        #print "lFirstList Ellipsoids.makeTemplate", lFirstList, self.name
        lCurrentContext = self.viewer.currentCamera.tk.call(self.viewer.currentCamera._w, 'contexttag')
        self.templateDSPL = ( lFirstList, lCurrentContext )

        GL.glNewList(lFirstList+1, GL.GL_COMPILE)
        #print '+%d'%(lFirstList+1), lCurrentContext, "glNewList Ellipsoids1"
        extractedGlutSolidSphere(1, self.slices, self.stacks, 0)
        #print '*%d'%GL.glGetIntegerv(GL.GL_LIST_INDEX), "glEndList Ellipsoids1"
        GL.glEndList()
        
        GL.glNewList(lFirstList+2, GL.GL_COMPILE)
        #print '+%d'%(lFirstList+2), lCurrentContext, "glNewList Ellipsoids2"
        extractedGlutSolidSphere(1, self.slices, self.stacks, 1)
        #print '*%d'%GL.glGetIntegerv(GL.GL_LIST_INDEX), "glEndList Ellipsoids2"
        GL.glEndList()

        self.chooseTemplate()
示例#9
0
    def makeTemplate(self):
        if __debug__:
            if hasattr(DejaVu, 'functionName'): DejaVu.functionName()
        #print "Spheres.makeTemplate", self.quality
        # it is asumed the right OpenGL context is active
        # make sure we are not already in a newlist
        if GL.glGetIntegerv(GL.GL_LIST_INDEX) == [0]:
            assert self.templateDSPL is None
            lFirstList = GL.glGenLists(3)
            #lFirstList = self.firstList
            #print "Spheres.makeTemplate", lFirstList
            #print "lFirstList Spheres.makeTemplate", lFirstList, self.name
            lCurrentContext = self.viewer.currentCamera.tk.call(
                self.viewer.currentCamera._w, 'contexttag')
            self.templateDSPL = (lFirstList, lCurrentContext)

            if (hasattr(DejaVu, 'enableVBO') and DejaVu.enableVBO) \
              or DejaVu.enableVertexArrayNonVBO is True :
                lSphereGeom = self.asIndexedPolygons(run=1,
                                                     quality=self.quality - 1,
                                                     centers=((0, 0, 0), ),
                                                     radii=((1., ), ))
                GL.glNewList(lFirstList + 1, GL.GL_COMPILE)
                lSphereGeom.Draw()
                GL.glEndList()
                lSphereGeom.Set(invertNormals=True)
                GL.glNewList(lFirstList + 2, GL.GL_COMPILE)
                lSphereGeom.Draw()
                GL.glEndList()
            else:
                quality = self.quality * 5
                GL.glNewList(lFirstList + 1, GL.GL_COMPILE)
                #print '+%d'%(lFirstList+1), lCurrentContext, "glNewList Spheres1"
                extractedGlutSolidSphere(1, quality, quality, 0)
                #print '*%d'%GL.glGetIntegerv(GL.GL_LIST_INDEX), "glEndList Spheres1"
                GL.glEndList()
                GL.glNewList(lFirstList + 2, GL.GL_COMPILE)
                #print '+%d'%(lFirstList+2), lCurrentContext, "glNewList Spheres2"
                extractedGlutSolidSphere(1, quality, quality, 1)
                #print '*%d'%GL.glGetIntegerv(GL.GL_LIST_INDEX), "glEndList Spheres2"
                GL.glEndList()

            self.chooseTemplate()
示例#10
0
    def makeTemplate(self):
        if __debug__:
         if hasattr(DejaVu, 'functionName'): DejaVu.functionName()
        #print "Spheres.makeTemplate", self.quality
        # it is asumed the right OpenGL context is active
        # make sure we are not already in a newlist
        if GL.glGetIntegerv(GL.GL_LIST_INDEX) == [0]:
            assert self.templateDSPL is None
            lFirstList = GL.glGenLists(3)
            #lFirstList = self.firstList
            #print "Spheres.makeTemplate", lFirstList
            #print "lFirstList Spheres.makeTemplate", lFirstList, self.name
            lCurrentContext = self.viewer.currentCamera.tk.call(self.viewer.currentCamera._w,
                                                        'contexttag')
            self.templateDSPL = ( lFirstList, lCurrentContext )

            if (hasattr(DejaVu, 'enableVBO') and DejaVu.enableVBO) \
              or DejaVu.enableVertexArrayNonVBO is True :
                lSphereGeom = self.asIndexedPolygons(run=1, quality=self.quality-1,
                                                     centers=((0,0,0),), radii=((1.,),) )
                GL.glNewList(lFirstList+1, GL.GL_COMPILE)
                lSphereGeom.Draw()
                GL.glEndList()
                lSphereGeom.Set(invertNormals=True)
                GL.glNewList(lFirstList+2, GL.GL_COMPILE)
                lSphereGeom.Draw()
                GL.glEndList()
            else:
                quality = self.quality * 5
                GL.glNewList(lFirstList+1, GL.GL_COMPILE)
                #print '+%d'%(lFirstList+1), lCurrentContext, "glNewList Spheres1"
                extractedGlutSolidSphere(1, quality, quality, 0)
                #print '*%d'%GL.glGetIntegerv(GL.GL_LIST_INDEX), "glEndList Spheres1"
                GL.glEndList()
                GL.glNewList(lFirstList+2, GL.GL_COMPILE)
                #print '+%d'%(lFirstList+2), lCurrentContext, "glNewList Spheres2"
                extractedGlutSolidSphere(1, quality, quality, 1)
                #print '*%d'%GL.glGetIntegerv(GL.GL_LIST_INDEX), "glEndList Spheres2"
                GL.glEndList()

            self.chooseTemplate()
示例#11
0
    def getDpyList(self, objects):
        """function to obtain a display list for any object in DejaVu"""
        from opengltk.OpenGL import GL
        # Draw build a display function that contains global coloring,
        # transformation nd all global GL properties of this objects.
        # we cannot use the object's display list that does not contains this
        # info
        #if len(objects) == 1 and objects[0].dpyList:
        #    return objects[0].dpyList
        # transparent object need to be drawn last

        # reorder object so transparent object drawn last
        transparent = []
        opaque = []
        for obj in objects:
            if obj.transparent:  #obj.isTransparent():
                transparent.append(obj)
            else:
                opaque.append(obj)
        objlist = opaque + transparent

        lNewList = GL.glGenLists(1)
        #print "lNewList geomsChooser.getDpyList", lNewList, self.name
        dpyList = (lNewList,
                   self.viewer.currentCamera.tk.call(
                       self.viewer.currentCamera._w, 'contexttag'))

        camera = self.mv.GUI.VIEWER.currentCamera
        camera.Activate()

        GL.glNewList(dpyList, GL.GL_COMPILE)
        #print "geomChooser 208", GL.glGetIntegerv(GL.GL_LIST_INDEX)
        for obj in objlist:
            if obj.immediateRendering:  # or obj.hasChildWithImmediateRendering:
                camera.drawMode = 5
                camera.Draw(obj)
            else:
                camera.drawMode = 2
                camera.drawTransparentObjects = 0
                camera.hasTransparentObjects = 0
                # draw opaque object
                for m in obj.instanceMatricesFortran:
                    GL.glPushMatrix()
                    GL.glMultMatrixf(m)
                    if len(obj.children):
                        map(camera.Draw, obj.children)
                    else:
                        camera.Draw(obj)
                    GL.glPopMatrix()

                # draw transparent children of object
                if camera.hasTransparentObjects:
                    camera.drawTransparentObjects = 1
                    for m in obj.instanceMatricesFortran:
                        GL.glPushMatrix()
                        GL.glMultMatrixf(m)
                        map(camera.Draw, obj.children)
                        GL.glPopMatrix()
                # draw transparent object that do not have children
                if obj.isTransparent() and not len(obj.children):
                    camera.drawTransparentObjects = 1
                    for m in obj.instanceMatricesFortran:
                        GL.glPushMatrix()
                        GL.glMultMatrixf(m)
                        camera.Draw(obj)
                        GL.glPopMatrix()

        GL.glEndList()
        return dpyList
    def RedoDisplayList(self):
        if __debug__:
         if hasattr(DejaVu, 'functionName'): DejaVu.functionName()
            #print "IndexedGeom.RedoDisplayList", self.name
##          if __debug__:
##              print 'IndexedGeom RedoDisplayList for', self.fullName

        Geom.RedoDisplayList(self)

        if len(self.faceSet) and len(self.vertexSet) \
          and (   self.primitiveType == GL.GL_TRIANGLES \
               or self.primitiveType == GL.GL_QUADS \
               or self.primitiveType == GL.GL_POLYGON):

            # we always build this, that way we don't have to built on demand
            outl = self.outline
            if outl.colorAsMaterial:
                if self.materials[GL.GL_FRONT] and \
                       not self.inheritMaterial:
                    mat = self.materials[GL.GL_FRONT]
                    fpProp = []
                    fpBind = []
                    for propInd in range(4):
                        b, p = mat.GetProperty(propInd)
                        fpProp.append(p)
                        fpBind.append(b)
                    fpProp.append(mat.prop[4])
                    fpBind.append(mat.binding[4])
                else:
                    fpProp = None
                    fpBind = None

                if self.materials[GL.GL_BACK] and \
                   not self.inheritMaterial:
                    mat = self.materials[GL.GL_BACK]
                    bpProp = []
                    bpBind = []
                    for propInd in range(4):
                        b, p = mat.GetProperty(propInd)
                        bpProp.append(p)
                        bpBind.append(b)
                    bpProp.append(mat.prop[4])
                    bpBind.append(mat.binding[4])

                else:
                    bpProp = None
                    bpBind = None
            else:
                fpProp = bpProp = fpBind = bpBind = None

            texCoords = None

            if outl.lighting:
                norms = self.normals
            else:
                norms = None

            # WARNING: if texture, fpProp, bpProp, fpBind, bpBind,
            # are not passed (either None or arrays) we get a segmentation
            # fault if the surface has many colors (i.e. color MSMS by atom
            # type and dispaly outline seg faults)

            # calling with too many arguments segaults too
            # just add  None, None, None, None, after the line with colors

            if hasattr(outl, 'dpyList') and outl.dpyList is not None:
                lNewList = outl.dpyList[0]
            else:
                lNewList = GL.glGenLists(1)
                self.viewer.deleteOpenglList()

            #print "lNewList IndexedGeom.RedoDisplayList", lNewList, self.name
            lCurrentContext = self.viewer.currentCamera.tk.call(self.viewer.currentCamera._w, 'contexttag')
            outl.dpyList = ( lNewList, lCurrentContext)
                             
            GL.glNewList(outl.dpyList[0], GL.GL_COMPILE)
            #print '+%d'%outl.dpyList[0], lCurrentContext, "glNewList IndexedGeom"
            status=glDrawIndexedGeom(
                GL.GL_TRIANGLES,
                self.vertexSet.vertices.array,
                self.faceSet.faces.array,
                norms,
                texCoords,
                fpProp, bpProp, fpBind, bpBind,
                self.frontAndBack,
                1)  # 1 means use diffuse component if no lighting
            #print '*%d'%GL.glGetIntegerv(GL.GL_LIST_INDEX), "glEndList IndexedGeom"
            GL.glEndList()
            if not status:
                #print '-%d'%outl.dpyList[0], "glDeleteLists IndexedGeom"
                GL.glDeleteLists(outl.dpyList[0], 1)
                outl.dpyList = None
    def getDpyList(self,objects):
        """function to obtain a display list for any object in DejaVu"""
        from opengltk.OpenGL import GL
        # Draw build a display function that contains global coloring,
        # transformation nd all global GL properties of this objects.
        # we cannot use the object's display list that does not contains this
        # info
        #if len(objects) == 1 and objects[0].dpyList:
        #    return objects[0].dpyList
        # transparent object need to be drawn last

        # reorder object so transparent object drawn last
        transparent =[]
        opaque = []
        for obj in objects:
            if obj.transparent: #obj.isTransparent():
                transparent.append(obj)
            else:
                opaque.append(obj)
        objlist = opaque + transparent
        
        lNewList = GL.glGenLists(1)
        #print "lNewList geomsChooser.getDpyList", lNewList, self.name
        dpyList = ( lNewList,
                   self.viewer.currentCamera.tk.call(self.viewer.currentCamera._w, 'contexttag')
                  )

        camera = self.mv.GUI.VIEWER.currentCamera
        camera.Activate()

        GL.glNewList(dpyList, GL.GL_COMPILE)
        #print "geomChooser 208", GL.glGetIntegerv(GL.GL_LIST_INDEX)
        for obj in objlist:
            if obj.immediateRendering: # or obj.hasChildWithImmediateRendering:
                camera.drawMode=5
                camera.Draw(obj)
            else:
                camera.drawMode=2
                camera.drawTransparentObjects = 0
                camera.hasTransparentObjects = 0
                # draw opaque object
                for m in obj.instanceMatricesFortran:
                    GL.glPushMatrix()
                    GL.glMultMatrixf(m)
                    if len(obj.children):
                        map( camera.Draw, obj.children)
                    else:
                        camera.Draw(obj)
                    GL.glPopMatrix()
                
                # draw transparent children of object
                if camera.hasTransparentObjects:
                    camera.drawTransparentObjects = 1
                    for m in obj.instanceMatricesFortran:
                        GL.glPushMatrix()
                        GL.glMultMatrixf(m)
                        map( camera.Draw, obj.children)
                        GL.glPopMatrix()
                # draw transparent object that do not have children
                if obj.isTransparent() and not len(obj.children):
                    camera.drawTransparentObjects =1
                    for m in obj.instanceMatricesFortran:
                        GL.glPushMatrix()
                        GL.glMultMatrixf(m)
                        camera.Draw(obj)
                        GL.glPopMatrix()
                    

        GL.glEndList()    
        return dpyList