1 /**************************************************************************
2 * Copyright 2012 Intel corporation
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 **************************************************************************/
41 draw (Display *dpy, Window window, int width, int height)
54 GLX_X_VISUAL_TYPE, GLX_DIRECT_COLOR,
57 XVisualInfo *visual_info = glXChooseVisual(dpy, 0, visual_attr);
58 GLXContext ctx = glXCreateContext(dpy, visual_info, NULL, True);
59 glXMakeCurrent(dpy, window, ctx);
61 glew_err = glewInit();
62 if (glew_err != GLEW_OK)
64 fprintf (stderr, "glewInit failed: %s\n",
65 glewGetErrorString(glew_err));
69 glViewport(0, 0, width, height);
70 glClearColor(1, 0, 1, 1);
71 glClear(GL_COLOR_BUFFER_BIT);
73 glXSwapBuffers (dpy, window);
75 glXDestroyContext (dpy, ctx);
79 handle_events(Display *dpy, Window window, int width, int height)
82 KeyCode quit_code = XKeysymToKeycode (dpy, XStringToKeysym("Q"));
84 XNextEvent (dpy, &xev);
87 XNextEvent (dpy, &xev);
90 if (xev.xkey.keycode == quit_code) {
95 width = xev.xconfigure.width;
96 height = xev.xconfigure.height;
99 if (xev.xexpose.count == 0) {
100 draw (dpy, window, width, height);
114 dpy = XOpenDisplay (NULL);
117 fprintf(stderr, "Failed to open display %s\n",
122 window = XCreateSimpleWindow(dpy, DefaultRootWindow (dpy),
123 0, 0, width, height, 0,
124 BlackPixel (dpy, DefaultScreen (dpy)),
125 BlackPixel (dpy, DefaultScreen (dpy)));
127 XSelectInput(dpy, window,
128 KeyPressMask | StructureNotifyMask | ExposureMask);
130 XMapWindow (dpy, window);
132 handle_events (dpy, window, width, height);
134 XDestroyWindow (dpy, window);