我正在用pySFML编写一个简单的位图字体渲染器,我想问是否有更好更快的方法来解决这个问题。在
我使用VertexArray并为字符串中的每个字符创建一个四元组。每个四边形都应用了适当的纹理坐标。在
示例字体(PNG文件):
字体呈现代码:import sfml
class BitmapFont(object):
'''
Loads a bitmap font.
`chars` is string with all characters available in the font file, example: '+0123456789x'.
`widths` is mapping between characters and character width in pixels.
'''
def __init__(self, path, chars, widths, colors=1, kerning=0):
self.texture = sfml.Texture.from_file(path)
self.colors = colors
self.height = self.texture.height / self.colors
self.chars = chars
self.kerning = kerning
self.widths = widths
self.glyphs = []
y