Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I have been trying to set up an EGL session with a window that I created using XCB. I am not having much success. I keep getting the error: An EGLDisplay argument does not name a valid EGL display connection

Is it even possible to use XCB with EGL/GLES2? I was using XLib before but i was not a big fan of their error handling.

void pretty_print_egl_check(int do_assert_on_failure = 1, const char *message = "");

void create_display()
{
EGLint numConfigs;

EGLint configAttribList[] =
{
    EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
    EGL_RED_SIZE,       8,
    EGL_GREEN_SIZE,     8,
    EGL_BLUE_SIZE,      8,
    EGL_ALPHA_SIZE,     8,
    EGL_DEPTH_SIZE,     24,

    EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
    EGL_NONE, EGL_NONE
};

EGLint contextAttribs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE};


// Initialize X Windows
_display = xcb_connect(NULL,NULL);

if(xcb_connection_has_error(_display))
{
    xcb_disconnect(_display);
    printf("Could not connect to X11 display.\n");

}

assert(NULL != _display);

_eglDisplay = eglGetDisplay ((Display *)_display);
pretty_print_egl_check(true,"eglGetDisplay call");

// Initialize EGL.
eglInitialize( _eglDisplay, NULL, NULL );
pretty_print_egl_check(true,"eglInitialize call");
}


void pretty_print_egl_check(int do_assert_on_failure = 1, const char *message = "")
{
    int error = eglGetError();
    const char *egl_success_string                  = "The last function succeeded without error." ;
    const char *egl_not_initialized_string          = "EGL is not initialized, or could not be initialized, for the specified EGL display connection. " ;
    const char *egl_bad_access_string               = "EGL cannot access a requested resource (for example a context is bound in another thread). " ;
    const char *egl_bad_alloc_string                = "EGL failed to allocate resources for the requested operation.";
    const char *egl_bad_attribute_string            = "An unrecognized attribute or attribute value was passed in the attribute list. ";
    const char *egl_bad_context_string              = "An EGLContext argument does not name a valid EGL rendering context. ";
    const char *egl_bad_config_string               = "An EGLConfig argument does not name a valid EGL frame buffer configuration. ";
    const char *egl_bad_current_surface_string      = "The current surface of the calling thread is a window, pixel buffer or pixmap that is no longer valid. " ;
    const char *egl_bad_display_string              = "An EGLDisplay argument does not name a valid EGL display connection.";
    const char *egl_bad_surface_string              = "An EGLSurface argument does not name a valid surface (window, pixel buffer or pixmap) configured for GL rendering. ";
    const char *egl_bad_match_string                = "Arguments are inconsistent (for example, a valid context requires buffers not supplied by a valid surface). ";
    const char *egl_bad_parameter_string            = "One or more argument values are invalid.";
    const char *egl_bad_native_pixmap_string        = "A NativePixmapType argument does not refer to a valid native pixmap. ";
    const char *egl_bad_native_window_string        = "A NativeWindowType argument does not refer to a valid native window.";
    const char *egl_context_lost_string     = "A power management event has occurred. The application must destroy all contexts and reinitialise OpenGL ES state and objects to continue rendering. ";


    switch (error)
    {

            case EGL_SUCCESS:
                    printf("%s:%s",message,egl_success_string);
                    break;
            case EGL_NOT_INITIALIZED:
                    printf("%s:%s",message,egl_not_initialized_string);
                    break;
            case EGL_BAD_ACCESS:
                    printf("%s:%s",message,egl_bad_access_string);
                    break;
            case EGL_BAD_ALLOC:
                    printf("%s:%s",message,egl_bad_alloc_string);
                    break;
            case EGL_BAD_ATTRIBUTE:
                    printf("%s:%s",message,egl_bad_attribute_string);
                    break;
            case EGL_BAD_CONTEXT:
                    printf("%s:%s",message,egl_bad_context_string);
                    break;
            case EGL_BAD_CONFIG:
                    printf("%s:%s",message,egl_bad_config_string);
                    break;
            case EGL_BAD_CURRENT_SURFACE:
                    printf("%s:%s",message,egl_bad_current_surface_string);
                    break;
            case EGL_BAD_DISPLAY:
                    printf("%s:%s",message,egl_bad_display_string);
                    break;
            case EGL_BAD_SURFACE:
                    printf("%s:%s",message,egl_bad_surface_string);
                    break;
            case EGL_BAD_MATCH:
                    printf("%s:%s",message,egl_bad_match_string);
                    break;
            case EGL_BAD_PARAMETER:
                    printf("%s:%s",message,egl_bad_parameter_string);
                    break;
            case EGL_BAD_NATIVE_PIXMAP:
                    printf("%s:%s",message,egl_bad_native_pixmap_string);
                    break;
            case EGL_BAD_NATIVE_WINDOW:
                    printf("%s:%s",message,egl_bad_native_window_string);
                    break;
            case EGL_CONTEXT_LOST:
                    printf("%s:%s",message,egl_context_lost_string);
                    break;
            default:
                    printf("%s:%s",message,"Unknown EGL error");
                    break;
    }
    printf("\n");
    if (do_assert_on_failure)
    {
            assert(error == EGL_SUCCESS);
    }
}
share|improve this question
add comment

closed as off-topic by Byte56 Apr 7 at 15:20

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions about debugging a problem in your project must present a concise selection of code and context so as to allow a reader to diagnose the issue without needing to read all of your code or to engage in extensive back-and-forth dialog. For more information, see this meta thread." – Byte56
If this question can be reworded to fit the rules in the help center, please edit the question.

2 Answers

I do not know why, but this works for me:

_eglDisplay = eglGetDisplay ((EGLNativeDisplayType)NULL);

I found it by chance, and everything works fine except that eglQueryString() return EGL_BAD_DISPLAY.

I hope this helps.

Anyone know more about this?

share|improve this answer
add comment

I'm not sure how to get a specific xcb_connection_t, but eglGetDisplay(EGL_DEFAULT_DISPLAY) works to get the "default one". Since I generally just have one, that works for me.

share|improve this answer
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.