1 /* Copyright © 2013, Intel Corporation
3 * Permission is hereby granted, free of charge, to any person obtaining a copy
4 * of this software and associated documentation files (the "Software"), to deal
5 * in the Software without restriction, including without limitation the rights
6 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 * copies of the Software, and to permit persons to whom the Software is
8 * furnished to do so, subject to the following conditions:
10 * The above copyright notice and this permission notice shall be included in
11 * all copies or substantial portions of the Software.
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 /* Perform some simple drawing via OpenGL as follows:
24 * 1. Using EGL to construct an OpenGL context
25 * 2. By using dlopen to dynamically load libGL.so and libEGL.so
26 * 3. By using dlsym to lookup OpenGL functions
29 #define GL_GLEXT_PROTOTYPES
39 EGLBoolean (*my_eglBindAPI)(EGLenum);
40 EGLBoolean (*my_eglChooseConfig)(EGLDisplay, EGLint const *, EGLConfig *, EGLint, EGLint *);
41 EGLContext (*my_eglCreateContext)(EGLDisplay, EGLConfig, EGLContext, EGLint const *);
42 EGLSurface (*my_eglCreateWindowSurface)(EGLDisplay, EGLConfig, NativeWindowType, EGLint const *);
43 EGLBoolean (*my_eglGetConfigAttrib)(EGLDisplay, EGLConfig, EGLint, EGLint *);
44 EGLDisplay (*my_eglGetDisplay)(NativeDisplayType);
45 EGLBoolean (*my_eglInitialize)(EGLDisplay, EGLint *, EGLint *);
46 EGLBoolean (*my_eglMakeCurrent)(EGLDisplay, EGLSurface, EGLSurface, EGLContext);
47 EGLBoolean (*my_eglSwapBuffers)(EGLDisplay, EGLSurface);
48 void (*my_glClear)(GLbitfield);
49 void (*my_glClearColor)(GLclampf, GLclampf, GLclampf, GLclampf);
50 void (*my_glViewport)(GLint, GLint, GLsizei, GLsizei);
52 #define COMMON_USE_EGL
53 #define COMMON_GL_PREFIX my_
54 #define COMMON_EGL_PREFIX my_
58 resolve_symbols (void)
64 gl_handle = dlopen ("libGL.so", RTLD_LAZY);
65 if (gl_handle == NULL) {
66 fprintf (stderr, "Error: Failed to open libGL.so\n");
70 egl_handle = dlopen ("libEGL.so", RTLD_LAZY);
71 if (egl_handle == NULL) {
72 fprintf (stderr, "Error: Failed to open libEGL.so\n");
79 my_eglBindAPI = dlsym (egl_handle, "eglBindAPI");
82 fprintf (stderr, "Failed to dlsym eglBindAPI: %s\n", error);
86 my_eglChooseConfig = dlsym (egl_handle, "eglChooseConfig");
89 fprintf (stderr, "Failed to dlsym eglChooseConfig: %s\n", error);
93 my_eglCreateContext = dlsym (egl_handle, "eglCreateContext");
96 fprintf (stderr, "Failed to dlsym eglCreateContext: %s\n", error);
100 my_eglCreateWindowSurface = dlsym (egl_handle, "eglCreateWindowSurface");
103 fprintf (stderr, "Failed to dlsym eglCreateWindowSurface: %s\n", error);
107 my_eglGetConfigAttrib = dlsym (egl_handle, "eglGetConfigAttrib");
110 fprintf (stderr, "Failed to dlsym eglGetConfigAttrib: %s\n", error);
114 my_eglGetDisplay = dlsym (egl_handle, "eglGetDisplay");
117 fprintf (stderr, "Failed to dlsym eglGetDisplay: %s\n", error);
121 my_eglInitialize = dlsym (egl_handle, "eglInitialize");
124 fprintf (stderr, "Failed to dlsym eglInitialize: %s\n", error);
128 my_eglMakeCurrent = dlsym (egl_handle, "eglMakeCurrent");
131 fprintf (stderr, "Failed to dlsym eglMakeCurrent: %s\n", error);
135 my_eglSwapBuffers = dlsym (egl_handle, "eglSwapBuffers");
138 fprintf (stderr, "Failed to dlsym eglSwapBuffers: %s\n", error);
142 my_glClear = dlsym (gl_handle, "glClear");
145 fprintf (stderr, "Failed to dlsym glClear: %s\n", error);
149 my_glClearColor = dlsym (gl_handle, "glClearColor");
152 fprintf (stderr, "Failed to dlsym glClearColor: %s\n", error);
156 my_glViewport = dlsym (gl_handle, "glViewport");
159 fprintf (stderr, "Failed to dlsym glViewport: %s\n", error);
173 XVisualInfo *visual_info;
177 dpy = util_x11_init_display ();
179 common_create_egl_context (dpy, EGL_OPENGL_API, &egl_dpy,
180 &ctx, &config, &visual_info);
182 window = util_x11_init_window (dpy, visual_info);
184 surface = my_eglCreateWindowSurface (egl_dpy, config, window, NULL);
186 common_make_current (egl_dpy, ctx, surface);
188 common_handle_events (dpy, egl_dpy, surface);
190 util_x11_fini_window (dpy, window);
192 util_x11_fini_display (dpy);