PyOpenGL flickering points and lines

58 Views Asked by At

I'm trying to visualize 3D human keypoints in PyOpenGL, the code works fine if one human is present.

more than one, the points and lines starts to flicker.

while True:
        # Grab an image
        time_temp=time.time()
        
        def points(keypoints_3d):
            glEnable(GL_POINT_SMOOTH)
            glEnable(GL_BLEND)
            glEnable(GL_FRAMEBUFFER_SRGB)
            glPointSize(10)
            
            glBegin(GL_POINTS)
            glColor3d(1, 1, 1)
            
            for i in range(len(keypoints_3d)):
                glVertex3d(keypoints_3d[i][0]/100, keypoints_3d[i][1]/100, keypoints_3d[i][2]/100)
                #print("JNW",keypoints_3d[i][0])
            glEnd()

        def lines(keypoints_3d):
            glEnable(GL_POINT_SMOOTH)
            glEnable(GL_BLEND)
            glEnable(GL_FRAMEBUFFER_SRGB)
            glPointSize(10)
            glBegin(GL_LINES)
            glColor3d(1, 1, 1)
            
            for i in range(len(keypoints_3d)):
                if(i<5):
                    glVertex3d(keypoints_3d[i][0]/100, keypoints_3d[i][1]/100, keypoints_3d[i][2]/100)
                    glVertex3d(keypoints_3d[i+1][0]/100, keypoints_3d[i+1][1]/100, keypoints_3d[i+1][2]/100)

                #print("JNW",keypoints_3d[i][0])
            glEnd()

            
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                quit()
        glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
        for body in bodies_list:
            points(keypoints_3d)
            lines(keypoints_3d)
            pygame.display.flip()
            pygame.time.wait(10)

enter image description here

I'm sure there are better ways to visualize these points and lines in PyopenGl.

Can someone guide me?

1

There are 1 best solutions below

0
Rabbid76 On BEST ANSWER

You need to update the display once after you have drawn all the geometry, instead of updating it after each geometry. So call pygame.display.flip() after the loop, but not in the loop:

while True:

    # [...]

    # clear display
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
    
    # draw all the geometry 
    for body in bodies_list:
        points(keypoints_3d)
        lines(keypoints_3d)
    
    # update the display
    pygame.display.flip()
    pygame.time.wait(10)