繁体   English   中英

使OpenGL上下文没有屏幕

[英]Make OpenGL context with No screens

我正在尝试在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 Server是否与此一起运行:

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

输出以下内容:

No X server at $DISPLAY []

这使我认为未设置$ DISPLAY变量,尽管我不知道如何检查它是否已设置。

然后,我运行了“ sudo startx”并得到了以下内容:

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

好吧,GLX是X11 OpenGL传输协议。 因此,您绝对需要运行X服务器(您是否可以在异地使用GPU?)。

如果未连接任何监视器,则默认配置下的Xorg服务器的更高版本将拒绝启动。 但是,使用/ etc / X11中正确的xorg.conf并使用正确的命令行选项,您甚至可以哄骗服务器启动。 但是,您将不得不启动重定向复合管理器或重写OpenGL程序以使用帧缓冲区对象,否则您将无法绘制帧缓冲区(我强烈建议您使用帧缓冲区对象路由)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM