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 #define UNUSED __attribute__((unused))
47 set_2d_projection (void)
49 glMatrixMode (GL_PROJECTION);
51 glOrtho (0, width, height, 0, 0, 1);
52 glMatrixMode (GL_MODELVIEW);
56 draw (Display *dpy, Window window, int width, int height)
68 GLX_X_VISUAL_TYPE, GLX_DIRECT_COLOR,
72 /* Window and context setup. */
73 XVisualInfo *visual_info = glXChooseVisual(dpy, 0, visual_attr);
74 GLXContext ctx = glXCreateContext(dpy, visual_info, NULL, True);
75 glXMakeCurrent(dpy, window, ctx);
77 glew_err = glewInit();
78 if (glew_err != GLEW_OK)
80 fprintf (stderr, "glewInit failed: %s\n",
81 glewGetErrorString(glew_err));
85 glViewport(0, 0, width, height);
89 /* Frame 1. Perform a few operations, most without side effects. */
91 GLint line_width UNUSED, logic_op UNUSED;
92 GLboolean blend_enabled UNUSED;
94 glGetIntegerv(GL_LINE_WIDTH, &line_width);
95 glGetIntegerv(GL_LOGIC_OP_MODE, &logic_op);
97 blend_enabled = glIsEnabled(GL_BLEND);
101 blend_enabled = glIsEnabled(GL_BLEND);
106 glXSwapBuffers (dpy, window);
107 /* Frame 2. Again, more operations, most with side effects. */
109 GLint line_width UNUSED, logic_op UNUSED;
110 GLboolean blend_enabled UNUSED;
112 glGetIntegerv(GL_LINE_WIDTH, &line_width);
113 glGetIntegerv(GL_LOGIC_OP_MODE, &logic_op);
115 blend_enabled = glIsEnabled(GL_BLEND);
119 blend_enabled = glIsEnabled(GL_BLEND);
125 glXDestroyContext (dpy, ctx);
129 handle_events(Display *dpy, Window window, int width, int height)
132 KeyCode quit_code = XKeysymToKeycode (dpy, XStringToKeysym("Q"));
134 XNextEvent (dpy, &xev);
137 XNextEvent (dpy, &xev);
140 if (xev.xkey.keycode == quit_code) {
144 case ConfigureNotify:
145 width = xev.xconfigure.width;
146 height = xev.xconfigure.height;
149 if (xev.xexpose.count == 0) {
150 draw (dpy, window, width, height);
164 dpy = XOpenDisplay (NULL);
167 fprintf(stderr, "Failed to open display %s\n",
172 window = XCreateSimpleWindow(dpy, DefaultRootWindow (dpy),
173 0, 0, width, height, 0,
174 BlackPixel (dpy, DefaultScreen (dpy)),
175 BlackPixel (dpy, DefaultScreen (dpy)));
177 XSelectInput(dpy, window,
178 KeyPressMask | StructureNotifyMask | ExposureMask);
180 XMapWindow (dpy, window);
182 handle_events (dpy, window, width, height);
184 XDestroyWindow (dpy, window);