ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/x11.c
(Generate patch)

Comparing ray/src/rt/x11.c (file contents):
Revision 1.18 by greg, Fri Apr 19 15:02:54 1991 UTC vs.
Revision 2.4 by greg, Sat May 30 09:32:18 1992 UTC

# Line 1 | Line 1
1 + /* Copyright (c) 1992 Regents of the University of California */
2 +
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ LBL";
5   #endif
6  
5 /* Copyright (c) 1989 Regents of the University of California */
6
7   /*
8 < *  x11.c - driver for X-windows version 11.3
8 > *  x11.c - driver for X-windows version 11
9   *
10   *     Jan 1990
11   */
# Line 38 | Line 38 | static char SCCSid[] = "$SunId$ LBL";
38  
39   #define  ourscreen      DefaultScreen(ourdisplay)
40   #define  ourroot        RootWindow(ourdisplay,ourscreen)
41 #define  ourwhite       WhitePixel(ourdisplay,ourscreen)
42 #define  ourblack       BlackPixel(ourdisplay,ourscreen)
41  
42   #define  levptr(etype)  ((etype *)&currentevent)
43  
# Line 47 | Line 45 | static XEvent  currentevent;           /* current event */
45  
46   static int  ncolors = 0;                /* color table size */
47   static unsigned long  *pixval = NULL;   /* allocated pixels */
48 + static unsigned long  ourblack=0, ourwhite=1;
49  
50   static Display  *ourdisplay = NULL;     /* our display */
51  
52 < static Visual  *ourvisual;              /* our visual structure */
52 > static XVisualInfo  ourvinfo;           /* our visual information */
53  
54   static Window  gwind = 0;               /* our graphics window */
55  
# Line 84 | Line 83 | x11_init(name, id)             /* initialize driver */
83   char  *name, *id;
84   {
85          int  nplanes;
87        XVisualInfo  ourvinfo;
86          XSetWindowAttributes    ourwinattr;
87          XWMHints  ourxwmhints;
88          XSizeHints      oursizhints;
# Line 94 | Line 92 | char  *name, *id;
92                  stderr_v("cannot open X-windows; DISPLAY variable set?\n");
93                  return(NULL);
94          }
95 +                                        /* find a usable visual */
96          nplanes = DisplayPlanes(ourdisplay, ourscreen);
97 <        if (nplanes < 4) {
98 <                stderr_v("not enough colors\n");
99 <                return(NULL);
100 <        } else if (nplanes <= 12) {
97 >        if (XMatchVisualInfo(ourdisplay,ourscreen,
98 >                                24,TrueColor,&ourvinfo) ||
99 >                        XMatchVisualInfo(ourdisplay,ourscreen,
100 >                                24,DirectColor,&ourvinfo)) {
101 >                ourblack = 0;
102 >                ourwhite = ourvinfo.red_mask |
103 >                                ourvinfo.green_mask |
104 >                                ourvinfo.blue_mask ;
105 >        } else {
106 >                if (nplanes < 4) {
107 >                        stderr_v("not enough colors\n");
108 >                        return(NULL);
109 >                }
110                  if (!XMatchVisualInfo(ourdisplay,ourscreen,
111 <                                nplanes,PseudoColor,&ourvinfo)) {
112 <                        stderr_v("PseudoColor server required\n");
111 >                                        nplanes,PseudoColor,&ourvinfo) &&
112 >                                !XMatchVisualInfo(ourdisplay,ourscreen,
113 >                                        nplanes,GrayScale,&ourvinfo)) {
114 >                        stderr_v("unsupported visual type\n");
115                          return(NULL);
116                  }
117 <        } else if (!XMatchVisualInfo(ourdisplay,ourscreen,
118 <                        nplanes,TrueColor,&ourvinfo) &&
109 <                                                /* kludge for DirectColor */
110 <                        !XMatchVisualInfo(ourdisplay,ourscreen,
111 <                        nplanes,DirectColor,&ourvinfo)) {
112 <                stderr_v("TrueColor server required\n");
113 <                return(NULL);
117 >                ourblack = BlackPixel(ourdisplay,ourscreen);
118 >                ourwhite = WhitePixel(ourdisplay,ourscreen);
119          }
115        ourvisual = ourvinfo.visual;
120          make_gmap(GAMMA);
121          /* open window */
122          ourwinattr.background_pixel = ourblack;
123          ourwinattr.border_pixel = ourblack;
124 +                                        /* this is stupid */
125 +        ourwinattr.colormap = XCreateColormap(ourdisplay, ourroot,
126 +                                ourvinfo.visual, AllocNone);
127          gwind = XCreateWindow(ourdisplay, ourroot, 0, 0,
128                  DisplayWidth(ourdisplay,ourscreen)-2*BORWIDTH,
129                  DisplayHeight(ourdisplay,ourscreen)-2*BORWIDTH,
130 <                BORWIDTH, nplanes, InputOutput, ourvisual,
131 <                CWBackPixel|CWBorderPixel, &ourwinattr);
130 >                BORWIDTH, ourvinfo.depth, InputOutput, ourvinfo.visual,
131 >                CWBackPixel|CWBorderPixel|CWColormap, &ourwinattr);
132          if (gwind == 0) {
133                  stderr_v("cannot create window\n");
134                  return(NULL);
135          }
136 <        XStoreName(ourdisplay, gwind, id);
136 >        XFreeColormap(ourdisplay, ourwinattr.colormap);
137 >        XStoreName(ourdisplay, gwind, id);
138          /* create a cursor */
139          pickcursor = XCreateFontCursor(ourdisplay, XC_diamond_cross);
140          ourgc = XCreateGC(ourdisplay, gwind, 0, NULL);
# Line 198 | Line 206 | int  xres, yres;
206          }
207          XClearWindow(ourdisplay, gwind);
208                                                  /* reinitialize color table */
209 <        if (ourvisual->class == PseudoColor)
209 >        if (ourvinfo.class == PseudoColor || ourvinfo.class == GrayScale)
210                  if (getpixels() == 0)
211                          stderr_v("cannot allocate colors\n");
212                  else
# Line 206 | Line 214 | int  xres, yres;
214                                                  /* get new command line */
215          if (comline != NULL)
216                  xt_close(comline);
217 <        comline = xt_open(ourdisplay,
218 <                        DefaultGC(ourdisplay,ourscreen),
211 <                        gwind, 0, gheight, gwidth, COMHEIGHT, 0, COMFN);
217 >        comline = xt_open(ourdisplay, gwind, 0, gheight,
218 >                        gwidth, COMHEIGHT, 0, ourblack, ourwhite, COMFN);
219          if (comline == NULL) {
220                  stderr_v("Cannot open command line window\n");
221                  quit(1);
# Line 231 | Line 238 | int  xmin, ymin, xmax, ymax;
238  
239          if (ncolors > 0)
240                  pixel = pixval[get_pixel(col, xnewcolr)];
241 <        else if (ourvisual->class != PseudoColor)
241 >        else if (ourvinfo.class == TrueColor || ourvinfo.class == DirectColor)
242                  pixel = true_pixel(col);
243          else
244                  return;
# Line 343 | Line 350 | getpixels()                            /* get the color map */
350          register int  i, j;
351  
352          if (ncolors > 0)
353 <                goto donecolors;
354 <        if (ourvisual == DefaultVisual(ourdisplay,ourscreen)) {
353 >                return(ncolors);
354 >        if (ourvinfo.visual == DefaultVisual(ourdisplay,ourscreen)) {
355                  ourmap = DefaultColormap(ourdisplay,ourscreen);
356                  goto loop;
357          }
358   newmap:
359 <        ourmap = XCreateColormap(ourdisplay,gwind,ourvisual,AllocNone);
359 >        ourmap = XCreateColormap(ourdisplay,gwind,ourvinfo.visual,AllocNone);
360   loop:
361 <        for (ncolors = ourvisual->map_entries;
362 <                        ncolors > ourvisual->map_entries/3;
361 >        for (ncolors = ourvinfo.colormap_size;
362 >                        ncolors > ourvinfo.colormap_size/3;
363                          ncolors = ncolors*.937) {
364                  pixval = (unsigned long *)malloc(ncolors*sizeof(unsigned long));
365                  if (pixval == NULL)
# Line 385 | Line 392 | loop:
392                          i--;
393                  }
394          XSetWindowColormap(ourdisplay, gwind, ourmap);
388 donecolors:
389 #ifdef  DEBUG
390        thiscolor.flags = DoRed|DoGreen|DoBlue;
391        thiscolor.red = thiscolor.green = thiscolor.blue = 0;
392        for (i = 0; i < ncolors; i++) {
393                thiscolor.pixel = pixval[i];
394                XStoreColor(ourdisplay, ourmap, &thiscolor);
395        }
396 #endif
395          return(ncolors);
396   }
397  
# Line 419 | Line 417 | COLOR  col;
417          BYTE  rgb[3];
418  
419          map_color(rgb, col);
420 <        rval = ourvisual->red_mask*rgb[RED]/255 & ourvisual->red_mask;
421 <        rval |= ourvisual->green_mask*rgb[GRN]/255 & ourvisual->green_mask;
422 <        rval |= ourvisual->blue_mask*rgb[BLU]/255 & ourvisual->blue_mask;
420 >        rval = ourvinfo.red_mask*rgb[RED]/255 & ourvinfo.red_mask;
421 >        rval |= ourvinfo.green_mask*rgb[GRN]/255 & ourvinfo.green_mask;
422 >        rval |= ourvinfo.blue_mask*rgb[BLU]/255 & ourvinfo.blue_mask;
423          return(rval);
424   }
425  
# Line 450 | Line 448 | getevent()                     /* get next event */
448                  freepixels();
449                  break;
450          case MapNotify:
451 <                if (ourvisual->class == PseudoColor)
451 >                if (ourvinfo.class == PseudoColor ||
452 >                                ourvinfo.class == GrayScale)
453                          if (getpixels() == 0)
454                                  stderr_v("Cannot allocate colors\n");
455                          else

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines