如何让PyOpenGL的标题显示中文
How to make PyOpenGL's title show Chinese
代码在这里。
from OpenGL.GL import *
from OpenGL.GLU import *
from OpenGL.GLUT import *
import sys
def initial():
glClearColor(1.0, 1.0, 1.0, 1.0)
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
gluOrtho2D(-10.0, 10.0, -10.0, 10.0)
def Display():
glClear(GL_COLOR_BUFFER_BIT)
glColor3f(1.0, 0.0, 0.0)
glViewport(0, 0, 200, 200)
glColor3f(0.0, 0.0, 1.0)
glViewport(200, 0, 200, 200)
glFlush()
def main():
glutInit(sys.argv)
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB)
glutInitWindowPosition(100, 100)
glutInitWindowSize(400, 200)
glutCreateWindow("一二三四")
initial()
glutDisplayFunc(Display)
glutMainLoop()
if __name__ == "__main__":
main()
标题是“一二三四”,结果是
我不想从UTF-8转成GBK,请问有什么办法可以解决吗?
As far as I know, glfw can support Chinese. But I am not familiar with it.
我的Python版本是3.7.0 32位
经过一番测试,我找到了解决方案:
只需改变
glutCreateWindow("一二三四")
至
glutCreateWindow("一二三四".encode("gb2312"))
代码在这里。
from OpenGL.GL import *
from OpenGL.GLU import *
from OpenGL.GLUT import *
import sys
def initial():
glClearColor(1.0, 1.0, 1.0, 1.0)
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
gluOrtho2D(-10.0, 10.0, -10.0, 10.0)
def Display():
glClear(GL_COLOR_BUFFER_BIT)
glColor3f(1.0, 0.0, 0.0)
glViewport(0, 0, 200, 200)
glColor3f(0.0, 0.0, 1.0)
glViewport(200, 0, 200, 200)
glFlush()
def main():
glutInit(sys.argv)
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB)
glutInitWindowPosition(100, 100)
glutInitWindowSize(400, 200)
glutCreateWindow("一二三四")
initial()
glutDisplayFunc(Display)
glutMainLoop()
if __name__ == "__main__":
main()
标题是“一二三四”,结果是
我不想从UTF-8转成GBK,请问有什么办法可以解决吗?
As far as I know, glfw can support Chinese. But I am not familiar with it.
我的Python版本是3.7.0 32位
经过一番测试,我找到了解决方案:
只需改变
glutCreateWindow("一二三四")
至
glutCreateWindow("一二三四".encode("gb2312"))