Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

PyOpenGL GLUT ctypes error

📅 2012-Apr-26 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ ctypes, error, pyopengl, python, unicode ⬩ 📚 Archive

Installing PyOpenGL can be quite painful on 64-bit Python 3.x with Windows 7. But, once you that is done, you might face this error in your program:

glutCreateWindow( "cube" )
# ctypes.ArgumentError: argument 1: <class 'TypeError'>: wrong type

ctypes provides the data types to communicate with C libraries. I got the above error when I was passing a string to a GLUT function. The error is caused because underneath the PyOpenGL call is an old-school C function expecting ASCII text, whereas Python 3.x gives it Unicode text by default.

So, the solution is to pass the string in the bytes format. In the above case, the error was solved by changing it to:

glutCreateWindow( b"cube" )

Tried with:

© 2022 Ashwin Nanjappa • All writing under CC BY-SA license • 🐘📧