| 16 | } |
| 17 | |
| 18 | static void create_context(void) { |
| 19 | EGLint num_config; |
| 20 | EGLContext g_egl_ctx; |
| 21 | EGLDisplay g_egl_dpy; |
| 22 | EGLConfig g_config; |
| 23 | |
| 24 | static const EGLint attribute_list[] = { |
| 25 | EGL_RED_SIZE, 8, |
| 26 | EGL_GREEN_SIZE, 8, |
| 27 | EGL_BLUE_SIZE, 8, |
| 28 | EGL_ALPHA_SIZE, 8, |
| 29 | EGL_SURFACE_TYPE, EGL_WINDOW_BIT, |
| 30 | EGL_NONE |
| 31 | }; |
| 32 | |
| 33 | static const EGLint context_attributes[] = { |
| 34 | EGL_CONTEXT_CLIENT_VERSION, 2, |
| 35 | EGL_NONE |
| 36 | }; |
| 37 | |
| 38 | g_egl_dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY); |
| 39 | if (!g_egl_dpy) |
| 40 | die("failed to create display"); |
| 41 | |
| 42 | if (!eglInitialize(g_egl_dpy, NULL, NULL)) |
| 43 | die("failed to initialize egl"); |
| 44 | |
| 45 | if (!eglChooseConfig(g_egl_dpy, attribute_list, &g_config, 1, &num_config)) |
| 46 | die("failed to choose config"); |
| 47 | |
| 48 | g_egl_ctx = eglCreateContext(g_egl_dpy, g_config, EGL_NO_CONTEXT, context_attributes); |
| 49 | if (!g_egl_ctx) |
| 50 | die("failed to create context"); |
| 51 | |
| 52 | EGLNativeWindowType dummyWindow; |
| 53 | EGLSurface surface = eglCreateWindowSurface(g_egl_dpy, g_config, dummyWindow, NULL); |
| 54 | if (!surface) |
| 55 | die("failed to create window surface"); |
| 56 | |
| 57 | if (!eglMakeCurrent(g_egl_dpy, surface, surface, g_egl_ctx)) |
| 58 | die("failed to activate context"); |
| 59 | } |
| 60 | |
| 61 | int main(int argc, char *argv[]) { |
| 62 | unsigned i; |