我用Python Imaging Library
来加载.ttf
字体。这是代码:
self.rect = Image.new("RGBA", (600,100), (255,255,255))
self.draw = ImageDraw.Draw(self.rect)
self.font = ImageFont.truetype("font.ttf", 96)
self.draw.text((5,0), "activatedgeek", (0,0,0), font=self.font)
self.texture = self.loadFont(self.rect)
这是loadFont()
各个类的功能:
def loadFont(self, im):
try:
ix, iy, image = im.size[0], im.size[1], im.tostring("raw", "RGBA", 0, -1)
except SystemError:
ix, iy, image = im.size[0], im.size[1], im.tostring("raw", "RGBX", 0, -1)
retid = gl.glGenTextures(1)
gl.glPixelStorei(gl.GL_UNPACK_ALIGNMENT,1)
gl.glBindTexture(gl.GL_TEXTURE_2D,retid)
gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER, gl.GL_LINEAR_MIPMAP_LINEAR)
gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MIN_FILTER, gl.GL_LINEAR_MIPMAP_LINEAR)
gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_WRAP_S, gl.GL_CLAMP)
gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_WRAP_T, gl.GL_CLAMP)
gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_GENERATE_MIPMAP, gl.GL_TRUE)
gl.glTexImage2D(gl.GL_TEXTURE_2D,0,3,ix,iy,0,gl.GL_RGBA,gl.GL_UNSIGNED_BYTE,image)
return retid
这是我使用的快照,glReadPixels()
不幸的是与使用PyQt
.
它显示了一个不需要的边界,一些人工制品。请帮我纠正这个问题。