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 glXGetProcAddress to lookup OpenGL functions
29 #define GL_GLEXT_PROTOTYPES
39 void* (*my_glXGetProcAddress) (char *);
40 void (*my_glClear) (GLbitfield);
41 void (*my_glClearColor) (GLclampf, GLclampf, GLclampf, GLclampf);
42 void (*my_glLoadIdentity) (void);
43 void (*my_glMatrixMode) (GLenum);
44 void (*my_glOrtho) (GLdouble, GLdouble, GLdouble, GLdouble, GLdouble, GLdouble);
45 void (*my_glViewport) (GLint, GLint, GLsizei, GLsizei);
46 XVisualInfo * (*my_glXChooseVisual) (Display *, int, int *);
47 GLXContext (*my_glXCreateContext) (Display *, XVisualInfo *, GLXContext, Bool);
48 void (*my_glXDestroyContext) (Display *, GLXContext);
49 Bool (*my_glXMakeCurrent) (Display *, GLXDrawable, GLXContext);
50 void (*my_glXSwapBuffers) (Display *, GLXDrawable);
52 #define HANDLE_EVENTS_GL_PREFIX my_
53 #include "handle-events.c"
56 resolve_symbols (void)
61 gl_handle = dlopen ("libGL.so", RTLD_LAZY);
62 if (gl_handle == NULL) {
63 fprintf (stderr, "Error: Failed to open libGL.so\n");
70 my_glXGetProcAddress = dlsym (gl_handle, "glXGetProcAddress");
73 fprintf (stderr, "Failed to dlsym glXGetProcAddress: %s\n", error);
77 my_glClear = my_glXGetProcAddress ("glClear");
78 if (my_glClear == NULL) {
79 fprintf (stderr, "Failed to glXGetProcAddress glClear\n");
83 my_glClearColor = my_glXGetProcAddress ("glClearColor");
84 if (my_glClearColor == NULL) {
85 fprintf (stderr, "Failed to glXGetProcAddress glClearColor\n");
89 my_glLoadIdentity = my_glXGetProcAddress ("glLoadIdentity");
90 if (my_glLoadIdentity == NULL) {
91 fprintf (stderr, "Failed to glXGetProcAddress glLoadIdentity\n");
95 my_glMatrixMode = my_glXGetProcAddress ("glMatrixMode");
96 if (my_glMatrixMode == NULL) {
97 fprintf (stderr, "Failed to glXGetProcAddress glMatrixMode\n");
101 my_glOrtho = my_glXGetProcAddress ("glOrtho");
102 if (my_glOrtho == NULL) {
103 fprintf (stderr, "Failed to glXGetProcAddress glOrtho\n");
107 my_glViewport = my_glXGetProcAddress ("glViewport");
108 if (my_glViewport == NULL) {
109 fprintf (stderr, "Failed to glXGetProcAddress glViewport\n");
113 my_glXChooseVisual = my_glXGetProcAddress ("glXChooseVisual");
114 if (my_glXChooseVisual == NULL) {
115 fprintf (stderr, "Failed to glXGetProcAddress glXChooseVisual\n");
119 my_glXCreateContext = my_glXGetProcAddress ("glXCreateContext");
120 if (my_glXCreateContext == NULL) {
121 fprintf (stderr, "Failed to glXGetProcAddress glXCreateContext\n");
125 my_glXDestroyContext = my_glXGetProcAddress ("glXDestroyContext");
126 if (my_glXDestroyContext == NULL) {
127 fprintf (stderr, "Failed to glXGetProcAddress glXDestroyContext\n");
131 my_glXMakeCurrent = my_glXGetProcAddress ("glXMakeCurrent");
132 if (my_glXMakeCurrent == NULL) {
133 fprintf (stderr, "Failed to glXGetProcAddress glXMakeCurrent\n");
137 my_glXSwapBuffers = my_glXGetProcAddress ("glXSwapBuffers");
138 if (my_glXSwapBuffers == NULL) {
139 fprintf (stderr, "Failed to glXGetProcAddress glXSwapBuffers\n");
150 util_init_display_window (&dpy, &window);
154 handle_events (dpy, window);
156 util_fini_display_window (dpy, window);