Reputation: 551
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);
Upvotes: 8
Views: 10354
Reputation: 1
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)
To solve the issue finally, you need to change lib/site-packages/OpenGL/GLUT/special.py file's content like this, or like this:
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)
Upvotes: 0
Reputation: 667
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:
ctypes.ArgumentError with file_reader on Python 3
Upvotes: 3
Reputation: 74
on the Windows 7 64-bit with intel core duo
installed : python-3.4.0.amd64.exe
pip install image
pip install numpy
downloaded wheel pack from : http://www.lfd.uci.edu/~gohlke/pythonlibs/#jpype
having PyOpenGL-3.1.1-cp34-cp34m-win_amd64.whl
tried to install pip install PyOpenGL-3.1.1-cp34-cp34m-win_amd64.whl
got message :
PyOpenGL-3.1.1-cp34-cp34m-win_amd64.whl is not supported wheel on this platform
upgraded pip:
python -m pip --upgrade pip
after upgrading it was succesfully installed
pip install PyOpenGL-3.1.1-cp34-cp34m-win_amd64.whl
pip install PyOpenGL_accelerate-3.1.1-cp34-cp34m-win_amd64.whl
wanted to run code from : http://noobtuts.com/python/opengl-introduction
got error :
ctypes.ArgumentError: argument 1: <class 'TypeError'>: wrong type
changed function: glutCreateWindow("name")
to glutCreateWindow(b'name')
and got it running.
summarize:
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
change call from glutCreateWindow("name")
to glutCreateWindow(b'name')
Upvotes: -2
Reputation: 228
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'
Upvotes: 19