【问题标题】:PyOpenGL GLUT error NULL display callback not permittedPyOpenGL GLUT错误NULL显示回调不允许
【发布时间】:2022-01-28 00:34:41
【问题描述】:

我正在尝试在一个名为 Window 的类中通过 glut 创建一个窗口。但是,当我运行函数 display(self) 时,我得到了这个错误:

freeglut (foo):程序中的致命错误。 GLUT 3.0+ 或 freeglut 2.0.1+ 中不允许 NULL 显示回调

当我在 main.py 中使用 glut 时,我没有收到此错误,我不明白为什么。任何帮助将不胜感激。

这是我的 main.py :

def main():
    window = Window(100, 500, 0, 0, "pipo")
    window.display()


if __name__ == '__main__':
    main()

我的窗口类:

class Window:
    def __init__(self, height, width, x, y, title):
        self.height = height
        self.width = width
        self.x = x
        self.y = y
        self.title = title
        self.initWindow()

    def initWindow(self):
        glutInit()  # Initialize a glut instance which will allow us to customize our window
        glutInitDisplayMode(GLUT_RGBA)  # Set the display mode to be colored
        glutInitWindowSize(self.width, self.height)  # Set the width and height of your window
        glutInitWindowPosition(self.x, self.y)  # Set the position at which this windows should appear
        wind = glutCreateWindow(self.title)  # Give your window a title

    def clear(self):
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

    def display(self):
        glutDisplayFunc(self.clear())  # Tell OpenGL to call the showScreen method continuously
        glutIdleFunc(self.clear())  # Draw any graphics or shapes in the showScreen function at all times
        glutMainLoop()

【问题讨论】:

    标签: python glut pyopengl freeglut


    【解决方案1】:

    self.clear() 是一个方法调用。您必须将方法对象传递给函数而不是调用方法(self.clear 而不是 self.clear()):

    glutDisplayFunc(self.clear())
    glutIdleFunc(self.clear())

    glutDisplayFunc(self.clear)
    glutIdleFunc(self.clear) 
    

    请注意,当您执行glutDisplayFunc(self.clear()) 时,会调用clear 方法并将clear method( None) 的返回值传递给函数。

    【讨论】:

      猜你喜欢
      • 2013-05-05
      • 2019-11-25
      • 2021-05-02
      • 2014-03-21
      • 2017-02-27
      • 1970-01-01
      • 2015-04-23
      • 2016-06-30
      • 2013-01-12
      相关资源
      最近更新 更多