Example #1
0
    def compile(self, mode=None):
        """Build the cached display list for this background object
        
        Note: we store 2 display lists in the cache, but only return
        one from the compile method.  The second list is the final
        rendering list, while the first is just the low-level rendering
        code.
        """
        colorSet = self.colorSet()
        if len(colorSet):
            vertices, colors = self.buildSphere(colorSet)
            glMultMatrixf(mode.matrix)
            first = displaylist.DisplayList()
            first.start()
            try:
                glVertexPointerf(vertices)
                glColorPointerf(colors)
                glEnableClientState(GL_VERTEX_ARRAY)
                glEnableClientState(GL_COLOR_ARRAY)
                glDrawArrays(GL_TRIANGLE_STRIP, 0, len(vertices))
            finally:
                first.end()
            second = displaylist.DisplayList()
            second.start()
            try:
                glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE)
                glDisable(
                    GL_DEPTH_TEST
                )  # we don't want to do anything with the depth buffer...
                glDisable(GL_LIGHTING)
                glEnable(GL_COLOR_MATERIAL)
                glDisable(GL_CULL_FACE)

                for index in range(int(SEGMENTS)):
                    first()
                    glRotated(360.0 / SEGMENTS, 0, 1, 0)
                glDisableClientState(GL_VERTEX_ARRAY)
                glDisableClientState(GL_COLOR_ARRAY)
                # now, completely wipe out the depth buffer, so this appears as a "background"... no idea how expensive this is
                glClear(GL_DEPTH_BUFFER_BIT)

                glEnable(GL_DEPTH_TEST)
                glEnable(GL_LIGHTING)
                glColor(0.0, 0.0, 0.0)
                glDisable(GL_COLOR_MATERIAL)
                glEnable(GL_CULL_FACE)
                glFrontFace(GL_CCW)

                holder = mode.cache.holder(self, (first, second))
                for field in protofunctions.getFields(self):
                    # change to any field requires a recompile
                    if field.name != 'bound':
                        holder.depend(self, field)
                return second
            finally:
                second.end()
        holder = mode.cache.holder(self, (None, ()))
        return None
Example #2
0
    def compile(self, mode=None):
        """Compile material information into readily-rendered format"""
        holder = mode.cache.holder(self, None)
        for field in protofunctions.getFields(self):
            # change to any field requires a recompile
            holder.depend(self, field)
#		def dl():
        dl = displaylist.DisplayList()
        dl.start()
        try:
            alpha = 1.0 - self.transparency
            renderingData = zeros((4, 4), 'f')
            renderingData[:, 3] = alpha
            diffuseColor = self.diffuseColor.astype('f')
            renderingData[0, :3] = diffuseColor
            renderingData[1, :3] = self.emissiveColor.astype('f')
            renderingData[2, :3] = self.specularColor.astype('f')
            renderingData[3, :3] = (diffuseColor *
                                    self.ambientIntensity).astype('f')
            map(glMaterialfv, self.faces, self.datamap, renderingData)
            glMaterialf(self.faces[0], GL_SHININESS, self.shininess * 128)
        finally:
            dl.end()
        holder.data = dl
        return holder.data
Example #3
0
 def compile(self, mode=None):
     """Compile the geometry as a display-list"""
     dl = displaylist.DisplayList()
     dl.start()
     try:
         self.do()
         holder = mode.cache.holder(self, dl)
         return dl
     finally:
         dl.end()
Example #4
0
    def compile(self, mode=None):
        """Compile the VPCurve into a display-list
        """
        # This code is not OpenGL 3.1 compatible
        if self.pos.any():
            dl = displaylist.DisplayList()
            #XXX should do sanity checks here...
            dl.start()
            try:
                pos = self.pos
                color = self.color
                colorLen = len(color)
                killThickness = 0
                if self.radius:
                    glLineWidth(self.radius * 2)
                    killThickness = 1
                try:

                    glEnable(GL_COLOR_MATERIAL)
                    try:
                        glBegin(GL_LINE_STRIP)
                        try:
                            lastColor = None
                            for index in range(len(pos)):
                                point = pos[index]
                                if index < colorLen:
                                    col = tuple(color[index])
                                    if col != lastColor:
                                        glColor3dv(col)
                                    lastColor = col
                                glVertex3dv(point)
                        finally:
                            glEnd()
                    finally:
                        glDisable(GL_COLOR_MATERIAL)
                finally:
                    if killThickness:
                        glLineWidth(1)
            finally:
                dl.end()
            holder = mode.cache.holder(self, dl)
            for field in protofunctions.getFields(self):
                # change to any field requires a recompile
                holder.depend(self, field)
            return dl
        return None
Example #5
0
 def compile(self, mode):
     """Compile this geometry node to display-list
     
     Initial code is taken from the PyOpenGL-Demo gears.py
     which was in the Public Domain and converted multiple 
     times since then.
     """
     dl = displaylist.DisplayList()
     dl.start()
     try:
         self.gear(
             self.inner_radius,
             self.outer_radius,
             self.width,
             self.teeth,
             self.tooth_depth,
         )
         holder = mode.cache.holder(self, dl)
         for name in ('inner_radius', 'outer_radius', 'width', 'teeth',
                      'tooth_depth'):
             holder.depend(self, name)
         return dl
     finally:
         dl.end()
