Azoith 2019-01-23 05:20
浏览 379

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()
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 overleaf中论文编辑,报错`pages' is a missing field, not a string, for entry 4
    • ¥15 vhdl+MODELSIM
    • ¥20 simulink中怎么使用solve函数?
    • ¥30 dspbuilder中使用signalcompiler时报错Error during compilation: Fitter failed,求解决办法
    • ¥15 gwas 分析-数据质控之过滤稀有突变中出现的问题
    • ¥15 没有注册类 (异常来自 HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))
    • ¥15 知识蒸馏实战博客问题
    • ¥15 用PLC设计纸袋糊底机送料系统
    • ¥15 simulink仿真中dtc控制永磁同步电机如何控制开关频率
    • ¥15 用C语言输入方程怎么