8

我正在尝试在 python 中创建一个带有 glut 的窗口并具有以下代码:

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);
4

4 回答 4

19

我刚刚遇到了完全相同的问题,发现了这个博客条目:

http://codeyarns.com/2012/04/27/pyopengl-glut-ctypes-error/

基本上,您需要指定您正在传递字节数据而不是使用字符串b'Window Title'

于 2014-11-26T16:28:09.433 回答
3

除了b在字符串前添加一个:

b"MyWindow"

您还可以使用以下方法将字符串转换为 ascii 字节:

bytes("MyWindow","ascii")

有关更多详细信息,您可以参考以下链接:

PyOpenGL GLUT ctypes 错误

ctypes.ArgumentError 与 Python 3 上的 file_reader

于 2017-12-16T06:11:58.720 回答
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)
于 2018-03-29T12:25:52.037 回答
-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')

于 2016-05-09T01:16:26.213 回答