Search code examples
pythonpyglet

Why pyglet couldn't draw octagon?


I was trying to create an 2D octagon here, and for some reason, I didn't succeded. the output is just a black screen. I am pretty sure the problem is inside this part of code:

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

Solution

  • GL_OCTAGONS is not a valid argument to glBegin. This is just an arbitrary assumption from you. You've to use one of the OpenGL Primitive types.
    Use either GL_POLYGON or GL_TRIANGLE_FAN:

    glBegin(GL_OCTAGONS)

    glBegin(GL_POLYGON)