在另一台机器上运行的 Python 代码中的 GLUT Warning 和 GLUT Fatal Error
GLUT Warning and GLUT Fatal Error in a Python code that runs in another machine
我必须在以下代码中做一些修改作为作业,但是教授在 class 中显示了代码 运行ning,但即使在安装包后它也没有 运行 在我的 Mac 机器上,错误说要更新我的代码,但是在他的 Windows 机器上也应该 运行,所以理想的是修复错误而不是代码。
def main():
glutInit(sys.argv) #initial the system
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB)
glutInitWindowSize(int(window_width), int(window_hight)) #initial window size
glutInitWindowPosition(100, 100) #initial window position
glutCreateWindow("ICSI 422 Demo") #assign a title for the window
initGL()
# drawpoints() #call funtion drawpoints
# drawlines()
# drawSquares()
glutMainLoop()
当我尝试 运行ning 代码时,它在我的终端上输出:
Python[1547:103885] GLUT Warning: The following is a new check for GLUT 3.0; update your code.
Python[1547:103885] GLUT Fatal Error: redisplay needed for window 1, but no display callback.
正如您所猜到的,我是 OpenGL 的新手,也是 Python 的新手,所以我能做什么?
在使用 glutMainLoop()
启动主循环之前,您需要通过将函数指针传递给 glutDisplayFunc()
来告诉 GLUT 在绘制时调用什么函数。请参阅此处的文档:
https://www.opengl.org/documentation/specs/glut/spec3/node46.html
在 C 中,它看起来像这样:
void myDisplayFunc() {
// gfx fun
}
int main() {
// boring init
glutDisplayFunc(myDisplayFunc);
glutMainLoop();
}
我不确切知道使用 Python 绑定是如何工作的,但这就是导致错误的原因。 GLUT 需要一个函数在需要绘制到屏幕上时调用,因为你没有给它一个它只是退出并退出。
请注意,其他有用的回调以相同的方式定义(参见 glutKeyboardFunc()
和 glutMouseFunc()
)。
我必须在以下代码中做一些修改作为作业,但是教授在 class 中显示了代码 运行ning,但即使在安装包后它也没有 运行 在我的 Mac 机器上,错误说要更新我的代码,但是在他的 Windows 机器上也应该 运行,所以理想的是修复错误而不是代码。
def main():
glutInit(sys.argv) #initial the system
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB)
glutInitWindowSize(int(window_width), int(window_hight)) #initial window size
glutInitWindowPosition(100, 100) #initial window position
glutCreateWindow("ICSI 422 Demo") #assign a title for the window
initGL()
# drawpoints() #call funtion drawpoints
# drawlines()
# drawSquares()
glutMainLoop()
当我尝试 运行ning 代码时,它在我的终端上输出:
Python[1547:103885] GLUT Warning: The following is a new check for GLUT 3.0; update your code.
Python[1547:103885] GLUT Fatal Error: redisplay needed for window 1, but no display callback.
正如您所猜到的,我是 OpenGL 的新手,也是 Python 的新手,所以我能做什么?
在使用 glutMainLoop()
启动主循环之前,您需要通过将函数指针传递给 glutDisplayFunc()
来告诉 GLUT 在绘制时调用什么函数。请参阅此处的文档:
https://www.opengl.org/documentation/specs/glut/spec3/node46.html
在 C 中,它看起来像这样:
void myDisplayFunc() {
// gfx fun
}
int main() {
// boring init
glutDisplayFunc(myDisplayFunc);
glutMainLoop();
}
我不确切知道使用 Python 绑定是如何工作的,但这就是导致错误的原因。 GLUT 需要一个函数在需要绘制到屏幕上时调用,因为你没有给它一个它只是退出并退出。
请注意,其他有用的回调以相同的方式定义(参见 glutKeyboardFunc()
和 glutMouseFunc()
)。