PyOpenGL、pygame 和绘制形状时的错误

PyOpenGL, pygame, and errors when drawing a shape

我一直在使用 python、pygame 和 pyopengl 编写自定义贪吃蛇游戏。我正在尝试在屏幕上绘制一个形状。但是,我偶然发现了这个错误:

Traceback (most recent call last):
  File "F:\Projects\python\Python_Game\venv\lib\site-packages\OpenGL\latebind.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:\Projects\python\Python_Game\src\game.py", line 35, in <module>
    main()
  File "F:\Projects\python\Python_Game\src\game.py", line 31, in main
    game.draw_shapes()
  File "F:\Projects\python\Python_Game\src\game_classes.py", line 203, in draw_shapes
    f.draw()
  File "F:\Projects\python\Python_Game\src\game_classes.py", line 128, in draw
    shape.draw()
  File "F:\Projects\python\Python_Game\src\opengl_classes.py", line 128, in draw
    glVertex2fv(cosine, sine)
  File "F:\Projects\python\Python_Game\venv\lib\site-packages\OpenGL\latebind.py", line 47, in __call__
    return self._finalCall( *args, **named )
  File "F:\Projects\python\Python_Game\venv\lib\site-packages\OpenGL\wrapper.py", line 689, in wrapperCall
    pyArgs = tuple( calculate_pyArgs( args ))
  File "F:\Projects\python\Python_Game\venv\lib\site-packages\OpenGL\wrapper.py", line 450, in calculate_pyArgs
    yield converter(args[index], self, args)
  File "F:\Projects\python\Python_Game\venv\lib\site-packages\OpenGL\arrays\arrayhelpers.py", line 115, in asArraySize
    byteSize = handler.arrayByteCount( result )
AttributeError: ("'NumberHandler' object has no attribute 'arrayByteCount'", <function asArrayTypeSize.<locals>.asArraySize at 0x000002642A35DCA0>)

控制台向我抛出类型错误和属性错误。我不确定这是由于我的代码还是其中一个库的问题。我正在使用 Python 3.9.1、pygame 2.0.1 和 PyOpenGL 3.1.5。

这是出现问题的脚本片段:

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()

glVertex2fv 的参数必须是一个包含 2 个元素的数组。如果你有两个单独的坐标,它们没有聚集在一个数组中,你必须使用 glVertex2f。见 glVertex:

glVertex2fv(cosine, sine)

glVertex2f(cosine, sine)