c++ - freeglut 如何探测 X11 服务器是否可用?

标签 c++ opengl freeglut

我有一个程序可以使用 freeglut 以图形方式显示数据,这很好但不是必需的。我经常使用 putty 在家里的 debian 服务器上编辑和编译我的程序,但是当我尝试从 putty 中运行二进制文件时,我收到此消息:

freeglut (./a.out): failed to open display ''

现在我知道,只要稍作调整,我就可以让 cygwin 使用 ssh -X 以某种方式隧道化 X 服务器,但我想要的是简单地检测 freeglut 是否可以渲染到屏幕,如果不能,那就不要打扰了。

我该怎么做?我尝试在 gdb 中对我的程序运行回溯,但没有堆栈,所以我不知道是否有异常或我可以捕获的返回值。

最佳答案

glutInit() :

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/

相关文章:

c++ - 新行转义序列返回到行首

math - 如何根据共享顶点的多个三角形计算法向量?

c++ - OpenGL 文本忽略转义序列

c++ - cairo + freeglut 组合错误

visual-studio-2008 - glutBitmapCharacter() 太慢了,有没有在 OpenGL 程序中使用字体的替代方法?

c++ - 将图像读取为二进制文件

c++ - 列表元素被替换而不是插入

c++ - 在 SSBO 中发送 uvec4 数组

opengl - 如何使用 GLSL 着色器将径向模糊应用于整个场景?

c++ - 设置 OpenGL - 它不会工作