Merge commit 'origin/gallium-0.1' into gallium-0.2
[mesa.git] / progs / xdemos / glxgears.c
1 /*
2 * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included
12 * in all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 */
21
22 /*
23 * This is a port of the infamous "gears" demo to straight GLX (i.e. no GLUT)
24 * Port by Brian Paul 23 March 2001
25 *
26 * Command line options:
27 * -info print GL implementation information
28 * -stereo use stereo enabled GLX visual
29 *
30 */
31
32
33 #include <math.h>
34 #include <stdlib.h>
35 #include <stdio.h>
36 #include <string.h>
37 #include <X11/Xlib.h>
38 #include <X11/keysym.h>
39 #include <GL/gl.h>
40 #include <GL/glx.h>
41
42
43 #define BENCHMARK
44
45 #ifdef BENCHMARK
46
47 /* XXX this probably isn't very portable */
48
49 #include <sys/time.h>
50 #include <unistd.h>
51
52 /* return current time (in seconds) */
53 static double
54 current_time(void)
55 {
56 struct timeval tv;
57 #ifdef __VMS
58 (void) gettimeofday(&tv, NULL );
59 #else
60 struct timezone tz;
61 (void) gettimeofday(&tv, &tz);
62 #endif
63 return (double) tv.tv_sec + tv.tv_usec / 1000000.0;
64 }
65
66 #else /*BENCHMARK*/
67
68 /* dummy */
69 static double
70 current_time(void)
71 {
72 /* update this function for other platforms! */
73 static double t = 0.0;
74 static int warn = 1;
75 if (warn) {
76 fprintf(stderr, "Warning: current_time() not implemented!!\n");
77 warn = 0;
78 }
79 return t += 1.0;
80 }
81
82 #endif /*BENCHMARK*/
83
84
85
86 #ifndef M_PI
87 #define M_PI 3.14159265
88 #endif
89
90
91 /** Event handler results: */
92 #define NOP 0
93 #define EXIT 1
94 #define DRAW 2
95
96 static GLfloat view_rotx = 20.0, view_roty = 30.0, view_rotz = 0.0;
97 static GLint gear1, gear2, gear3;
98 static GLfloat angle = 0.0;
99
100 static GLboolean fullscreen = GL_FALSE; /* Create a single fullscreen window */
101 static GLboolean stereo = GL_FALSE; /* Enable stereo. */
102 static GLboolean animate = GL_TRUE; /* Animation */
103 static GLfloat eyesep = 5.0; /* Eye separation. */
104 static GLfloat fix_point = 40.0; /* Fixation point distance. */
105 static GLfloat left, right, asp; /* Stereo frustum params. */
106
107
108 /*
109 *
110 * Draw a gear wheel. You'll probably want to call this function when
111 * building a display list since we do a lot of trig here.
112 *
113 * Input: inner_radius - radius of hole at center
114 * outer_radius - radius at center of teeth
115 * width - width of gear
116 * teeth - number of teeth
117 * tooth_depth - depth of tooth
118 */
119 static void
120 gear(GLfloat inner_radius, GLfloat outer_radius, GLfloat width,
121 GLint teeth, GLfloat tooth_depth)
122 {
123 GLint i;
124 GLfloat r0, r1, r2;
125 GLfloat angle, da;
126 GLfloat u, v, len;
127
128 r0 = inner_radius;
129 r1 = outer_radius - tooth_depth / 2.0;
130 r2 = outer_radius + tooth_depth / 2.0;
131
132 da = 2.0 * M_PI / teeth / 4.0;
133
134 glShadeModel(GL_FLAT);
135
136 glNormal3f(0.0, 0.0, 1.0);
137
138 /* draw front face */
139 glBegin(GL_QUAD_STRIP);
140 for (i = 0; i <= teeth; i++) {
141 angle = i * 2.0 * M_PI / teeth;
142 glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5);
143 glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5);
144 if (i < teeth) {
145 glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5);
146 glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
147 width * 0.5);
148 }
149 }
150 glEnd();
151
152 /* draw front sides of teeth */
153 glBegin(GL_QUADS);
154 da = 2.0 * M_PI / teeth / 4.0;
155 for (i = 0; i < teeth; i++) {
156 angle = i * 2.0 * M_PI / teeth;
157
158 glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5);
159 glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), width * 0.5);
160 glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da),
161 width * 0.5);
162 glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
163 width * 0.5);
164 }
165 glEnd();
166
167 glNormal3f(0.0, 0.0, -1.0);
168
169 /* draw back face */
170 glBegin(GL_QUAD_STRIP);
171 for (i = 0; i <= teeth; i++) {
172 angle = i * 2.0 * M_PI / teeth;
173 glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5);
174 glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5);
175 if (i < teeth) {
176 glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
177 -width * 0.5);
178 glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5);
179 }
180 }
181 glEnd();
182
183 /* draw back sides of teeth */
184 glBegin(GL_QUADS);
185 da = 2.0 * M_PI / teeth / 4.0;
186 for (i = 0; i < teeth; i++) {
187 angle = i * 2.0 * M_PI / teeth;
188
189 glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
190 -width * 0.5);
191 glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da),
192 -width * 0.5);
193 glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), -width * 0.5);
194 glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5);
195 }
196 glEnd();
197
198 /* draw outward faces of teeth */
199 glBegin(GL_QUAD_STRIP);
200 for (i = 0; i < teeth; i++) {
201 angle = i * 2.0 * M_PI / teeth;
202
203 glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5);
204 glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5);
205 u = r2 * cos(angle + da) - r1 * cos(angle);
206 v = r2 * sin(angle + da) - r1 * sin(angle);
207 len = sqrt(u * u + v * v);
208 u /= len;
209 v /= len;
210 glNormal3f(v, -u, 0.0);
211 glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), width * 0.5);
212 glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), -width * 0.5);
213 glNormal3f(cos(angle), sin(angle), 0.0);
214 glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da),
215 width * 0.5);
216 glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da),
217 -width * 0.5);
218 u = r1 * cos(angle + 3 * da) - r2 * cos(angle + 2 * da);
219 v = r1 * sin(angle + 3 * da) - r2 * sin(angle + 2 * da);
220 glNormal3f(v, -u, 0.0);
221 glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
222 width * 0.5);
223 glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
224 -width * 0.5);
225 glNormal3f(cos(angle), sin(angle), 0.0);
226 }
227
228 glVertex3f(r1 * cos(0), r1 * sin(0), width * 0.5);
229 glVertex3f(r1 * cos(0), r1 * sin(0), -width * 0.5);
230
231 glEnd();
232
233 glShadeModel(GL_SMOOTH);
234
235 /* draw inside radius cylinder */
236 glBegin(GL_QUAD_STRIP);
237 for (i = 0; i <= teeth; i++) {
238 angle = i * 2.0 * M_PI / teeth;
239 glNormal3f(-cos(angle), -sin(angle), 0.0);
240 glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5);
241 glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5);
242 }
243 glEnd();
244 }
245
246
247 static void
248 draw(void)
249 {
250 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
251
252 glPushMatrix();
253 glRotatef(view_rotx, 1.0, 0.0, 0.0);
254 glRotatef(view_roty, 0.0, 1.0, 0.0);
255 glRotatef(view_rotz, 0.0, 0.0, 1.0);
256
257 glPushMatrix();
258 glTranslatef(-3.0, -2.0, 0.0);
259 glRotatef(angle, 0.0, 0.0, 1.0);
260 glCallList(gear1);
261 glPopMatrix();
262
263 glPushMatrix();
264 glTranslatef(3.1, -2.0, 0.0);
265 glRotatef(-2.0 * angle - 9.0, 0.0, 0.0, 1.0);
266 glCallList(gear2);
267 glPopMatrix();
268
269 glPushMatrix();
270 glTranslatef(-3.1, 4.2, 0.0);
271 glRotatef(-2.0 * angle - 25.0, 0.0, 0.0, 1.0);
272 glCallList(gear3);
273 glPopMatrix();
274
275 glPopMatrix();
276 }
277
278
279 static void
280 draw_gears(void)
281 {
282 if (stereo) {
283 /* First left eye. */
284 glDrawBuffer(GL_BACK_LEFT);
285
286 glMatrixMode(GL_PROJECTION);
287 glLoadIdentity();
288 glFrustum(left, right, -asp, asp, 5.0, 60.0);
289
290 glMatrixMode(GL_MODELVIEW);
291
292 glPushMatrix();
293 glTranslated(+0.5 * eyesep, 0.0, 0.0);
294 draw();
295 glPopMatrix();
296
297 /* Then right eye. */
298 glDrawBuffer(GL_BACK_RIGHT);
299
300 glMatrixMode(GL_PROJECTION);
301 glLoadIdentity();
302 glFrustum(-right, -left, -asp, asp, 5.0, 60.0);
303
304 glMatrixMode(GL_MODELVIEW);
305
306 glPushMatrix();
307 glTranslated(-0.5 * eyesep, 0.0, 0.0);
308 draw();
309 glPopMatrix();
310 }
311 else {
312 draw();
313 }
314 }
315
316
317 /** Draw single frame, do SwapBuffers, compute FPS */
318 static void
319 draw_frame(Display *dpy, Window win)
320 {
321 static int frames = 0;
322 static double tRot0 = -1.0, tRate0 = -1.0;
323 double dt, t = current_time();
324
325 if (tRot0 < 0.0)
326 tRot0 = t;
327 dt = t - tRot0;
328 tRot0 = t;
329
330 if (animate) {
331 /* advance rotation for next frame */
332 angle += 70.0 * dt; /* 70 degrees per second */
333 if (angle > 3600.0)
334 angle -= 3600.0;
335 }
336
337 draw_gears();
338 glXSwapBuffers(dpy, win);
339
340 frames++;
341
342 if (tRate0 < 0.0)
343 tRate0 = t;
344 if (t - tRate0 >= 5.0) {
345 GLfloat seconds = t - tRate0;
346 GLfloat fps = frames / seconds;
347 printf("%d frames in %3.1f seconds = %6.3f FPS\n", frames, seconds,
348 fps);
349 tRate0 = t;
350 frames = 0;
351 }
352 }
353
354
355 /* new window size or exposure */
356 static void
357 reshape(int width, int height)
358 {
359 glViewport(0, 0, (GLint) width, (GLint) height);
360
361 if (stereo) {
362 GLfloat w;
363
364 asp = (GLfloat) height / (GLfloat) width;
365 w = fix_point * (1.0 / 5.0);
366
367 left = -5.0 * ((w - 0.5 * eyesep) / fix_point);
368 right = 5.0 * ((w + 0.5 * eyesep) / fix_point);
369 }
370 else {
371 GLfloat h = (GLfloat) height / (GLfloat) width;
372
373 glMatrixMode(GL_PROJECTION);
374 glLoadIdentity();
375 glFrustum(-1.0, 1.0, -h, h, 5.0, 60.0);
376 }
377
378 glMatrixMode(GL_MODELVIEW);
379 glLoadIdentity();
380 glTranslatef(0.0, 0.0, -40.0);
381 }
382
383
384
385 static void
386 init(void)
387 {
388 static GLfloat pos[4] = { 5.0, 5.0, 10.0, 0.0 };
389 static GLfloat red[4] = { 0.8, 0.1, 0.0, 1.0 };
390 static GLfloat green[4] = { 0.0, 0.8, 0.2, 1.0 };
391 static GLfloat blue[4] = { 0.2, 0.2, 1.0, 1.0 };
392
393 glLightfv(GL_LIGHT0, GL_POSITION, pos);
394 glEnable(GL_CULL_FACE);
395 glEnable(GL_LIGHTING);
396 glEnable(GL_LIGHT0);
397 glEnable(GL_DEPTH_TEST);
398
399 /* make the gears */
400 gear1 = glGenLists(1);
401 glNewList(gear1, GL_COMPILE);
402 glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, red);
403 gear(1.0, 4.0, 1.0, 20, 0.7);
404 glEndList();
405
406 gear2 = glGenLists(1);
407 glNewList(gear2, GL_COMPILE);
408 glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, green);
409 gear(0.5, 2.0, 2.0, 10, 0.7);
410 glEndList();
411
412 gear3 = glGenLists(1);
413 glNewList(gear3, GL_COMPILE);
414 glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, blue);
415 gear(1.3, 2.0, 0.5, 10, 0.7);
416 glEndList();
417
418 glEnable(GL_NORMALIZE);
419 }
420
421
422 /**
423 * Remove window border/decorations.
424 */
425 static void
426 no_border( Display *dpy, Window w)
427 {
428 static const unsigned MWM_HINTS_DECORATIONS = (1 << 1);
429 static const int PROP_MOTIF_WM_HINTS_ELEMENTS = 5;
430
431 typedef struct
432 {
433 unsigned long flags;
434 unsigned long functions;
435 unsigned long decorations;
436 long inputMode;
437 unsigned long status;
438 } PropMotifWmHints;
439
440 PropMotifWmHints motif_hints;
441 Atom prop, proptype;
442 unsigned long flags = 0;
443
444 /* setup the property */
445 motif_hints.flags = MWM_HINTS_DECORATIONS;
446 motif_hints.decorations = flags;
447
448 /* get the atom for the property */
449 prop = XInternAtom( dpy, "_MOTIF_WM_HINTS", True );
450 if (!prop) {
451 /* something went wrong! */
452 return;
453 }
454
455 /* not sure this is correct, seems to work, XA_WM_HINTS didn't work */
456 proptype = prop;
457
458 XChangeProperty( dpy, w, /* display, window */
459 prop, proptype, /* property, type */
460 32, /* format: 32-bit datums */
461 PropModeReplace, /* mode */
462 (unsigned char *) &motif_hints, /* data */
463 PROP_MOTIF_WM_HINTS_ELEMENTS /* nelements */
464 );
465 }
466
467
468 /*
469 * Create an RGB, double-buffered window.
470 * Return the window and context handles.
471 */
472 static void
473 make_window( Display *dpy, const char *name,
474 int x, int y, int width, int height,
475 Window *winRet, GLXContext *ctxRet)
476 {
477 int attribs[] = { GLX_RGBA,
478 GLX_RED_SIZE, 1,
479 GLX_GREEN_SIZE, 1,
480 GLX_BLUE_SIZE, 1,
481 GLX_DOUBLEBUFFER,
482 GLX_DEPTH_SIZE, 1,
483 None };
484 int stereoAttribs[] = { GLX_RGBA,
485 GLX_RED_SIZE, 1,
486 GLX_GREEN_SIZE, 1,
487 GLX_BLUE_SIZE, 1,
488 GLX_DOUBLEBUFFER,
489 GLX_DEPTH_SIZE, 1,
490 GLX_STEREO,
491 None };
492 int scrnum;
493 XSetWindowAttributes attr;
494 unsigned long mask;
495 Window root;
496 Window win;
497 GLXContext ctx;
498 XVisualInfo *visinfo;
499
500 scrnum = DefaultScreen( dpy );
501 root = RootWindow( dpy, scrnum );
502
503 if (fullscreen) {
504 x = 0; y = 0;
505 width = DisplayWidth( dpy, scrnum );
506 height = DisplayHeight( dpy, scrnum );
507 }
508
509 if (stereo)
510 visinfo = glXChooseVisual( dpy, scrnum, stereoAttribs );
511 else
512 visinfo = glXChooseVisual( dpy, scrnum, attribs );
513 if (!visinfo) {
514 if (stereo) {
515 printf("Error: couldn't get an RGB, "
516 "Double-buffered, Stereo visual\n");
517 } else
518 printf("Error: couldn't get an RGB, Double-buffered visual\n");
519 exit(1);
520 }
521
522 /* window attributes */
523 attr.background_pixel = 0;
524 attr.border_pixel = 0;
525 attr.colormap = XCreateColormap( dpy, root, visinfo->visual, AllocNone);
526 attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask;
527 /* XXX this is a bad way to get a borderless window! */
528 mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
529
530 win = XCreateWindow( dpy, root, x, y, width, height,
531 0, visinfo->depth, InputOutput,
532 visinfo->visual, mask, &attr );
533
534 if (fullscreen)
535 no_border(dpy, win);
536
537 /* set hints and properties */
538 {
539 XSizeHints sizehints;
540 sizehints.x = x;
541 sizehints.y = y;
542 sizehints.width = width;
543 sizehints.height = height;
544 sizehints.flags = USSize | USPosition;
545 XSetNormalHints(dpy, win, &sizehints);
546 XSetStandardProperties(dpy, win, name, name,
547 None, (char **)NULL, 0, &sizehints);
548 }
549
550 ctx = glXCreateContext( dpy, visinfo, NULL, True );
551 if (!ctx) {
552 printf("Error: glXCreateContext failed\n");
553 exit(1);
554 }
555
556 XFree(visinfo);
557
558 *winRet = win;
559 *ctxRet = ctx;
560 }
561
562
563 /**
564 * Handle one X event.
565 * \return NOP, EXIT or DRAW
566 */
567 static int
568 handle_event(Display *dpy, Window win, XEvent *event)
569 {
570 switch (event->type) {
571 case Expose:
572 return DRAW;
573 case ConfigureNotify:
574 reshape(event->xconfigure.width, event->xconfigure.height);
575 break;
576 case KeyPress:
577 {
578 char buffer[10];
579 int r, code;
580 code = XLookupKeysym(&event->xkey, 0);
581 if (code == XK_Left) {
582 view_roty += 5.0;
583 }
584 else if (code == XK_Right) {
585 view_roty -= 5.0;
586 }
587 else if (code == XK_Up) {
588 view_rotx += 5.0;
589 }
590 else if (code == XK_Down) {
591 view_rotx -= 5.0;
592 }
593 else {
594 r = XLookupString(&event->xkey, buffer, sizeof(buffer),
595 NULL, NULL);
596 if (buffer[0] == 27) {
597 /* escape */
598 return EXIT;
599 }
600 else if (buffer[0] == 'a' || buffer[0] == 'A') {
601 animate = !animate;
602 }
603 }
604 return DRAW;
605 }
606 }
607 return NOP;
608 }
609
610
611 static void
612 event_loop(Display *dpy, Window win)
613 {
614 while (1) {
615 int op;
616 while (!animate || XPending(dpy) > 0) {
617 XEvent event;
618 XNextEvent(dpy, &event);
619 op = handle_event(dpy, win, &event);
620 if (op == EXIT)
621 return;
622 else if (op == DRAW)
623 break;
624 }
625
626 draw_frame(dpy, win);
627 }
628 }
629
630
631 static void
632 usage(void)
633 {
634 printf("Usage:\n");
635 printf(" -display <displayname> set the display to run on\n");
636 printf(" -stereo run in stereo mode\n");
637 printf(" -fullscreen run in fullscreen mode\n");
638 printf(" -info display OpenGL renderer info\n");
639 printf(" -geometry WxH+X+Y window geometry\n");
640 }
641
642
643 int
644 main(int argc, char *argv[])
645 {
646 unsigned int winWidth = 300, winHeight = 300;
647 int x = 0, y = 0;
648 Display *dpy;
649 Window win;
650 GLXContext ctx;
651 char *dpyName = NULL;
652 GLboolean printInfo = GL_FALSE;
653 int i;
654
655 for (i = 1; i < argc; i++) {
656 if (strcmp(argv[i], "-display") == 0) {
657 dpyName = argv[i+1];
658 i++;
659 }
660 else if (strcmp(argv[i], "-info") == 0) {
661 printInfo = GL_TRUE;
662 }
663 else if (strcmp(argv[i], "-stereo") == 0) {
664 stereo = GL_TRUE;
665 }
666 else if (strcmp(argv[i], "-fullscreen") == 0) {
667 fullscreen = GL_TRUE;
668 }
669 else if (i < argc-1 && strcmp(argv[i], "-geometry") == 0) {
670 XParseGeometry(argv[i+1], &x, &y, &winWidth, &winHeight);
671 i++;
672 }
673 else {
674 usage();
675 return -1;
676 }
677 }
678
679 dpy = XOpenDisplay(dpyName);
680 if (!dpy) {
681 printf("Error: couldn't open display %s\n",
682 dpyName ? dpyName : getenv("DISPLAY"));
683 return -1;
684 }
685
686 make_window(dpy, "glxgears", x, y, winWidth, winHeight, &win, &ctx);
687 XMapWindow(dpy, win);
688 glXMakeCurrent(dpy, win, ctx);
689
690 if (printInfo) {
691 printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
692 printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION));
693 printf("GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR));
694 printf("GL_EXTENSIONS = %s\n", (char *) glGetString(GL_EXTENSIONS));
695 }
696
697 init();
698
699 /* Set initial projection/viewing transformation.
700 * We can't be sure we'll get a ConfigureNotify event when the window
701 * first appears.
702 */
703 reshape(winWidth, winHeight);
704
705 event_loop(dpy, win);
706
707 glDeleteLists(gear1, 1);
708 glDeleteLists(gear2, 1);
709 glDeleteLists(gear3, 1);
710 glXDestroyContext(dpy, ctx);
711 XDestroyWindow(dpy, win);
712 XCloseDisplay(dpy);
713
714 return 0;
715 }