Python glutCreateWindow error 'wrong type'

I am trying to create a redundant window 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 am getting an error on the 'glutCreateWindow' line saying the following:

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 for this function indicates

int glutCreateWindow(char *name);

      

+3


source to share


4 answers


I just ran into the same problem and found this blog post:

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



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

+14


source


Apart from adding a b

before the line:

b"MyWindow"

      

You can also convert string to ascii bytes with this:

bytes("MyWindow","ascii")

      




For more information, you can refer to these links:

Ctypes PyOpenGL GLUT error

ctypes.ArgumentError with file_reader in Python 3

+1


source


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 problem, finally, you need to change the contents of lib / site-packages / OpenGL / GLUT / special.py, for example, 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)

      

0


source


on 64-bit Windows 7 with Intel Core duo

: python-3.4.0.amd64.exe

pip install image
pip install numpy

      

downloaded wheel package from: http://www.lfd.uci.edu/~gohlke/pythonlibs/#jpype

with PyOpenGL-3.1.1-cp34-cp34m-win_amd64.whl

tried to install pip install PyOpenGL-3.1.1-cp34-cp34m-win_amd64.whl

message received:

PyOpenGL-3.1.1-cp34-cp34m-win_amd64.whl is not supported wheel on this platform

      

updated:

python -m pip --upgrade pip

      

after upgrade it was installed successfully

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 the code from: http://noobtuts.com/python/opengl-introduction

received error:

ctypes.ArgumentError: argument 1: <class 'TypeError'>: wrong type

      

function changed: glutCreateWindow("name")

before glutCreateWindow(b'name')

and running.

summarizing:

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 the call from glutCreateWindow("name")

toglutCreateWindow(b'name')

-2


source







All Articles