1 /* xscreensaver, Copyright (c) 1999 by Jamie Zawinski <jwz@jwz.org>
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
12 /* This file contains code for picking the best visual for GL programs by
13 actually asking the GL library to figure it out for us. The code in
14 visual.c might do a good job of this on most systems, but not, in
17 Why? Because with the SGI O2 X server is weird.
19 GL programs tend to work best on a visual that is *half* as deep as the
20 depth of the screen, since that way, they can do double-buffering. So
21 generally, if the screen is 24 bits deep, but a 12-bit TrueColor visual
22 is available, then that's the visual you should use.
24 But on the server that runs on the O2 (a machine that has serious hardware
25 support for GL) the 12-bit PseudoColor visual looks awful (you get a black
26 and white, flickery image.) On these machines, the visual you want turns
27 out to be 0x31 -- this is but one of the eight 15-bit TrueColor visuals
28 (yes, 8, and yes, 15) that O2s provide. This is the only visual that works
29 properly -- as far as `xdpyinfo' is concerned, all of the 15-bit TrueColor
30 visuals are identical, but some flicker like mad, and some have deeply
31 weird artifacts (hidden surfaces show through!) I suppose these other
32 visuals must be tied to some arcane hardware feature...
34 So the bottom line is, there exists information about visuals which is
35 available to GL, but which is not available via Xlib calls. So the only
36 way to know which visual to use (other than impirically) is to actually
49 get_gl_visual (Screen *screen)
53 Display *dpy = DisplayOfScreen (screen);
54 int screen_num = screen_number (screen);
58 attrs[i++] = GLX_RGBA;
59 attrs[i++] = GLX_RED_SIZE; attrs[i++] = 1;
60 attrs[i++] = GLX_GREEN_SIZE; attrs[i++] = 1;
61 attrs[i++] = GLX_BLUE_SIZE; attrs[i++] = 1;
62 attrs[i++] = GLX_DEPTH_SIZE; attrs[i++] = 1;
63 attrs[i++] = GLX_DOUBLEBUFFER;
66 vi = glXChooseVisual (dpy, screen_num, attrs);
68 if (!vi) /* Try without double-buffering. */
71 vi = glXChooseVisual (dpy, screen_num, attrs);
74 if (!vi) /* Try mono. */
77 attrs[i++] = GLX_DOUBLEBUFFER;
79 vi = glXChooseVisual (dpy, screen_num, attrs);
82 if (!vi) /* Try mono without double-buffer. */
85 vi = glXChooseVisual (dpy, screen_num, attrs);
92 Visual *v = vi->visual;