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 2.1 by greg, Tue Nov 12 17:10:04 1991 UTC vs.
Revision 2.3 by greg, Fri May 29 15:42:49 1992 UTC

# 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) {
101 <                if (!XMatchVisualInfo(ourdisplay,ourscreen,
102 <                                nplanes,PseudoColor,&ourvinfo)) {
104 <                        stderr_v("PseudoColor server required\n");
97 >        if (    !XMatchVisualInfo(ourdisplay,ourscreen,
98 >                        24,TrueColor,&ourvinfo) &&
99 >                !XMatchVisualInfo(ourdisplay,ourscreen,
100 >                        24,DirectColor,&ourvinfo)       ) {
101 >                if (nplanes < 4) {
102 >                        stderr_v("not enough colors\n");
103                          return(NULL);
104 +                } else if (!XMatchVisualInfo(ourdisplay,ourscreen,
105 +                                        nplanes,PseudoColor,&ourvinfo) &&
106 +                                !XMatchVisualInfo(ourdisplay,ourscreen,
107 +                                        nplanes,GrayScale,&ourvinfo)) {
108 +                        stderr_v("unsupported visual type\n");
109 +                        return(NULL);
110                  }
111 <        } else if (!XMatchVisualInfo(ourdisplay,ourscreen,
112 <                        nplanes,TrueColor,&ourvinfo) &&
113 <                                                /* kludge for DirectColor */
114 <                        !XMatchVisualInfo(ourdisplay,ourscreen,
115 <                        nplanes,DirectColor,&ourvinfo)) {
112 <                stderr_v("TrueColor server required\n");
113 <                return(NULL);
111 >                ourblack = BlackPixel(ourdisplay,ourscreen);
112 >                ourwhite = WhitePixel(ourdisplay,ourscreen);
113 >        } else {
114 >                ourblack = 0;
115 >                ourwhite = ~0;
116          }
115        ourvisual = ourvinfo.visual;
117          make_gmap(GAMMA);
118          /* open window */
119          ourwinattr.background_pixel = ourblack;
120          ourwinattr.border_pixel = ourblack;
121 +                                        /* this is a waste! */
122 +        ourwinattr.colormap = XCreateColormap(ourdisplay, ourroot,
123 +                                ourvinfo.visual, AllocNone);
124          gwind = XCreateWindow(ourdisplay, ourroot, 0, 0,
125                  DisplayWidth(ourdisplay,ourscreen)-2*BORWIDTH,
126                  DisplayHeight(ourdisplay,ourscreen)-2*BORWIDTH,
127 <                BORWIDTH, nplanes, InputOutput, ourvisual,
128 <                CWBackPixel|CWBorderPixel, &ourwinattr);
127 >                BORWIDTH, ourvinfo.depth, InputOutput, ourvinfo.visual,
128 >                CWBackPixel|CWBorderPixel|CWColormap, &ourwinattr);
129          if (gwind == 0) {
130                  stderr_v("cannot create window\n");
131                  return(NULL);
# Line 198 | Line 202 | int  xres, yres;
202          }
203          XClearWindow(ourdisplay, gwind);
204                                                  /* reinitialize color table */
205 <        if (ourvisual->class == PseudoColor)
205 >        if (ourvinfo.class == PseudoColor || ourvinfo.class == GrayScale)
206                  if (getpixels() == 0)
207                          stderr_v("cannot allocate colors\n");
208                  else
# Line 206 | Line 210 | int  xres, yres;
210                                                  /* get new command line */
211          if (comline != NULL)
212                  xt_close(comline);
213 <        comline = xt_open(ourdisplay,
214 <                        DefaultGC(ourdisplay,ourscreen),
211 <                        gwind, 0, gheight, gwidth, COMHEIGHT, 0, COMFN);
213 >        comline = xt_open(ourdisplay, gwind, 0, gheight,
214 >                        gwidth, COMHEIGHT, 0, ourblack, ourwhite, COMFN);
215          if (comline == NULL) {
216                  stderr_v("Cannot open command line window\n");
217                  quit(1);
# Line 231 | Line 234 | int  xmin, ymin, xmax, ymax;
234  
235          if (ncolors > 0)
236                  pixel = pixval[get_pixel(col, xnewcolr)];
237 <        else if (ourvisual->class != PseudoColor)
237 >        else if (ourvinfo.class == TrueColor || ourvinfo.class == DirectColor)
238                  pixel = true_pixel(col);
239          else
240                  return;
# Line 343 | Line 346 | getpixels()                            /* get the color map */
346          register int  i, j;
347  
348          if (ncolors > 0)
349 <                goto donecolors;
350 <        if (ourvisual == DefaultVisual(ourdisplay,ourscreen)) {
349 >                return(ncolors);
350 >        if (ourvinfo.visual == DefaultVisual(ourdisplay,ourscreen)) {
351                  ourmap = DefaultColormap(ourdisplay,ourscreen);
352                  goto loop;
353          }
354   newmap:
355 <        ourmap = XCreateColormap(ourdisplay,gwind,ourvisual,AllocNone);
355 >        ourmap = XCreateColormap(ourdisplay,gwind,ourvinfo.visual,AllocNone);
356   loop:
357 <        for (ncolors = ourvisual->map_entries;
358 <                        ncolors > ourvisual->map_entries/3;
357 >        for (ncolors = ourvinfo.colormap_size;
358 >                        ncolors > ourvinfo.colormap_size/3;
359                          ncolors = ncolors*.937) {
360                  pixval = (unsigned long *)malloc(ncolors*sizeof(unsigned long));
361                  if (pixval == NULL)
# Line 385 | Line 388 | loop:
388                          i--;
389                  }
390          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
391          return(ncolors);
392   }
393  
# Line 419 | Line 413 | COLOR  col;
413          BYTE  rgb[3];
414  
415          map_color(rgb, col);
416 <        rval = ourvisual->red_mask*rgb[RED]/255 & ourvisual->red_mask;
417 <        rval |= ourvisual->green_mask*rgb[GRN]/255 & ourvisual->green_mask;
418 <        rval |= ourvisual->blue_mask*rgb[BLU]/255 & ourvisual->blue_mask;
416 >        rval = ourvinfo.red_mask*rgb[RED]/255 & ourvinfo.red_mask;
417 >        rval |= ourvinfo.green_mask*rgb[GRN]/255 & ourvinfo.green_mask;
418 >        rval |= ourvinfo.blue_mask*rgb[BLU]/255 & ourvinfo.blue_mask;
419          return(rval);
420   }
421  
# Line 450 | Line 444 | getevent()                     /* get next event */
444                  freepixels();
445                  break;
446          case MapNotify:
447 <                if (ourvisual->class == PseudoColor)
447 >                if (ourvinfo.class == PseudoColor ||
448 >                                ourvinfo.class == GrayScale)
449                          if (getpixels() == 0)
450                                  stderr_v("Cannot allocate colors\n");
451                          else

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines