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 GLX to construct an OpenGL context
25 * 2. By using dlopen to dynamically load libGL.so
26 * 3. By using glXGetProcAddressARB to lookup OpenGL functions
29 #define GL_GLEXT_PROTOTYPES
39 void* (*my_glXGetProcAddressARB) (char *);
40 void (*my_glClear) (GLbitfield);
41 void (*my_glClearColor) (GLclampf, GLclampf, GLclampf, GLclampf);
42 void (*my_glViewport) (GLint, GLint, GLsizei, GLsizei);
43 XVisualInfo * (*my_glXChooseVisual) (Display *, int, int *);
44 GLXContext (*my_glXCreateContext) (Display *, XVisualInfo *, GLXContext, Bool);
45 void (*my_glXDestroyContext) (Display *, GLXContext);
46 Bool (*my_glXMakeCurrent) (Display *, GLXDrawable, GLXContext);
47 void (*my_glXSwapBuffers) (Display *, GLXDrawable);
49 #define COMMON_GL_PREFIX my_
53 resolve_symbols (void)
58 gl_handle = dlopen ("libGL.so", RTLD_LAZY);
59 if (gl_handle == NULL) {
60 fprintf (stderr, "Error: Failed to open libGL.so\n");
67 my_glXGetProcAddressARB = dlsym (gl_handle, "glXGetProcAddressARB");
70 fprintf (stderr, "Failed to dlsym glXGetProcAddressARB: %s\n", error);
74 my_glClear = my_glXGetProcAddressARB ("glClear");
75 if (my_glClear == NULL) {
76 fprintf (stderr, "Failed to glXGetProcAddressARB glClear\n");
80 my_glClearColor = my_glXGetProcAddressARB ("glClearColor");
81 if (my_glClearColor == NULL) {
82 fprintf (stderr, "Failed to glXGetProcAddressARB glClearColor\n");
86 my_glViewport = my_glXGetProcAddressARB ("glViewport");
87 if (my_glViewport == NULL) {
88 fprintf (stderr, "Failed to glXGetProcAddressARB glViewport\n");
92 my_glXChooseVisual = my_glXGetProcAddressARB ("glXChooseVisual");
93 if (my_glXChooseVisual == NULL) {
94 fprintf (stderr, "Failed to glXGetProcAddressARB glXChooseVisual\n");
98 my_glXCreateContext = my_glXGetProcAddressARB ("glXCreateContext");
99 if (my_glXCreateContext == NULL) {
100 fprintf (stderr, "Failed to glXGetProcAddressARB glXCreateContext\n");
104 my_glXDestroyContext = my_glXGetProcAddressARB ("glXDestroyContext");
105 if (my_glXDestroyContext == NULL) {
106 fprintf (stderr, "Failed to glXGetProcAddressARB glXDestroyContext\n");
110 my_glXMakeCurrent = my_glXGetProcAddressARB ("glXMakeCurrent");
111 if (my_glXMakeCurrent == NULL) {
112 fprintf (stderr, "Failed to glXGetProcAddressARB glXMakeCurrent\n");
116 my_glXSwapBuffers = my_glXGetProcAddressARB ("glXSwapBuffers");
117 if (my_glXSwapBuffers == NULL) {
118 fprintf (stderr, "Failed to glXGetProcAddressARB glXSwapBuffers\n");
129 XVisualInfo *visual_info;
133 dpy = util_x11_init_display ();
135 common_create_glx_context (dpy, &ctx, &visual_info);
137 window = util_x11_init_window (dpy, visual_info);
139 common_make_current (dpy, ctx, window);
141 common_handle_events (dpy, dpy, window);
143 util_x11_fini_window (dpy, window);
145 util_x11_fini_display (dpy);