This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How to get a SRGB default framebuffer in egl

Hello again!

I'm following a tutorial on (desktop) OpenGL 3.3 about gamma correction.

Basically to gain automatic gamma-corrected colors on the DESKTOP opengl we have to do:

1) Use the SRGBA texture format.

2) Use glEnable(GL_FRAMEBUFFER_SRGB) + at window gl context creation use a SRGB default framebuffer (e.g. GLFW_SRGB or equivalent depending on the library we're using).

Now I've read that this feature is available in OpenGLES3 too. However I got some problem with point 2 above.

-> glEnable(GL_FRAMEBUFFER_SRGB) does not seem to be present (well, this is more an OpenGLES3 question, rather then something related to the emulator).

-> To get a SRGB default framebuffer I've tried using the following code:

/* EGL Configuration */
EGLint aEGLAttributes[] = {
    EGL_RED_SIZE, 8,
    EGL_GREEN_SIZE, 8,
    EGL_BLUE_SIZE, 8,
    //EGL_DEPTH_SIZE, 24,
    EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
    EGL_COLORSPACE,  EGL_COLORSPACE_sRGB,   // New, but crashes the application...
    //EGL_GL_COLORSPACE_KHR, EGL_KHR_gl_colorspace,   // New, but crashes the application...
    EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT | EGL_OPENGL_ES3_BIT_KHR,
    EGL_NONE
};
EGLint aEGLContextAttributes[] = {
    EGL_CONTEXT_CLIENT_VERSION, 3,  // 2 = ES2, 3 = ES3
    EGL_NONE
};
EGLConfig    aEGLConfigs[1];
EGLint   cEGLConfigs;

#ifdef _WIN32

MSG sMessage;

#else

Colormap colormap;
XVisualInfo *pVisual;
XEvent e;

#endif

/* EGL Init */

#ifdef _WIN32

hDisplay = EGL_DEFAULT_DISPLAY;

#else

hDisplay = XOpenDisplay(NULL);
if (!hDisplay) {
    printf("Could not open display\n");
    exit(-1);
}

#endif

sEGLDisplay = EGL_CHECK(eglGetDisplay(hDisplay));
EGL_CHECK(eglInitialize(sEGLDisplay, NULL, NULL));
EGL_CHECK(eglChooseConfig(sEGLDisplay, aEGLAttributes, aEGLConfigs, 1, &cEGLConfigs));    // (*)
if (cEGLConfigs == 0) {
    printf("No EGL configurations were returned.\n");
    exit(-1);
}

#ifdef _WIN32

hWindow = create_window(uiWidth, uiHeight);

#else

hWindow = create_window("OpenGL ES 3.0 Texture Array Example", uiWidth,
    uiHeight, hDisplay, sEGLDisplay, aEGLConfigs[0], &colormap, &pVisual);

#endif

sEGLSurface = EGL_CHECK(eglCreateWindowSurface(sEGLDisplay, aEGLConfigs[0], (EGLNativeWindowType)hWindow, NULL));
if (sEGLSurface == EGL_NO_SURFACE) {
    printf("Failed to create EGL surface.\n");
    exit(-1);
}
sEGLContext = EGL_CHECK(eglCreateContext(sEGLDisplay, aEGLConfigs[0], EGL_NO_CONTEXT, aEGLContextAttributes));
if (sEGLContext == EGL_NO_CONTEXT) {
    printf("Failed to create EGL context.\n");
    exit(-1);
}
EGL_CHECK(eglMakeCurrent(sEGLDisplay, sEGLSurface, sEGLSurface, sEGLContext));

When I do so the program crashes with a:

eglGetError() = 12292 (0x00003004) at line (maked with (*) above):

EGL_CHECK(eglChooseConfig(sEGLDisplay, aEGLAttributes, aEGLConfigs, 1, &cEGLConfigs));    // (*)


Any hint ?