我正在尝试在python中创建一个具有create的窗口,并有以下代码:
glutInit()
glutInitWindowSize(windowWidth, windowHeight)
glutInitWindowPosition(int(centreX - windowWidth/2), int(centreY - windowHeight/2))
glutCreateWindow("MyWindow")
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH)
glutDisplayFunc(displayFun)
glutIdleFunc(animateFun)
glutKeyboardFunc(keyboardFun)
glutPassiveMotionFunc(mouseFun)
glutReshapeFunc(reshapeFun)
initFun()
#loadTextures()
glutMainLoop()我在“glutCreateWindow”行中看到一个错误,它是这样写的:
Traceback (most recent call last):
File "F:\MyProject\main.py", line 301, in <module>
glutCreateWindow("MyWindow")
File "C:\Python34\lib\site-packages\OpenGL\GLUT\special.py", line 73, in glutCreateWindow
return __glutCreateWindowWithExit(title, _exitfunc)
ctypes.ArgumentError: argument 1: <class 'TypeError'>: wrong type此函数的文档指定
int glutCreateWindow(char *name);发布于 2014-11-26 16:28:09
我刚刚遇到了同样的问题,发现了这篇博客文章:
http://codeyarns.com/2012/04/27/pyopengl-glut-ctypes-error/
基本上,您需要指定正在传递字节数据,而不是使用b'Window Title'传递字符串。
发布于 2017-12-16 06:11:58
除了在字符串之前添加一个b之外:
b"MyWindow"您还可以使用以下方法将字符串转换为ascii字节:
bytes("MyWindow","ascii")有关更多细节,您可以参考以下链接:
发布于 2018-03-29 12:25:52
def glutCreateWindow(title):
"""Create window with given title
This is the Win32-specific version that handles
registration of an exit-function handler
"""
return __glutCreateWindowWithExit(title.encode(), _exitfunc)为了最终解决这个问题,您需要更改lib/site-packages/OpenGL/GLUT/special.py文件的内容,如这样或这样:
def glutCreateWindow(title):
"""Create window with given title
This is the Win32-specific version that handles
registration of an exit-function handler
"""
return __glutCreateWindowWithExit(bytes(title,"ascii"), _exitfunc)https://stackoverflow.com/questions/27093037
复制相似问题