【问题标题】:PyOpenGL, pygame, and errors when drawing a shapePyOpenGL、pygame 和绘制形状时的错误
【发布时间】:2021-04-30 20:15:46
【问题描述】:

我一直在使用 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>)

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

这是出现问题的脚本的 sn-p:

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

【问题讨论】:

    标签: python python-3.x opengl pygame pyopengl


    【解决方案1】:

    glVertex2fv 的参数必须是一个有 2 个元素的数组。如果您有两个未在数组中聚合的单独坐标,则必须使用glVertex2f。见glVertex

    glVertex2fv(cosine, sine)

    glVertex2f(cosine, sine)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-04-23
      • 1970-01-01
      • 2022-10-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多