Example #6
0
    def compile(self, mode=None):
        """Compile the IndexedLineSet into a display-list
        """
        if self.coord and len(self.coord.point) and len(self.coordIndex):
            dl = displaylist.DisplayList()
            holder = mode.cache.holder(self, dl)
            for field in protofunctions.getFields(self):
                # change to any field requires a recompile
                holder.depend(self, field)
            for (n, attr) in [
                (self.coord, 'point'),
                (self.color, 'color'),
            ]:
                if n:
                    holder.depend(n, protofunctions.getField(n, attr))

            points = self.coord.point
            indices = expandIndices(self.coordIndex)
            #XXX should do sanity checks here...
            if self.color and len(self.color.color):
                colors = self.color.color
                if self.colorPerVertex:
                    if len(self.colorIndex):
                        colorIndices = expandIndices(self.colorIndex)
                    else:
                        colorIndices = indices
                else:
                    if len(self.colorIndex):
                        # each item represents a single polyline colour
                        colorIndices = self.colorIndex
                    else:
                        # each item in color used in turn by each polyline
                        colorIndices = range(len(indices))
                # compile the color-friendly ILS
                dl.start()
                try:
                    glEnable(GL_COLOR_MATERIAL)
                    for index in range(len(indices)):
                        polyline = indices[index]
                        color = colorIndices[index]
                        try:
                            color = int(color)
                        except (TypeError, ValueError), err:
                            glBegin(GL_LINE_STRIP)
                            try:
                                for i, c in map(None, polyline, color):
                                    if c is not None:
                                        # numpy treats None as retrieve all??? why?
                                        currentColor = colors[c]
                                        if currentColor is not None:
                                            glColor3d(*currentColor)
                                    glVertex3f(*points[i])
                            finally:
                                glEnd()
                        else:
                            glColor3d(*colors[color])
                            glBegin(GL_LINE_STRIP)
                            try:
                                for i in polyline:
                                    glVertex3f(*points[i])
                            finally:
                                glEnd()
                    glDisable(GL_COLOR_MATERIAL)
                finally:
                    dl.end()
Example #7
0
 def compile(
     self,
     visible=1,
     lit=1,
     textured=1,
     transparent=0,
     mode=None,
 ):
     """Compile to an opaque textured display-list"""
     dl = displaylist.DisplayList()
     dl.start()
     try:
         if (not self.target.normal) or (
                 self.target.normal and not len(self.target.normal.vector)):
             # need to generate per-face or per-vertex-use vectors,
             # require tessellation!
             vertices = self.tessellate()
             if not vertices:
                 return None
             if self.target.normalPerVertex:
                 normalArray = build_normalPerVertex(
                     vertices, self.target.creaseAngle)
                 normalStep = 1
             else:
                 normalArray = triangleutilities.normalPerFace(vertexArray)
                 normalArray = repeat(normalArray, [3] * len(normalArray),
                                      0)
                 normalStep = 3
             glBegin(GL_TRIANGLES)
             if self.target.DEBUG_DRAW_NORMALS:
                 normalValues = []
             try:
                 normalIndex = -1
                 for vIndex in xrange(len(vertices)):
                     vertex = vertices[vIndex]
                     if vIndex % normalStep == 0:
                         normalIndex += 1
                     glNormal3dv(normalArray[normalIndex])
                     if vertex.color is not None:
                         glColor3dv(vertex.color)
                     if vertex.textureCoordinate is not None:
                         glTexCoord2dv(vertex.textureCoordinate)
                     glVertex3dv(vertex.point)
                     if self.target.DEBUG_DRAW_NORMALS:
                         normalValues.append(
                             (vertex.point,
                              vertex.point + normalArray[normalIndex]))
             finally:
                 glEnd()
             if self.target.DEBUG_DRAW_NORMALS:
                 glBegin(GL_LINES)
                 try:
                     for (v, n) in normalValues:
                         glColor3f(1, 0, 0)
                         glVertex3dv(v)
                         glColor3f(0, 1, 0)
                         glVertex3dv(n)
                 finally:
                     glEnd()
         else:
             # already has normals, can render without tessellation
             for polygon in self.polygons():
                 if len(polygon) == 3:
                     glBegin(GL_TRIANGLES)
                 elif len(polygon) == 4:
                     glBegin(GL_QUADS)
                 elif len(polygon) < 3:
                     continue
                 else:
                     glBegin(GL_POLYGON)
                 try:
                     for vertex in polygon:
                         if vertex.normal is not None:
                             glNormal3dv(vertex.normal)
                         if vertex.color is not None:
                             glColor3dv(vertex.color)
                         if vertex.textureCoordinate is not None:
                             glTexCoord2dv(vertex.textureCoordinate)
                         glVertex3dv(vertex.point)
                 finally:
                     glEnd()
         return DisplayListRenderer(dl)
     finally:
         dl.end()