【问题标题】:PyOpenGL Glut WindowPyOpenGL 过剩窗口
【发布时间】:2021-07-19 04:59:12
【问题描述】:

所以我最近开始使用 PyOpenGL 的 GLUT 模块,但找不到任何简单的教程(任何链接都将不胜感激),我只想使用 glutCreateWindow('window') 创建一个 glut 窗口,但只要窗口弹出它消失了。我尝试在我的主函数中使用glutMainLoop(),但它只是给出了一个错误。

from OpenGL.GLU import *
from OpenGL.GL import *

glutInit()

def main():
    glutCreateWindow('window')
    glutMainLoop()

if __name__=='__main__':main()

【问题讨论】:

    标签: pyopengl freeglut glutcreatewindow


    【解决方案1】:

    您必须设置glutDisplayFunc 回调。 glut 主循环调用显示回调。

    小例子:

    from OpenGL.GLUT import *
    from OpenGL.GLU import *
    from OpenGL.GL import *
    
    glutInit()
    
    def display():
        glClearColor(1, 0, 0, 0) # red
        glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
    
        # your rendering goes here
        # [...]
    
        glutSwapBuffers()
        glutPostRedisplay()
    
    def main():
        glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA)
        glutCreateWindow('window')
        glutDisplayFunc(display)
        glutMainLoop()
    
    if __name__=='__main__':
        main()
    

    glutInitDisplayMode 设置初始显示模式。 glutSwapBuffers 交换当前窗口蚂蚁的缓冲区,从而更新显示。 glutPostRedisplay 将当前窗口标记为重新显示,因此会导致显示不断重绘,这是动画所必需的。

    另见Immediate mode and legacy OpenGL

    【讨论】:

      猜你喜欢
      • 2012-01-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-03
      • 1970-01-01
      • 2012-08-05
      • 2012-05-28
      • 2020-08-17
      相关资源
      最近更新 更多