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_glLoadIdentity)(void);
51 void (*my_glMatrixMode)(GLenum);
52 void (*my_glOrtho)(GLdouble, GLdouble, GLdouble, GLdouble, GLdouble, GLdouble);
53 void (*my_glViewport)(GLint, GLint, GLsizei, GLsizei);
55 #define COMMON_USE_EGL
56 #define COMMON_GL_PREFIX my_
57 #define COMMON_EGL_PREFIX my_
61 resolve_symbols (void)
67 gl_handle = dlopen ("libGL.so", RTLD_LAZY);
68 if (gl_handle == NULL) {
69 fprintf (stderr, "Error: Failed to open libGL.so\n");
73 egl_handle = dlopen ("libEGL.so", RTLD_LAZY);
74 if (egl_handle == NULL) {
75 fprintf (stderr, "Error: Failed to open libEGL.so\n");
82 my_eglBindAPI = dlsym (egl_handle, "eglBindAPI");
85 fprintf (stderr, "Failed to dlsym eglBindAPI: %s\n", error);
89 my_eglChooseConfig = dlsym (egl_handle, "eglChooseConfig");
92 fprintf (stderr, "Failed to dlsym eglChooseConfig: %s\n", error);
96 my_eglCreateContext = dlsym (egl_handle, "eglCreateContext");
99 fprintf (stderr, "Failed to dlsym eglCreateContext: %s\n", error);
103 my_eglCreateWindowSurface = dlsym (egl_handle, "eglCreateWindowSurface");
106 fprintf (stderr, "Failed to dlsym eglCreateWindowSurface: %s\n", error);
110 my_eglGetConfigAttrib = dlsym (egl_handle, "eglGetConfigAttrib");
113 fprintf (stderr, "Failed to dlsym eglGetConfigAttrib: %s\n", error);
117 my_eglGetDisplay = dlsym (egl_handle, "eglGetDisplay");
120 fprintf (stderr, "Failed to dlsym eglGetDisplay: %s\n", error);
124 my_eglInitialize = dlsym (egl_handle, "eglInitialize");
127 fprintf (stderr, "Failed to dlsym eglInitialize: %s\n", error);
131 my_eglMakeCurrent = dlsym (egl_handle, "eglMakeCurrent");
134 fprintf (stderr, "Failed to dlsym eglMakeCurrent: %s\n", error);
138 my_eglSwapBuffers = dlsym (egl_handle, "eglSwapBuffers");
141 fprintf (stderr, "Failed to dlsym eglSwapBuffers: %s\n", error);
145 my_glClear = dlsym (gl_handle, "glClear");
148 fprintf (stderr, "Failed to dlsym glClear: %s\n", error);
152 my_glClearColor = dlsym (gl_handle, "glClearColor");
155 fprintf (stderr, "Failed to dlsym glClearColor: %s\n", error);
159 my_glLoadIdentity = dlsym (gl_handle, "glLoadIdentity");
162 fprintf (stderr, "Failed to dlsym glLoadIdentity: %s\n", error);
166 my_glMatrixMode = dlsym (gl_handle, "glMatrixMode");
169 fprintf (stderr, "Failed to dlsym glMatrixMode: %s\n", error);
173 my_glOrtho = dlsym (gl_handle, "glOrtho");
176 fprintf (stderr, "Failed to dlsym glOrtho: %s\n", error);
180 my_glViewport = dlsym (gl_handle, "glViewport");
183 fprintf (stderr, "Failed to dlsym glViewport: %s\n", error);
197 XVisualInfo *visual_info;
201 dpy = util_x11_init_display ();
203 common_create_egl_context (dpy, EGL_OPENGL_API, &egl_dpy,
204 &ctx, &config, &visual_info);
206 window = util_x11_init_window (dpy, visual_info);
208 surface = my_eglCreateWindowSurface (egl_dpy, config, window, NULL);
210 common_make_current (egl_dpy, ctx, surface);
212 common_handle_events (dpy, egl_dpy, surface);
214 util_x11_fini_window (dpy, window);
216 util_x11_fini_display (dpy);