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 directly linking with libGL.so
26 * 3. By directly calling OpenGL functions
29 #define GL_GLEXT_PROTOTYPES
36 set_2d_projection (int width, int height)
38 glMatrixMode (GL_PROJECTION);
40 glOrtho (0, width, height, 0, 0, 1);
41 glMatrixMode (GL_MODELVIEW);
45 paint_rgb_using_clear (double r, double g, double b)
47 glClearColor(r, g, b, 1.0);
48 glClear(GL_COLOR_BUFFER_BIT);
52 draw (Display *dpy, Window window, int width, int height)
64 GLX_X_VISUAL_TYPE, GLX_DIRECT_COLOR,
68 /* Window and context setup. */
69 XVisualInfo *visual_info = glXChooseVisual(dpy, 0, visual_attr);
70 GLXContext ctx = glXCreateContext(dpy, visual_info, NULL, True);
71 glXMakeCurrent(dpy, window, ctx);
73 glViewport(0, 0, width, height);
75 set_2d_projection (width, height);
77 /* Simply count through some colors, frame by frame. */
78 #define RGB(frame) (((frame+1)/4) % 2), (((frame+1)/2) % 2), ((frame+1) % 2)
81 for (i = 0; i < 2; i++) {
82 /* Frame: Draw a solid (magenta) frame */
83 paint_rgb_using_clear (RGB(frame));
84 glXSwapBuffers (dpy, window);
87 /* Frame: Draw a solid (yellow) frame */
88 paint_rgb_using_clear (RGB(frame));
89 glXSwapBuffers (dpy, window);
92 /* Frame: Draw a solid (cyan) frame */
93 paint_rgb_using_clear (RGB(frame));
94 glXSwapBuffers (dpy, window);
99 glXDestroyContext (dpy, ctx);
103 handle_events(Display *dpy, Window window)
109 XNextEvent (dpy, &xev);
112 XNextEvent (dpy, &xev);
114 case ConfigureNotify:
115 width = xev.xconfigure.width;
116 height = xev.xconfigure.height;
119 if (xev.xexpose.count == 0) {
120 draw (dpy, window, width, height);
134 util_init_display_window (&dpy, &window);
136 handle_events (dpy, window);
138 util_fini_display_window (dpy, window);