【发布时间】: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