gpt4 book ai didi

c++ - 使用无屏幕创建 OpenGL 上下文

转载 作者:太空宇宙 更新时间:2023-11-04 10:57:39 26 4
gpt4 key购买 nike

我正在尝试在 debian 服务器上使用 glx 创建一个 opengl 上下文。问题是我无法显示,似乎是因为没有 X 服务器在运行,我无法使用 sudo startx 启动 X 服务器,因为它说没有屏幕。

服务器不在现场,无法在其上添加显示器,我需要制作一个可以在其上运行并渲染事物和其他内容的 opengl 应用程序。

这是我当前的 C++ 测试代码:

#include <cstdio>
#include <X11/Xutil.h>
#include <GL/gl.h>
#include <GL/glx.h>

typedef GLXContext (*glXCreateContextAttribsARBProc) (Display*, GLXFBConfig, GLXContext, Bool, const int*);
typedef Bool (*glXMakeContextCurrentARBProc) (Display*, GLXDrawable, GLXDrawable, GLXContext);
static glXCreateContextAttribsARBProc glXCreateContextAttribsARB = NULL;
static glxMakeContextCurrentARBProc glxMakeContextCurrentARB = NULL;

int main(){
printf("tacos\n");
glXCreateContextAttribsARB = (glXCreateContextAttribsARBProc) glXGetProcAddressARB((const GLubyte*) "glXCreateContextAttribsARB");
glXMakeContextCurrentARB = (glXMakeContextCurrentARBProc) glXGetProcAddressARB((const GLubyte*) "glXMakeContextCurrent");

[ ... ] // Check if the two funcs are null, they are not when I run the program.

const char* display_name = NULL;
Display* display = XOpenDisplay(display_name);
if (display == NULL){
printf("failed to open display\n"); // outputs this and ends program
return 0;
}

printf("Great Success\n"); // does not get this far ^
return 0;
}

我检查 X 服务器是否正在运行:

if ! xset q &>/dev/null; then
echo "No X server at \$DISPLAY [$DISPLAY]" >&2;
fi

输出如下:

No X server at $DISPLAY []

这让我认为 $DISPLAY var 未设置,但我不知道如何检查它是否已设置。

然后我运行“sudo startx”并得到以下信息:

Fatal server error:
(EE) no screens found(EE)

最佳答案

嗯,GLX 是 X11 OpenGL 传输协议(protocol)。所以你绝对需要一个运行的 X 服务器(你在场外位置有可用的 GPU 吗?)。

如果没有连接监视器,默认配置的 Xorg 服务器的更高版本将拒绝启动。但是,使用位于/etc/X11 中的正确 xorg.conf 和正确的命令行选项,您甚至可以诱导服务器启动。然而,您要么必须启动一个重定向复合管理器,要么重写您的 OpenGL 程序以使用帧缓冲区对象,否则您将无法获得要绘制的帧缓冲区(我强烈建议使用帧缓冲区对象路线)。

关于c++ - 使用无屏幕创建 OpenGL 上下文,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28254097/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com