ftp://ftp.krokus.ru/pub/OpenBSD/distfiles/xscreensaver-4.06.tar.gz
[xscreensaver] / hacks / glx / xscreensaver-gl-helper.c
1 /* xscreensaver, Copyright (c) 2000, 2002 by Jamie Zawinski <jwz@jwz.org>
2  *
3  * Permission to use, copy, modify, distribute, and sell this software and its
4  * documentation for any purpose is hereby granted without fee, provided that
5  * the above copyright notice appear in all copies and that both that
6  * copyright notice and this permission notice appear in supporting
7  * documentation.  No representations are made about the suitability of this
8  * software for any purpose.  It is provided "as is" without express or 
9  * implied warranty.
10  */
11
12 /* xscreensaver-gl-helper -- prints the ID of the best visual to use
13    for GL programs on stdout.
14  */
15
16 #include "utils.h"
17 #include "visual.h"
18
19 #include <GL/gl.h>
20 #include <GL/glx.h>
21
22 char *progname = 0;
23 char *progclass = "XScreenSaver";
24 void *db = 0; /* hack hack -- no need for Xt in this program */
25
26 int
27 main (int argc, char **argv)
28 {
29   Display *dpy;
30   Screen *screen;
31   Visual *visual;
32   char *d = getenv ("DISPLAY");
33   int i;
34
35   progname = argv[0];
36   for (i = 1; i < argc; i++)
37     {
38       if (argv[i][0] == '-' && argv[i][1] == '-') argv[i]++;
39       if (strlen(argv[i]) >= 2 &&
40           !strncmp ("-display", argv[i], strlen(argv[i])))
41         {
42           if (i == argc-1) goto LOSE;
43           d = argv[i+1];
44           i++;
45         }
46       else
47         {
48          LOSE:
49           fprintf (stderr, "usage: %s [ -display host:dpy.screen ]\n",
50                    progname);
51           fprintf (stderr,
52                    "This program prints out the ID of the best "
53                    "X visual for GL programs to use.\n");
54           exit (1);
55         }
56     }
57
58   dpy = XOpenDisplay (d);
59   if (!dpy)
60     {
61       fprintf (stderr, "%s: couldn't open display %s\n", progname,
62                (d ? d : "(null)"));
63       exit (1);
64     }
65
66   screen = DefaultScreenOfDisplay (dpy);
67   visual = get_gl_visual (screen);
68
69   if (visual)
70     printf ("0x%x\n", (unsigned int) XVisualIDFromVisual (visual));
71   else
72     printf ("none\n");
73
74   exit (0);
75 }