是否有可以在OpenGL中显示UTF-8字符串的python模块?
我找到了pyFTGL但是当我运行以下代码时:
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, [1, 1, 1, 1])
font = FTGL.PolygonFont("NeoTechStd-Medium.ttf")
font.FaceSize(8)
font.line_height
font.Render("Angle = ? \u03C4")
我收到此错误:
font.Render(u"Weld Head Angle = ? \u03C4")
Boost.Python.ArgumentError: Python argument types in
PolygonFont.Render(PolygonFont, unicode)
did not match C++ signature:
Render(FontWrapper<FTPolygonFont> {lvalue}, char const*, double)
Render(FontWrapper<FTPolygonFont> {lvalue}, char const*)
DEBUG:Helpers.opengl_pipe:Redrawing contents of GLArea.
答案 0 :(得分:2)
您没有传递Render方法UTF-8;你正在传递一个unicode文字。
您需要将其编码为UTF-8:
font.Render("Angle = ? \u03C4".encode('utf8'))
我衷心建议您阅读this article on the subject of Unicode and encodings以了解其中的差异。