Skip to content

Instantly share code, notes, and snippets.

@vklachkov
Created June 22, 2021 15:11
Show Gist options
  • Save vklachkov/c24a99c82dbe518172d4693699186049 to your computer and use it in GitHub Desktop.
Save vklachkov/c24a99c82dbe518172d4693699186049 to your computer and use it in GitHub Desktop.
EGLint major, minor, count, n, size, w, h, format;
EGLDisplay display = nullptr;
EGLSurface surface;
EGLContext context;
EGLConfig *configs;
EGLConfig config = nullptr;
EGLBoolean result = EGL_FALSE;
static const EGLint config_attribs[] = {
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
EGL_RED_SIZE, 8,
EGL_GREEN_SIZE, 8,
EGL_BLUE_SIZE, 8,
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
EGL_NONE
};
static const EGLint context_attribs[] = {
EGL_CONTEXT_CLIENT_VERSION, 2,
EGL_NONE
};
display = eglGetDisplay((EGLNativeDisplayType) display);
if (display == EGL_NO_DISPLAY) {
// TODO
return -1;
}
result = eglInitialize(display, &major, &minor);
if (result != EGL_TRUE) {
// TODO
return -1;
}
LOGI("EGL successfuly initialized!");
LOGI("EGL major: %d, minor %d", major, minor);
eglGetConfigs(display, nullptr, 0, &count);
printf("EGL has %d configs", count);
configs = new EGLConfig[count]();
eglChooseConfig(display, config_attribs, configs, count, &n);
for (int i = 0; i < n; i++) {
eglGetConfigAttrib(display, configs[i], EGL_BUFFER_SIZE, &size);
eglGetConfigAttrib(display, configs[i], EGL_RED_SIZE, &size);
LOGD("Buffer size for config %d is %d", i, size);
LOGD("Red size for config %d is %d", i, size);
// just choose the first one
config = configs[i];
break;
}
eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &format);
surface = eglCreateWindowSurface(display, config, engine->app->window, nullptr);
context = eglCreateContext(display, config, EGL_NO_CONTEXT, context_attribs);
result = eglMakeCurrent(display, surface, surface, context);
if (result == EGL_FALSE) {
// TODO
return -1;
}
GlInfo();
glEnable(GL_CULL_FACE);
glDisable(GL_DEPTH_TEST);
eglQuerySurface(display, surface, EGL_WIDTH, &w);
eglQuerySurface(display, surface, EGL_HEIGHT, &h);
engine->display = display;
engine->context = context;
engine->surface = surface;
engine->width = w;
engine->height = h;
engine->state.angle = 0;
return 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment