OpenGL without X using EGL

Hi

Using EGL I implemented an OpenGL off-screen renderer on Linux without X server running.
I was able to find some OpenGL ES and EGL examples and made it work,
but for desktop OpenGL I had no luck…

I checked this blog post

It showed how to initialize EGL and create an OpenGL context using EGL,
but it doesn’t show how to load OpenGL functions where I was stuck
(All EGL initialization and OpenGL context creation looked OK in my renderer) …

I tried GLEW, but it’s strongly tied to GLX/X11. I was not able to build it with EGL.
Tried other ways to load OpenGL :

http://apoorvaj.io/loading-opengl-without-glew.html

This time it built OK, and looked like it loaded OpenGL function symbols correctly
(the function pointers have valid addresses) …
However, the OpenGL functions failed to run in my renderer.
Two specific functions I ran were glCreateShader and glCreateProgram.
They returned 0 (failure) all the time with glError code 0.

Does anyone have a working example of EGL + (desktop) OpenGL using shaders?
Or any other suggestion for loading OpenGL functions running with EGL?
My Nvidia Linux driver version is 361.42.
Would it be helpful to upgrade the driver to a recent version?

Hi
I run into the same situation. Have you found a solution?
Thanks

I’m also experiencing similar problems. Did you guys check for errors occurring during the EGL initialisation (this is not included in the example code from https://devblogs.nvidia.com/parallelforall/egl-eye-opengl-visualization-without-x-server/
). For me, during execution of the following code my program fails as eglGetDisplay(EGL_DEFAULT_DISPLAY) returns EGL_NO_DISPLAY. Anyone also have this problem?

void checkEglErrors()
{
    EGLint err = eglGetError();
    if (EGL_SUCCESS != err)
    {
        std::cerr << "EGL error: " << std::hex << err << std::endl;
        throw std::runtime_error("EGL Error");
    }
}

int main(int argc, char *argv[])
{
    // 1. Initialize EGL
    EGLDisplay eglDpy = eglGetDisplay(EGL_DEFAULT_DISPLAY);
    if (EGL_NO_DISPLAY == eglDpy)
    {
        std::cerr << "eglGetDisplay returned EGL_NO_DISPLAY" << std::endl;
        return 1;
    }

    EGLint major, minor;

    if (eglInitialize(eglDpy, &major, &minor) == EGL_FALSE)
    {
        std::cerr << "Unable to initialize EGL using eglInitialize" << std::endl;
        return 1;
    }

    // 2. Select an appropriate configuration
    EGLint numConfigs;
    EGLConfig eglCfg;

    if (EGL_FALSE == eglChooseConfig(eglDpy, configAttribs, &eglCfg, 1, &numConfigs))
    {
        std::cerr << "eglChooseConfig failed" << std::endl;
        return 1;
    }

     // 3. Create a surface
    EGLSurface eglSurf = eglCreatePbufferSurface(eglDpy, eglCfg, pbufferAttribs);
    if (EGL_NO_SURFACE == eglSurf)
    {
        std::cerr << "Unable to initialize EGLSurface" << std::endl;
        return 1;
    }
    // 4. Bind the API
    if (EGL_FALSE == eglBindAPI(EGL_OPENGL_API)) 
    {
        std::cerr << "Unable to bind EGL API to OpenGL" << std::endl;
        return 1;
    }

    // 5. Create a context and make it current
    EGLContext eglCtx = eglCreateContext(eglDpy, eglCfg, EGL_NO_CONTEXT, NULL);
    if (EGL_NO_CONTEXT == eglCtx)
    {
        std:cerr << "Unable to initialize EGLContext" << std::endl;
        return 1;
    }

    if (EGL_FALSE == eglMakeCurrent(eglDpy, eglSurf, eglSurf, eglCtx))
    {
        std::cerr << "Unable to make EGL context current" << std::endl;
        return 1;
    }

    checkEglErrors();
    // from now on use your OpenGL context

    // 6. Terminate EGL when finished
    eglTerminate(eglDpy);
    return 0;
}

When you use EGL and (desktop)OpenGL with GLEW, you need GLEW 2.0.0 or newer.
And GLEW must be built with

make SYSTEM=linux-egl

Here is my working EGL + OpenGL + GLEW initialize/uninitialize code for off-line rendering(Only render to frame buffer object).
https://github.com/demotomohiro/Reflection-Refraction-less-Ronpa-Raytracing-Renderer/blob/master/src/glcontext_egl.cpp