示例#1
0
文件: egl.c 项目: mastensg/kubb
void
egl_init(NativeWindowType native_window)
{
    static const EGLint config_attrib_list[] = {
        EGL_RED_SIZE, 8,
        EGL_GREEN_SIZE, 8,
        EGL_BLUE_SIZE, 8,
        EGL_ALPHA_SIZE, 8,
        EGL_NONE
    };
    static const EGLint context_attrib_list[] = {
        EGL_CONTEXT_CLIENT_VERSION, 2,
        EGL_NONE
    };
    EGLConfig config;
    EGLint num_config;

    if(EGL_DEFAULT_DISPLAY == (display = eglGetDisplay(EGL_DEFAULT_DISPLAY)))
        errx(EXIT_FAILURE, "eglGetDisplay: EGL_NO_DISPLAY, can't obtain display");

    if(EGL_FALSE == eglInitialize(display, NULL, NULL))
        errx(EXIT_FAILURE, "eglInitialize: %s", egl_strerror(eglGetError()));

    if(EGL_FALSE == eglChooseConfig(display, config_attrib_list, &config, 1, &num_config))
        errx(EXIT_FAILURE, "eglChooseConfig: %s", egl_strerror(eglGetError()));

    if(EGL_FALSE == eglBindAPI(EGL_OPENGL_ES_API))
        errx(EXIT_FAILURE, "eglBindAPI: %s", egl_strerror(eglGetError()));

    if(EGL_NO_CONTEXT == (context = eglCreateContext(display, config, EGL_NO_CONTEXT, context_attrib_list)))
        errx(EXIT_FAILURE, "eglCreateContext: %s", egl_strerror(eglGetError()));

    if(EGL_NO_SURFACE == (surface = eglCreateWindowSurface(display, config, native_window, NULL)))
        errx(EXIT_FAILURE, "eglCreateWindowSurface: %s", egl_strerror(eglGetError()));

    if(EGL_FALSE == eglMakeCurrent(display, surface, surface, context))
        errx(EXIT_FAILURE, "eglMakeCurrent: %s", egl_strerror(eglGetError()));
}
示例#2
0
void egl_perror(const char *str)
{
        fprintf(stderr, "%s: %s\n", str, egl_strerror(eglGetError()));
}