2012-07-12 63 views
1

是否有一个python模块可以在OpenGL中显示UTF-8字符串?OpenGL utf-8字符串渲染

我发现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. 

回答

2

你是不是通过Render方法UTF-8;你传递它一个Unicode字面。

您需要将其编码为UTF-8:

font.Render("Angle = ? \u03C4".encode('utf8')) 

我非常乐意推荐您阅读this article on the subject of Unicode and encodings帮助理解上的差异。