AnsweredAssumed Answered

eglChooseConfig() succeeds, but eglCreateContext() claims bad config.

Question asked by Thomas Albertine on Oct 22, 2018
Latest reply on Oct 30, 2018 by Bio_TICFSL

I'm having trouble getting EGL to produce an OpenGL context for me. All the functions return no errors except eglCreateContext() which returns EGL_NO_CONTEXT, and eglGetError() produces the code for EGL_BAD_CONFIG. eglChooseConfig() produces no error.

 

I have some experience with OpenGL, but I've never had to create my own context before, so maybe I've missed something important.

 

I looked through the forums for a similar question and found this this post. I was struck by how similar his code looked to mine. He says that it works, but mine does not, and I can't see any meaningful difference.

 

Here's my code, stripping error checking to be concise:

/*
* EGL Initialization
* Creates OpenGl context
*/


/* This part lives in a header */
struct gl_details {
    GLuint vShader;
    GLuint fShader;
    EGLDisplay display;
    EGLConfig config;
    EGLSurface surface;
    EGLContext context;
    EGLNativeDisplayType nDispType;
    EGLNativeWindowType nWinType;
};
struct gl_details glDetails;

/* The rest lives in the .c file */
glDetails->nDispType = fbGetDisplayByIndex(0);
glDetails->display = eglGetDisplay(glDetails->nDispType);

eglInitialize(glDetails->display, NULL, NULL)
eglBindAPI(EGL_OPENGL_ES_API)

/* This is the part where I'm most suspicious. */
static const EGLint fb_attribute_list[] = {
    EGL_RED_SIZE, 5,
    EGL_GREEN_SIZE, 6,
    EGL_BLUE_SIZE, 5,
    EGL_ALPHA_SIZE, 0,
    EGL_SAMPLES, 0,
    EGL_DEPTH_SIZE, 24,
    EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
    EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
    EGL_NONE /* EGL null terminator */
};
EGLint configResults = 0;
eglChooseConfig(glDetails->display, &fb_attribute_list[0], &(glDetails->config), 1, &configResults)

glDetails->nWinType = fbCreateWindow(glDetails->nDispType, 0, 0, g_DsyInfo.fb_W, g_DsyInfo.fb_H);
glDetails->surface = eglCreateWindowSurface(glDetails->display, glDetails->config, glDetails->nWinType, NULL);

EGLint const context_attrib_list[] = {
    EGL_CONTEXT_CLIENT_VERSION, 2,
    EGL_NONE
};
glDetails->context = eglCreateContext(glDetails->display, glDetails->config, EGL_NO_CONTEXT, context_attrib_list);

eglMakeCurrent(glDetails->display, glDetails->surface, glDetails->surface, glDetails->context);

If anyone can see what I've done wrong, or even can tell me how to get better output for debugging, it would be much appreciated.

Outcomes