Exemple #1
0
    def drawToolMarkers(self):
        if self.editor.currentTool != self:
            return

        if self.panel and self.replacing:
            blockInfo = self.replaceBlockInfo
        else:
            blockInfo = self.blockInfo

        color = 1.0, 1.0, 1.0, 0.35
        if blockInfo:
            terrainTexture = self.editor.level.materials.terrainTexture
            tex = self.editor.level.materials.blockTextures[blockInfo.ID, blockInfo.blockData, 0]  # xxx
            tex = Texture(self.blockTexFunc(terrainTexture, tex))

            # color = (1.5 - alpha, 1.0, 1.5 - alpha, alpha - 0.35)
            GL.glMatrixMode(GL.GL_TEXTURE)
            GL.glPushMatrix()
            GL.glScale(16., 16., 16.)

        else:
            tex = None
            # color = (1.0, 0.3, 0.3, alpha - 0.35)

        GL.glPolygonOffset(DepthOffset.FillMarkers, DepthOffset.FillMarkers)
        self.editor.drawConstructionCube(self.selectionBox(),
                                         color,
                                         texture=tex)

        if blockInfo:
            GL.glMatrixMode(GL.GL_TEXTURE)
            GL.glPopMatrix()
Exemple #2
0
    def initTextures(self):

        terrainTexture = self.editor.level.materials.terrainTexture

        blockTextures = self.editor.level.materials.blockTextures[:, 0]

        if hasattr(self, 'blockTextures'):
            for tex in self.blockTextures.itervalues():
                tex.delete()

        self.blockTextures = {}

        def blockTexFunc(type):
            def _func():
                s, t = blockTextures[type][0]
                if not hasattr(terrainTexture, "data"):
                    return
                w, h = terrainTexture.data.shape[:2]
                s = s * w / 256
                t = t * h / 256
                texData = numpy.array(terrainTexture.data[t:t + h / 16,
                                                          s:s + w / 16])
                GL.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGBA, w / 16,
                                h / 16, 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE,
                                texData)

            return _func

        for type in range(256):
            self.blockTextures[type] = Texture(blockTexFunc(type))