u012880255
Azoith
2019-01-23 05:20

opengl中的depth_test不起作用

  • python

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()
  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

0条回答

为你推荐

换一换