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
26 * 3. By using eglGetProcAddress 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 void * (*my_eglGetProcAddress)(char const *);
46 EGLBoolean (*my_eglInitialize)(EGLDisplay, EGLint *, EGLint *);
47 EGLBoolean (*my_eglMakeCurrent)(EGLDisplay, EGLSurface, EGLSurface, EGLContext);
48 EGLBoolean (*my_eglSwapBuffers)(EGLDisplay, EGLSurface);
50 /* The OpenGL header files give typedefs for the types of all
51 * functions provided by etensisons. Here, though, we're using
52 * glxGetProcAddress to lookup core functions, so we provide our own
54 typedef void (*FIPS_GLCLEAR_FN)(GLbitfield);
55 FIPS_GLCLEAR_FN my_glClear;
57 typedef void (*FIPS_GLCLEARCOLOR_FN)(GLclampf, GLclampf, GLclampf, GLclampf);
58 FIPS_GLCLEARCOLOR_FN my_glClearColor;
60 typedef void (*FIPS_GLLOADIDENTITY_FN)(void);
61 FIPS_GLLOADIDENTITY_FN my_glLoadIdentity;
63 typedef void (*FIPS_GLMATRIXMODE_FN)(GLenum);
64 FIPS_GLMATRIXMODE_FN my_glMatrixMode;
66 typedef void (*FIPS_GLORTHO_FN)(GLdouble, GLdouble, GLdouble, GLdouble, GLdouble, GLdouble);
67 FIPS_GLORTHO_FN my_glOrtho;
69 typedef void (*FIPS_GLVIEWPORT_FN)(GLint, GLint, GLsizei, GLsizei);
70 FIPS_GLVIEWPORT_FN my_glViewport;
72 #define COMMON_USE_EGL
73 #define COMMON_GL_PREFIX my_
74 #define COMMON_EGL_PREFIX my_
78 resolve_symbols (void)
80 void *egl_handle, *gl_handle;
83 egl_handle = dlopen ("libEGL.so", RTLD_LAZY);
84 if (egl_handle == NULL) {
85 fprintf (stderr, "Error: Failed to open libEGL.so\n");
89 gl_handle = dlopen ("libGL.so", RTLD_LAZY);
90 if (gl_handle == NULL) {
91 fprintf (stderr, "Error: Failed to open libGL.so\n");
98 my_eglBindAPI = dlsym (egl_handle, "eglBindAPI");
101 fprintf (stderr, "Failed to dlsym eglBindAPI: %s\n", error);
105 my_eglChooseConfig = dlsym (egl_handle, "eglChooseConfig");
108 fprintf (stderr, "Failed to dlsym eglChooseConfig: %s\n", error);
112 my_eglCreateContext = dlsym (egl_handle, "eglCreateContext");
115 fprintf (stderr, "Failed to dlsym eglCreateContext: %s\n", error);
119 my_eglCreateWindowSurface = dlsym (egl_handle, "eglCreateWindowSurface");
122 fprintf (stderr, "Failed to dlsym eglCreateWindowSurface: %s\n", error);
126 my_eglGetConfigAttrib = dlsym (egl_handle, "eglGetConfigAttrib");
129 fprintf (stderr, "Failed to dlsym eglGetConfigAttrib: %s\n", error);
133 my_eglGetDisplay = dlsym (egl_handle, "eglGetDisplay");
136 fprintf (stderr, "Failed to dlsym eglGetDisplay: %s\n", error);
140 my_eglGetProcAddress = dlsym (egl_handle, "eglGetProcAddress");
143 fprintf (stderr, "Failed to dlsym eglGetProcAddress: %s\n", error);
147 my_eglInitialize = dlsym (egl_handle, "eglInitialize");
150 fprintf (stderr, "Failed to dlsym eglInitialize: %s\n", error);
154 my_eglMakeCurrent = dlsym (egl_handle, "eglMakeCurrent");
157 fprintf (stderr, "Failed to dlsym eglMakeCurrent: %s\n", error);
161 my_eglSwapBuffers = dlsym (egl_handle, "eglSwapBuffers");
164 fprintf (stderr, "Failed to dlsym eglSwapBuffers: %s\n", error);
168 my_glClear = (FIPS_GLCLEAR_FN) my_eglGetProcAddress ("glClear");
169 if (my_glClear == NULL) {
170 fprintf (stderr, "Failed to eglGetProcAddress glClear\n");
174 my_glClearColor = (FIPS_GLCLEARCOLOR_FN) my_eglGetProcAddress ("glClearColor");
175 if (my_glClearColor == NULL) {
176 fprintf (stderr, "Failed to eglGetProcAddress glClearColor\n");
180 my_glLoadIdentity = (FIPS_GLLOADIDENTITY_FN) my_eglGetProcAddress ("glLoadIdentity");
181 if (my_glLoadIdentity == NULL) {
182 fprintf (stderr, "Failed to eglGetProcAddress glLoadIdentity\n");
186 my_glMatrixMode = (FIPS_GLMATRIXMODE_FN) my_eglGetProcAddress ("glMatrixMode");
187 if (my_glMatrixMode == NULL) {
188 fprintf (stderr, "Failed to eglGetProcAddress glMatrixMode\n");
192 my_glOrtho = (FIPS_GLORTHO_FN) my_eglGetProcAddress ("glOrtho");
193 if (my_glOrtho == NULL) {
194 fprintf (stderr, "Failed to eglGetProcAddress glOrtho\n");
198 my_glViewport = (FIPS_GLVIEWPORT_FN) my_eglGetProcAddress ("glViewport");
199 if (my_glViewport == NULL) {
200 fprintf (stderr, "Failed to eglGetProcAddress glViewport\n");
214 XVisualInfo *visual_info;
218 dpy = util_x11_init_display ();
220 common_create_egl_context (dpy, EGL_OPENGL_API, &egl_dpy,
221 &ctx, &config, &visual_info);
223 window = util_x11_init_window (dpy, visual_info);
225 surface = my_eglCreateWindowSurface (egl_dpy, config, window, NULL);
227 common_make_current (egl_dpy, ctx, surface);
229 common_handle_events (dpy, egl_dpy, surface);
231 util_x11_fini_window (dpy, window);
233 util_x11_fini_display (dpy);