began for maemo
[xscreensaver] / 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
25 int
26 main (int argc, char **argv)
27 {
28   Display *dpy;
29   Screen *screen;
30   Visual *visual;
31   char *d = getenv ("DISPLAY");
32   int i;
33
34   progname = argv[0];
35   for (i = 1; i < argc; i++)
36     {
37       if (argv[i][0] == '-' && argv[i][1] == '-') argv[i]++;
38       if (strlen(argv[i]) >= 2 &&
39           !strncmp ("-display", argv[i], strlen(argv[i])))
40         {
41           if (i == argc-1) goto LOSE;
42           d = argv[i+1];
43           i++;
44         }
45       else
46         {
47          LOSE:
48           fprintf (stderr, "usage: %s [ -display host:dpy.screen ]\n",
49                    progname);
50           fprintf (stderr,
51                    "This program prints out the ID of the best "
52                    "X visual for GL programs to use.\n");
53           exit (1);
54         }
55     }
56
57   dpy = XOpenDisplay (d);
58   if (!dpy)
59     {
60       fprintf (stderr, "%s: couldn't open display %s\n", progname,
61                (d ? d : "(null)"));
62       exit (1);
63     }
64
65   screen = DefaultScreenOfDisplay (dpy);
66   visual = get_gl_visual (screen);
67
68   if (visual)
69     printf ("0x%x\n", (unsigned int) XVisualIDFromVisual (visual));
70   else
71     printf ("none\n");
72
73   exit (0);
74 }