为什么 pyglet 画不出八边形?

Why pyglet couldn't draw octagon?

我试图在这里创建一个二维八边形,但由于某种原因,我没有成功。输出只是一个黑屏。我很确定问题出在这部分代码中:

def on_draw(self):

    self.clear()
    glBegin(GL_OCTAGONS)
    glColor3ub(0,255,0)
    glVertex2f(0,0)
    glColor3ub(0,255,0)
    glVertex2f(10,0)
    glColor3ub(0,255,0)
    glVertex2f(15,5)
    glColor3ub(0,255,0)
    glVertex2f(15,15)
    glColor3ub(0,255,0)
    glVertex2f(10,20)
    glColor3ub(0,255,0)
    glVertex2f(0,20)
    glColor3ub(0,255,0)
    glVertex2f(-5,15)
    glColor3ub(0,255,0)
    glVertex2f(-5,5)
    glEnd()
        

GL_OCTAGONS 不是 glBegin. This is just an arbitrary assumption from you. You've to use one of the OpenGL Primitive 类型的有效参数。
使用 GL_POLYGONGL_TRIANGLE_FAN:

glBegin(GL_OCTAGONS)

glBegin(GL_POLYGON)