我正在尝试在python中创建一个包含过剩的窗口,并且具有以下代码:
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);
答案 0 :(得分:17)
我刚遇到完全相同的问题并找到了这个博客条目:
http://codeyarns.com/2012/04/27/pyopengl-glut-ctypes-error/
基本上,您需要使用b'Window Title'
答案 1 :(得分:2)
除了在字符串前添加b
:
b"MyWindow"
您还可以使用以下字符串将字符串转换为ascii字节:
bytes("MyWindow","ascii")
有关详细信息,请参阅以下链接:
答案 2 :(得分:0)
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)
答案 3 :(得分:-2)
在带有intel core duo的Windows 7 64位上
安装:python-3.4.0.amd64.exe
pip install image
pip install numpy
从http://www.lfd.uci.edu/~gohlke/pythonlibs/#jpype
下载了轮组拥有PyOpenGL-3.1.1-cp34-cp34m-win_amd64.whl
试图安装 pip install PyOpenGL-3.1.1-cp34-cp34m-win_amd64.whl
得到消息:
PyOpenGL-3.1.1-cp34-cp34m-win_amd64.whl is not supported wheel on this platform
升级了点子:
python -m pip --upgrade pip
升级后成功安装
pip install PyOpenGL-3.1.1-cp34-cp34m-win_amd64.whl
pip install PyOpenGL_accelerate-3.1.1-cp34-cp34m-win_amd64.whl
希望运行以下代码:http://noobtuts.com/python/opengl-introduction
得到错误:
ctypes.ArgumentError: argument 1: <class 'TypeError'>: wrong type
更改了功能:glutCreateWindow("name")
到glutCreateWindow(b'name')
并让它运行。
概括地说:
python -m pip --upgrade pip
pip install image
pip install numpy
pip install PyOpenGL-3.1.1-cp34-cp34m-win_amd64.whl
pip install PyOpenGL_accelerate-3.1.1-cp34-cp34m-win_amd64.whl
将来电从glutCreateWindow("name")
更改为glutCreateWindow(b'name')