Skip to content
Advertisement

PyOpenGL, pygame, and errors when drawing a shape

I’ve been writing a custom snake game using python, pygame, and pyopengl. I’m trying to draw a shape on the screen. However, I’ve stumbled upon this error:

Traceback (most recent call last):
  File "F:ProjectspythonPython_Gamevenvlibsite-packagesOpenGLlatebind.py", line 43, in __call__
    return self._finalCall( *args, **named )
TypeError: 'NoneType' object is not callable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "F:ProjectspythonPython_Gamesrcgame.py", line 35, in <module>
    main()
  File "F:ProjectspythonPython_Gamesrcgame.py", line 31, in main
    game.draw_shapes()
  File "F:ProjectspythonPython_Gamesrcgame_classes.py", line 203, in draw_shapes
    f.draw()
  File "F:ProjectspythonPython_Gamesrcgame_classes.py", line 128, in draw
    shape.draw()
  File "F:ProjectspythonPython_Gamesrcopengl_classes.py", line 128, in draw
    glVertex2fv(cosine, sine)
  File "F:ProjectspythonPython_Gamevenvlibsite-packagesOpenGLlatebind.py", line 47, in __call__
    return self._finalCall( *args, **named )
  File "F:ProjectspythonPython_Gamevenvlibsite-packagesOpenGLwrapper.py", line 689, in wrapperCall
    pyArgs = tuple( calculate_pyArgs( args ))
  File "F:ProjectspythonPython_Gamevenvlibsite-packagesOpenGLwrapper.py", line 450, in calculate_pyArgs
    yield converter(args[index], self, args)
  File "F:ProjectspythonPython_Gamevenvlibsite-packagesOpenGLarraysarrayhelpers.py", line 115, in asArraySize
    byteSize = handler.arrayByteCount( result )
AttributeError: ("'NumberHandler' object has no attribute 'arrayByteCount'", <function asArrayTypeSize.<locals>.asArraySize at 0x000002642A35DCA0>)

The console is throwing me a TypeError and an Attribute error. I’m not sure if this is due to my code or an issue with one of the libraries. I’m using Python 3.9.1, pygame 2.0.1, and PyOpenGL 3.1.5.

Here’s the snippet of my script where the issue arises:

class Circle:
    def __init__(self, pivot: Point, radius: int, sides: int, fill: bool, color: Color):
        self.pivot = pivot
        self.radius = radius
        self.sides = sides
        self.fill = fill
        self.color = color

    # Draw the shape of the circle
    def draw(self):
        glColor3f(self.color.r, self.color.g, self.color.b)
        if self.fill:
            glBegin(GL_POLYGON)
        else:
            glBegin(GL_LINE_LOOP)
        for i in range(100):
            cosine = self.radius * cos(i*2*pi/self.sides) + self.pivot.x
            sine = self.radius * sin(i*2*pi/self.sides) + self.pivot.y
            glVertex2fv(cosine, sine)
        glEnd()

Advertisement

Answer

The argument of glVertex2fv must be an array with 2 elements. If you have two separate coordinates which are not aggregated in an array you must use glVertex2f. See glVertex:

glVertex2fv(cosine, sine)

glVertex2f(cosine, sine)
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement