我有一个程序可以使用 freeglut
以图形方式显示数据,这很好但不是必需的。我经常使用 putty
在家里的 debian
服务器上编辑和编译我的程序,但是当我尝试从 putty
中运行二进制文件时,我收到此消息:
freeglut (./a.out): failed to open display ''
现在我知道,只要稍作调整,我就可以让 cygwin 使用 ssh -X
以某种方式隧道化 X 服务器,但我想要的是简单地检测 freeglut 是否可以渲染到屏幕,如果不能,那就不要打扰了。
我该怎么做?我尝试在 gdb
中对我的程序运行回溯,但没有堆栈,所以我不知道是否有异常或我可以捕获的返回值。
最佳答案
glutInit will initialize the GLUT library and negotiate a session with the window system. During this process, glutInit may cause the termination of the GLUT program with an error message to the user if GLUT cannot be properly initialized. Examples of this situation include the failure to connect to the window system, the lack of window system support for OpenGL, and invalid command line options.
所以,不,您无法真正使用 GLUT 处理丢失的 X 服务器。缺少一些讨厌的黑客攻击,例如父看门狗进程或以某种方式 Hook exit()
。
关于c++ - freeglut 如何探测 X11 服务器是否可用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25348858/