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);
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'
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:
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)
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')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.