Raoul
Raoul

Reputation: 1892

Unable to clear OpenGL viewport

I copied this script (pasted below) and ran it. Unfortunately, the image appears scrambled, as below. Can anyone help me get rid of that?

Config:

enter image description here

Upvotes: 1

Views: 668

Answers (1)

Dair
Dair

Reputation: 16240

Move, glClear to the paint method:

def paintGL(self):
    glClear(GL_COLOR_BUFFER_BIT)
    glColor3f(0.0, 0.0, 1.0)
    glRectf(-5, -5, 5, 5)
    glColor3f(1.0, 0.0, 0.0)
    glBegin(GL_LINES)
    glVertex3f(0, 0, 0)
    glVertex3f(20, 20, 0)
    glEnd()

Also here:

    def initializeGL(self):
        glColor3f(0.0, 0.0, 1.0)

you don't need glClear here. Produces:

enter image description here

Upvotes: 3

Related Questions