OpenGL EGL eglGetDisplay продолжает возвращать ошибку EGL 0x3008 (EGL_BAD_DISPLAY) - PullRequest
0 голосов
/ 01 апреля 2020

Моя версия Ubuntu 16.04, и я сначала установил mesa-common-dev, libgl1-mesa-dev, libglm-dev, libegl1-mesa-dev. Затем я установил NVIDIA-Linux-x86_64-440.64.run с поддержкой opengl.

Но когда я пытался запустить игрушечный пример, я получаю эту ошибку main: Assertion display != EGL_NO_DISPLAY failed

/* Compile with gcc -g3 -o example example.c -lX11 -lEGL */

#include <assert.h>
#include <stdio.h>
#include <EGL/egl.h>
#include <EGL/eglplatform.h>

void printEGLError();

int main(void) {
  Display* x_display = XOpenDisplay(NULL);
  EGLDisplay display = eglGetDisplay(x_display);
  // EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
  assert(display != EGL_NO_DISPLAY);

  EGLint major, minor;
  eglInitialize(display, &major, &minor);
  char *string = eglQueryString(display, EGL_CLIENT_APIS);
  assert(string);

  printf("%s\n", string);

  return 0;
}

/* Use printEGLError to show a description of the last EGL Error.
  The descriptions are taken from the eglGetError manual */
#define ERROR_DESC(...) fprintf(stderr, "%s\n", __VA_ARGS__); break

void printEGLError() {

  switch(eglGetError()) {

  case(EGL_SUCCESS):
    ERROR_DESC("The last function succeeded without error.");
  case(EGL_NOT_INITIALIZED):
    ERROR_DESC("EGL is not initialized, or could not be initialized, for the specified EGL display connection.");
  case(EGL_BAD_ACCESS):
    ERROR_DESC("EGL cannot access a requested resource (for example a context is bound in another thread).");
  case(EGL_BAD_ALLOC):
    ERROR_DESC("EGL failed to allocate resources for the requested operation.");
  case(EGL_BAD_ATTRIBUTE):
    ERROR_DESC("An unrecognized attribute or attribute value was passed in the attribute list.");
  case(EGL_BAD_CONTEXT):
    ERROR_DESC("An EGLContext argument does not name a valid EGL rendering context.");
  case(EGL_BAD_CONFIG):
    ERROR_DESC("An EGLConfig argument does not name a valid EGL frame buffer configuration.");
  case(EGL_BAD_CURRENT_SURFACE):
    ERROR_DESC("The current surface of the calling thread is a window, pixel buffer or pixmap that is no longer valid.");
  case(EGL_BAD_DISPLAY):
    ERROR_DESC("An EGLDisplay argument does not name a valid EGL display connection.");
  case(EGL_BAD_SURFACE):
    ERROR_DESC("An EGLSurface argument does not name a valid surface (window, pixel buffer or pixmap) configured for GL rendering.");
  case(EGL_BAD_MATCH):
    ERROR_DESC("Arguments are inconsistent (for example, a valid context requires buffers not supplied by a valid surface).");
  case(EGL_BAD_PARAMETER):
    ERROR_DESC("One or more argument values are invalid.");
  case(EGL_BAD_NATIVE_PIXMAP):
    ERROR_DESC("A NativePixmapType argument does not refer to a valid native pixmap.");
  case(EGL_BAD_NATIVE_WINDOW):
    ERROR_DESC("A NativeWindowType argument does not refer to a valid native window.");
  case(EGL_CONTEXT_LOST):
    ERROR_DESC("A power management event has occurred. The application must destroy all contexts and reinitialise OpenGL ES state and objects to continue rendering. ");
  }
}

Дополнительная информация: моя видеокарта Titan Xp и я пытался запустить sudo servide lightdm stop и удалил все возможные программы удаленного рабочего стола. Но проблема все еще существует. Кто-нибудь может помочь?

1 Ответ

0 голосов
/ 01 апреля 2020

Для тех, кто может быть смущен этой проблемой, просто unset DISPLAY. Это может спасти ваш день.

...