pythonglutglutcreatewindow

Python glutCreateWindow error 'wrong type'


I'm trying to create a window with glut in python and have the following code:

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()

I get an error on the 'glutCreateWindow' line saying this:

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

the documentation on this function specifies

int glutCreateWindow(char *name);

Solution

  • I just encountered exactly the same problem and found this blog entry:

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

    Basically you need to specify that you are passing byte data rather than a string using b'Window Title'