opengl中的depth_test不起作用

linux上用python写了个简单的程序,
画了红绿蓝三个方块,但是发现启用了深度测试之后还是按绘制顺序遮挡的,不知道哪错了
初学者,请大佬们指教,谢谢了

def drawImage():
    glEnable(GL_DEPTH_TEST)
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

    glColor3f(1, 0, 0)
    glBegin(GL_POLYGON)
    glVertex3f(0.1,0.1,0.5)
    glVertex3f(0.1,0.7,0.5)
    glVertex3f(0.7, 0.7, 0.5)
    glVertex3f(0.7, 0.1, 0.5)
    glEnd()

    glColor3f(0, 1, 0)
    glBegin(GL_POLYGON)
    glVertex3f(0.3,0.3,0.8)
    glVertex3f(0.3,0.9,0.8)
    glVertex3f(0.9, 0.9, 0.8)
    glVertex3f(0.9, 0.3, 0.8)
    glEnd()

    glColor3f(0, 0, 1)
    glBegin(GL_POLYGON)
    glVertex3f(0.5,0.5,0.3)
    glVertex3f(0.5,1.0,0.3)
    glVertex3f(1.0, 1.0, 0.3)
    glVertex3f(1.0, 0.5, 0.3)
    glEnd()

    glFlush()


glutInit()
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA)
glutInitWindowPosition(0, 0)
glutInitWindowSize(400, 400)
glutCreateWindow(b"show model")
glutDisplayFunc(drawImage)
glutIdleFunc(drawImage)
glutMainLoop()
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!