简体   繁体   中英

Using EGL on headless server or virtual console

I'm trying to use EGL in an environment without an X server. For testing purposes, I created a simple program that tries to get the EGL version:

$ cat version.c
#include <stdio.h>

#include <EGL/egl.h>

int main() {
  EGLDisplay eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);

  EGLint major;
  EGLint minor;

  EGLBoolean eglInitialized = eglInitialize(eglDisplay, &major, &minor);

  printf("%d %d %d\n", major, minor, eglInitialized);


  return 0;
}

$ gcc version.c -lEGL

When I run this on a standard Ubuntu machine, it runs just fine and prints 1 4 1 meaning that EGL is version 1.4 and the display was successfully initialized.

To emulate the server environment on which I eventually want to run, I switch to a virtual console with Ctrl + Alt + F1 , but now it fails:

$ ./a.out
libEGL warning: DRI3: xcb_connect failed
libEGL warning: DRI2: xcb_connect failed
libEGL warning: DRI2: xcb_connect failed
0 4196000 0

The same thing happens on the remote server.

I am not an expert here, but I think I know enough to answer this question sufficiently (though by now you have probably solved it long ago). You are trying to use the default display, which is X11 on your system. For headless you probably want to use gbm, assuming you are on a system using a relatively recent Mesa GL library and a kernel (Linux or other) which supports that.

See the Mesa eglinfo demo[1] for an example, and eglkms[2] for an example of rendering. You would want to leave out the bits which set the mode and create and display the frame buffer of course, and you might want to use /dev/dri/renderD128 instead of /dev/dri/card0.

[1] https://cgit.freedesktop.org/mesa/demos/tree/src/egl/opengl/eglinfo.c [2] https://cgit.freedesktop.org/mesa/demos/tree/src/egl/opengl/eglkms.c

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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