Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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);
like image 418
Gregory Sims Avatar asked Nov 23 '14 19:11

Gregory Sims


2 Answers

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'

like image 106
Sprucial Avatar answered Oct 23 '22 03:10

Sprucial


Apart from add a b before the string:

b"MyWindow"

You can also convert the string to ascii bytes with this:

bytes("MyWindow","ascii")

For more details, you could refer to these links:

PyOpenGL GLUT ctypes error

ctypes.ArgumentError with file_reader on Python 3

like image 3
Hansimov Avatar answered Oct 23 '22 02:10

Hansimov