ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/hd/rhd_glx.c
Revision: 3.4
Committed: Fri Dec 26 14:12:37 1997 UTC (26 years, 3 months ago) by gregl
Content type: text/plain
Branch: MAIN
Changes since 3.3: +176 -493 lines
Log Message:
reverted to using quadtree for GLX driver

File Contents

# User Rev Content
1 gregl 3.1 /* Copyright (c) 1997 Silicon Graphics, Inc. */
2    
3     #ifndef lint
4     static char SCCSid[] = "$SunId$ SGI";
5     #endif
6    
7     /*
8     * OpenGL GLX driver for holodeck display.
9 gregl 3.2 * Based on x11 driver.
10 gregl 3.1 */
11    
12     #include "standard.h"
13 gregl 3.4 #include "rhd_qtree.h"
14 gregl 3.1
15     #include <GL/glx.h>
16    
17     #include "x11icon.h"
18    
19     #ifndef FEQ
20     #define FEQ(a,b) ((a)-(b) <= FTINY && (a)-(b) >= -FTINY)
21     #endif
22    
23 gregl 3.4 #ifndef MAXCONE
24     #define MAXCONE 16 /* number of different cone sizes */
25 gregl 3.1 #endif
26 gregl 3.4 #ifndef MAXVERT
27     #define MAXVERT 32 /* maximum number of cone vertices */
28 gregl 3.1 #endif
29 gregl 3.4 #ifndef MINVERT
30     #define MINVERT 4 /* minimum number of cone vertices */
31 gregl 3.1 #endif
32 gregl 3.4 #ifndef DEPTHFACT
33     #define DEPTHFACT 16. /* multiplier for depth tests */
34 gregl 3.1 #endif
35    
36 gregl 3.2 #define GAMMA 1.4 /* default gamma correction */
37 gregl 3.1
38     #define MOVPCT 7 /* percent distance to move /frame */
39     #define MOVDIR(b) ((b)==Button1 ? 1 : (b)==Button2 ? 0 : -1)
40     #define MOVDEG (-5) /* degrees to orbit CW/down /frame */
41     #define MOVORB(s) ((s)&ShiftMask ? 1 : (s)&ControlMask ? -1 : 0)
42    
43     #define MINWIDTH 480 /* minimum graphics window width */
44     #define MINHEIGHT 400 /* minimum graphics window height */
45    
46     #define VIEWDIST 356 /* assumed viewing distance (mm) */
47    
48     #define BORWIDTH 5 /* border width */
49    
50     #define ourscreen DefaultScreen(ourdisplay)
51     #define ourroot RootWindow(ourdisplay,ourscreen)
52     #define ourmask (StructureNotifyMask|ExposureMask|KeyPressMask|\
53     ButtonPressMask|ButtonReleaseMask)
54    
55     #define levptr(etype) ((etype *)&currentevent)
56    
57     struct driver odev; /* global device driver structure */
58    
59     static XEvent currentevent; /* current event */
60    
61     static int mapped = 0; /* window is mapped? */
62     static unsigned long ourblack=0, ourwhite=~0;
63    
64     static Display *ourdisplay = NULL; /* our display */
65     static XVisualInfo *ourvinf; /* our visual information */
66     static Window gwind = 0; /* our graphics window */
67     static GLXContext gctx; /* our GLX context */
68    
69     static double pwidth, pheight; /* pixel dimensions (mm) */
70    
71 gregl 3.4 static double curzmax = 1e4; /* current depth upper limit */
72     static double nxtzmax = 0.; /* maximum (finite) depth so far */
73 gregl 3.1
74 gregl 3.4 static struct {
75     double rad; /* cone radius */
76     int nverts; /* number of vertices */
77     FVECT *va; /* allocated vertex array */
78     } cone[MAXCONE]; /* precomputed cones for drawing */
79    
80 gregl 3.1 static int inpresflags; /* input result flags */
81    
82     static int headlocked = 0; /* lock vertical motion */
83    
84     static int resizewindow(), getevent(), getkey(), moveview(),
85 gregl 3.4 initcones(), freecones(),
86     getmove(), fixwindow(), mytmflags();
87 gregl 3.1
88    
89     dev_open(id) /* initialize X11 driver */
90     char *id;
91     {
92     extern char *getenv();
93     static int atlBest[] = {GLX_RGBA, GLX_RED_SIZE,8,
94     GLX_GREEN_SIZE,8, GLX_BLUE_SIZE,8,
95 gregl 3.4 GLX_DEPTH_SIZE,15, None};
96 gregl 3.1 char *gv;
97     double gamval = GAMMA;
98     XSetWindowAttributes ourwinattr;
99     XWMHints ourxwmhints;
100     XSizeHints oursizhints;
101 gregl 3.4 /* set quadtree globals */
102     qtMinNodesiz = 3;
103 gregl 3.1 /* open display server */
104     ourdisplay = XOpenDisplay(NULL);
105     if (ourdisplay == NULL)
106     error(USER, "cannot open X-windows; DISPLAY variable set?\n");
107     /* find a usable visual */
108     ourvinf = glXChooseVisual(ourdisplay, ourscreen, atlBest);
109     if (ourvinf == NULL)
110     error(USER, "no suitable visuals available");
111     /* get a context */
112     gctx = glXCreateContext(ourdisplay, ourvinf, NULL, GL_TRUE);
113     /* set gamma and tone mapping */
114     if ((gv = XGetDefault(ourdisplay, "radiance", "gamma")) != NULL
115     || (gv = getenv("DISPLAY_GAMMA")) != NULL)
116     gamval = atof(gv);
117     if (tmInit(mytmflags(), stdprims, gamval) == NULL)
118     error(SYSTEM, "not enough memory in dev_open");
119     /* open window */
120     ourwinattr.background_pixel = ourblack;
121     ourwinattr.border_pixel = ourblack;
122     ourwinattr.event_mask = ourmask;
123     /* this is stupid */
124     ourwinattr.colormap = XCreateColormap(ourdisplay, ourroot,
125     ourvinf->visual, AllocNone);
126     gwind = XCreateWindow(ourdisplay, ourroot, 0, 0,
127     DisplayWidth(ourdisplay,ourscreen)-2*BORWIDTH,
128     DisplayHeight(ourdisplay,ourscreen)-2*BORWIDTH,
129     BORWIDTH, ourvinf->depth, InputOutput, ourvinf->visual,
130     CWBackPixel|CWBorderPixel|CWColormap|CWEventMask, &ourwinattr);
131     if (gwind == 0)
132     error(SYSTEM, "cannot create window\n");
133     XStoreName(ourdisplay, gwind, id);
134     /* set window manager hints */
135     ourxwmhints.flags = InputHint|IconPixmapHint;
136     ourxwmhints.input = True;
137     ourxwmhints.icon_pixmap = XCreateBitmapFromData(ourdisplay,
138     gwind, x11icon_bits, x11icon_width, x11icon_height);
139     XSetWMHints(ourdisplay, gwind, &ourxwmhints);
140     oursizhints.min_width = MINWIDTH;
141     oursizhints.min_height = MINHEIGHT;
142     oursizhints.flags = PMinSize;
143     XSetNormalHints(ourdisplay, gwind, &oursizhints);
144 gregl 3.2 /* set GLX context */
145     glXMakeCurrent(ourdisplay, gwind, gctx);
146     glEnable(GL_DEPTH_TEST);
147     glDepthFunc(GL_LEQUAL);
148     glShadeModel(GL_FLAT);
149     glDisable(GL_DITHER);
150 gregl 3.4 glDisable(GL_CULL_FACE);
151     glMatrixMode(GL_PROJECTION);
152     glOrtho(0., 1., 0., 1., -.01, 1.01);
153     glTranslated(0., 0., -1.01);
154 gregl 3.1 /* figure out sensible view */
155     pwidth = (double)DisplayWidthMM(ourdisplay, ourscreen) /
156     DisplayWidth(ourdisplay, ourscreen);
157     pheight = (double)DisplayHeightMM(ourdisplay, ourscreen) /
158     DisplayHeight(ourdisplay, ourscreen);
159     copystruct(&odev.v, &stdview);
160     odev.v.type = VT_PER;
161 gregl 3.2 /* map the window */
162     XMapWindow(ourdisplay, gwind);
163     dev_input(); /* sets size and view angles */
164     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
165 gregl 3.4 /* allocate our leaf pile */
166     if (!qtAllocLeaves(2 * DisplayWidth(ourdisplay,ourscreen) *
167     DisplayHeight(ourdisplay,ourscreen) /
168     (qtMinNodesiz*qtMinNodesiz)))
169 gregl 3.2 error(SYSTEM, "insufficient memory for value storage");
170 gregl 3.1 odev.name = id;
171     odev.ifd = ConnectionNumber(ourdisplay);
172 gregl 3.4 /* initialize cone array */
173     initcones();
174 gregl 3.1 }
175    
176    
177     dev_close() /* close our display and free resources */
178     {
179     glXMakeCurrent(ourdisplay, None, NULL);
180     glXDestroyContext(ourdisplay, gctx);
181     XDestroyWindow(ourdisplay, gwind);
182     gwind = 0;
183     XCloseDisplay(ourdisplay);
184     ourdisplay = NULL;
185 gregl 3.4 qtFreeLeaves();
186 gregl 3.1 tmDone(NULL);
187 gregl 3.4 freecones();
188 gregl 3.1 odev.v.type = 0;
189     odev.hres = odev.vres = 0;
190     odev.ifd = -1;
191     }
192    
193    
194     int
195     dev_view(nv) /* assign new driver view */
196     register VIEW *nv;
197     {
198 gregl 3.4 if (nv->type == VT_PAR || /* check view legality */
199     nv->horiz > 160. || nv->vert > 160.) {
200 gregl 3.1 error(COMMAND, "illegal view type/angle");
201 gregl 3.4 nv->type = odev.v.type;
202 gregl 3.1 nv->horiz = odev.v.horiz;
203     nv->vert = odev.v.vert;
204     return(0);
205     }
206 gregl 3.4 if (nv->vfore > FTINY) {
207     error(COMMAND, "cannot handle fore clipping");
208     nv->vfore = 0.;
209     return(0);
210     }
211 gregl 3.1 if (nv != &odev.v) {
212     if (!FEQ(nv->horiz,odev.v.horiz) || /* resize window? */
213     !FEQ(nv->vert,odev.v.vert)) {
214     int dw = DisplayWidth(ourdisplay,ourscreen);
215     int dh = DisplayHeight(ourdisplay,ourscreen);
216    
217     dw -= 25; /* for window frame */
218     dh -= 50;
219     odev.hres = 2.*VIEWDIST/pwidth *
220     tan(PI/180./2.*nv->horiz);
221     odev.vres = 2.*VIEWDIST/pheight *
222     tan(PI/180./2.*nv->vert);
223     if (odev.hres > dw) {
224     odev.vres = dw * odev.vres / odev.hres;
225     odev.hres = dw;
226     }
227     if (odev.vres > dh) {
228     odev.hres = dh * odev.hres / odev.vres;
229     odev.vres = dh;
230     }
231     XResizeWindow(ourdisplay, gwind, odev.hres, odev.vres);
232 gregl 3.2 dev_input(); /* get resize event */
233 gregl 3.1 }
234     copystruct(&odev.v, nv);
235     }
236 gregl 3.4 if (nxtzmax > FTINY) {
237     curzmax = nxtzmax;
238     nxtzmax = 0.;
239     }
240     glClear(GL_DEPTH_BUFFER_BIT);
241     qtReplant();
242 gregl 3.1 return(1);
243     }
244    
245    
246     int
247     dev_input() /* get X11 input */
248     {
249     inpresflags = 0;
250    
251     do
252     getevent();
253    
254     while (XQLength(ourdisplay) > 0);
255    
256     return(inpresflags);
257     }
258    
259    
260 gregl 3.4 int
261     dev_flush() /* flush output */
262 gregl 3.1 {
263 gregl 3.4 qtUpdate();
264     glFlush();
265     return(XPending(ourdisplay));
266 gregl 3.1 }
267    
268    
269 gregl 3.4 dev_cone(rgb, ip, rad) /* render a cone in view coordinates */
270     BYTE rgb[3];
271     FVECT ip;
272     double rad;
273 gregl 3.1 {
274 gregl 3.4 register int ci, j;
275     double apexh, basez;
276     /* compute apex height (0. to 1.) */
277     if (ip[2] > 1e6)
278     apexh = 1. - 1./DEPTHFACT;
279     else {
280     if (ip[2] > nxtzmax)
281     nxtzmax = ip[2];
282     if (ip[2] >= curzmax)
283     apexh = 1. - 1./DEPTHFACT;
284     else
285     apexh = 1. - ip[2]/(curzmax*DEPTHFACT);
286 gregl 3.1 }
287 gregl 3.4 /* find closest cone match */
288     for (ci = 0; ci < MAXCONE-1; ci++)
289     if (cone[ci].rad >= rad)
290     break;
291     /* draw it */
292     glColor3ub(rgb[0], rgb[1], rgb[2]);
293     glBegin(GL_TRIANGLE_FAN);
294     glVertex3d(ip[0], ip[1], apexh); /* start with apex */
295     basez = apexh*cone[ci].va[0][2]; /* base z's all the same */
296     for (j = 0; j < cone[ci].nverts; j++) /* draw each face */
297     glVertex3d(ip[0]+cone[ci].va[j][0], ip[1]+cone[ci].va[j][1],
298     basez);
299     /* connect last to first */
300     glVertex3d(ip[0]+cone[ci].va[0][0], ip[1]+cone[ci].va[0][1], basez);
301     glEnd(); /* all done */
302 gregl 3.1 }
303    
304    
305     static int
306     mytmflags() /* figure out tone mapping flags */
307     {
308     extern char *progname;
309     register char *cp, *tail;
310     /* find basic name */
311     for (cp = tail = progname; *cp; cp++)
312     if (*cp == '/')
313     tail = cp+1;
314     for (cp = tail; *cp && *cp != '.'; cp++)
315     ;
316     if (cp-tail == 3 && !strncmp(tail, "glx", 3))
317     return(TM_F_CAMERA);
318     if (cp-tail == 4 && !strncmp(tail, "glxh", 4))
319     return(TM_F_HUMAN);
320     error(USER, "illegal driver name");
321     }
322    
323    
324     static
325 gregl 3.4 initcones() /* initialize cone vertices */
326 gregl 3.1 {
327     register int i, j;
328 gregl 3.4 double minrad, d;
329 gregl 3.1
330 gregl 3.4 if (cone[0].nverts)
331     freecones();
332     minrad = 2.*qtMinNodesiz/(double)(DisplayWidth(ourdisplay,ourscreen) +
333     DisplayHeight(ourdisplay,ourscreen));
334     for (i = 0; i < MAXCONE; i++) {
335     d = (double)i/(MAXCONE-1); d *= d; /* x^2 distribution */
336     cone[i].rad = minrad + (1.-minrad)*d;
337     cone[i].nverts = MINVERT + (MAXVERT-MINVERT)*d;
338     cone[i].va = (FVECT *)malloc(cone[i].nverts*sizeof(FVECT));
339     if (cone[i].va == NULL)
340     error(SYSTEM, "out of memory in initcones");
341     for (j = cone[i].nverts; j--; ) {
342     d = 2.*PI * (j+.5) / (cone[i].nverts);
343     cone[i].va[j][0] = cos(d) * cone[i].rad;
344     cone[i].va[j][1] = sin(d) * cone[i].rad;
345     cone[i].va[j][2] = 1. - cone[i].rad;
346 gregl 3.2 }
347     }
348     }
349    
350    
351     static
352 gregl 3.4 freecones() /* free cone vertices */
353 gregl 3.2 {
354 gregl 3.4 register int i;
355 gregl 3.2
356 gregl 3.4 for (i = MAXCONE; i--; )
357     if (cone[i].nverts) {
358     free((char *)cone[i].va);
359     cone[i].va = NULL;
360     cone[i].nverts = 0;
361 gregl 3.2 }
362     }
363    
364    
365     static
366 gregl 3.1 getevent() /* get next event */
367     {
368     XNextEvent(ourdisplay, levptr(XEvent));
369     switch (levptr(XEvent)->type) {
370     case ConfigureNotify:
371     resizewindow(levptr(XConfigureEvent));
372     break;
373     case UnmapNotify:
374     mapped = 0;
375     break;
376     case MapNotify:
377     mapped = 1;
378     break;
379     case Expose:
380     fixwindow(levptr(XExposeEvent));
381     break;
382     case KeyPress:
383     getkey(levptr(XKeyPressedEvent));
384     break;
385     case ButtonPress:
386     getmove(levptr(XButtonPressedEvent));
387     break;
388     }
389     }
390    
391    
392     static
393     draw3dline(wp) /* draw 3d line in world coordinates */
394     register FVECT wp[2];
395     {
396     glVertex3d(wp[0][0], wp[0][1], wp[0][2]);
397     glVertex3d(wp[1][0], wp[1][1], wp[1][2]);
398     }
399    
400    
401     static
402     draw_grids() /* draw holodeck section grids */
403     {
404 gregl 3.2 static BYTE gridrgba[4] = {0x0, 0xff, 0xff, 0x00};
405 gregl 3.4 double xmin, xmax, ymin, ymax, zmin, zmax;
406     double d, cx, sx, crad;
407     FVECT vx, vy;
408     register int i, j;
409     /* can we even do it? */
410     if (!mapped || odev.v.type != VT_PER)
411 gregl 3.1 return;
412 gregl 3.4 /* compute view frustum */
413     if (normalize(odev.v.vdir) == 0.0)
414     return;
415     zmin = 0.01;
416     zmax = 10000.;
417     if (odev.v.vfore > FTINY)
418     zmin = odev.v.vfore;
419     if (odev.v.vaft > FTINY)
420     zmax = odev.v.vaft;
421     xmax = zmin * tan(PI/180./2. * odev.v.horiz);
422     xmin = -xmax;
423     d = odev.v.hoff * (xmax - xmin);
424     xmin += d; xmax += d;
425     ymax = zmin * tan(PI/180./2. * odev.v.vert);
426     ymin = -ymax;
427     d = odev.v.voff * (ymax - ymin);
428     ymin += d; ymax += d;
429     /* set view matrix */
430     glMatrixMode(GL_PROJECTION);
431     glPushMatrix();
432     glLoadIdentity();
433     glFrustum(xmin, xmax, ymin, ymax, zmin, zmax);
434     gluLookAt(odev.v.vp[0], odev.v.vp[1], odev.v.vp[2],
435     odev.v.vp[0] + odev.v.vdir[0],
436     odev.v.vp[1] + odev.v.vdir[1],
437     odev.v.vp[2] + odev.v.vdir[2],
438     odev.v.vup[0], odev.v.vup[1], odev.v.vup[2]);
439     glDisable(GL_DEPTH_TEST); /* write no depth values */
440 gregl 3.1 glColor4ub(gridrgba[0], gridrgba[1], gridrgba[2], gridrgba[3]);
441 gregl 3.4 glBegin(GL_LINES); /* draw each grid line */
442 gregl 3.1 gridlines(draw3dline);
443     glEnd();
444 gregl 3.4 glEnable(GL_DEPTH_TEST); /* restore rendering params */
445     glPopMatrix();
446 gregl 3.1 }
447    
448    
449     static
450     moveview(dx, dy, mov, orb) /* move our view */
451     int dx, dy, mov, orb;
452     {
453     VIEW nv;
454     FVECT odir, v1;
455     double d;
456     register int li;
457     /* start with old view */
458     copystruct(&nv, &odev.v);
459     /* change view direction */
460     if (mov | orb) {
461 gregl 3.4 if ((li = qtFindLeaf(dx, dy)) < 0)
462 gregl 3.1 return(0); /* not on window */
463 gregl 3.4 VSUM(odir, qtL.wp[li], nv.vp, -1.);
464 gregl 3.1 } else {
465     if (viewray(nv.vp, nv.vdir, &odev.v,
466     (dx+.5)/odev.hres, (dy+.5)/odev.vres) < -FTINY)
467     return(0); /* outside view */
468     }
469     if (orb && mov) { /* orbit left/right */
470     spinvector(odir, odir, nv.vup, d=MOVDEG*PI/180.*mov);
471 gregl 3.4 VSUM(nv.vp, qtL.wp[li], odir, -1.);
472 gregl 3.1 spinvector(nv.vdir, nv.vdir, nv.vup, d);
473     } else if (orb) { /* orbit up/down */
474     fcross(v1, odir, nv.vup);
475     if (normalize(v1) == 0.)
476     return(0);
477     spinvector(odir, odir, v1, d=MOVDEG*PI/180.*orb);
478 gregl 3.4 VSUM(nv.vp, qtL.wp[li], odir, -1.);
479 gregl 3.1 spinvector(nv.vdir, nv.vdir, v1, d);
480     } else if (mov) { /* move forward/backward */
481     d = MOVPCT/100. * mov;
482     VSUM(nv.vp, nv.vp, odir, d);
483     }
484     if (!mov ^ !orb && headlocked) { /* restore head height */
485     VSUM(v1, odev.v.vp, nv.vp, -1.);
486     d = DOT(v1, odev.v.vup);
487     VSUM(nv.vp, nv.vp, odev.v.vup, d);
488     }
489     if (setview(&nv) != NULL)
490     return(0); /* illegal view */
491     dev_view(&nv);
492     inpresflags |= DFL(DC_SETVIEW);
493     return(1);
494     }
495    
496    
497     static
498     getmove(ebut) /* get view change */
499     XButtonPressedEvent *ebut;
500     {
501     int movdir = MOVDIR(ebut->button);
502     int movorb = MOVORB(ebut->state);
503 gregl 3.4 int oldnodesiz = qtMinNodesiz;
504 gregl 3.1 Window rootw, childw;
505     int rootx, rooty, wx, wy;
506     unsigned int statemask;
507    
508 gregl 3.4 qtMinNodesiz = 24; /* accelerate update rate */
509 gregl 3.1 XNoOp(ourdisplay);
510    
511     while (!XCheckMaskEvent(ourdisplay,
512     ButtonReleaseMask, levptr(XEvent))) {
513    
514     if (!XQueryPointer(ourdisplay, gwind, &rootw, &childw,
515     &rootx, &rooty, &wx, &wy, &statemask))
516     break; /* on another screen */
517    
518     if (!moveview(wx, odev.vres-1-wy, movdir, movorb)) {
519     sleep(1);
520     continue;
521     }
522 gregl 3.4 glClear(GL_COLOR_BUFFER_BIT);
523     qtUpdate();
524 gregl 3.1 draw_grids();
525 gregl 3.4 glFlush();
526 gregl 3.1 }
527     if (!(inpresflags & DFL(DC_SETVIEW))) { /* do final motion */
528     movdir = MOVDIR(levptr(XButtonReleasedEvent)->button);
529     wx = levptr(XButtonReleasedEvent)->x;
530     wy = levptr(XButtonReleasedEvent)->y;
531     moveview(wx, odev.vres-1-wy, movdir, movorb);
532     }
533     dev_flush();
534 gregl 3.4
535     qtMinNodesiz = oldnodesiz; /* restore quadtree resolution */
536 gregl 3.1 }
537    
538    
539     static
540     getkey(ekey) /* get input key */
541     register XKeyPressedEvent *ekey;
542     {
543     int n;
544     char buf[8];
545    
546     n = XLookupString(ekey, buf, sizeof(buf), NULL, NULL);
547     if (n != 1)
548     return;
549     switch (buf[0]) {
550     case 'h': /* turn on height motion lock */
551     headlocked = 1;
552     return;
553     case 'H': /* turn off height motion lock */
554     headlocked = 0;
555     return;
556     case 'l': /* retrieve last view */
557     inpresflags |= DFL(DC_LASTVIEW);
558     return;
559     case 'p': /* pause computation */
560     inpresflags |= DFL(DC_PAUSE);
561     return;
562     case 'v': /* spit out view */
563     inpresflags |= DFL(DC_GETVIEW);
564     return;
565     case '\n':
566     case '\r': /* resume computation */
567     inpresflags |= DFL(DC_RESUME);
568     return;
569     case CTRL('R'): /* redraw screen */
570 gregl 3.2 glClear(GL_DEPTH_BUFFER_BIT);
571 gregl 3.4 qtRedraw(0, 0, odev.hres, odev.vres);
572 gregl 3.1 return;
573     case CTRL('L'): /* refresh from server */
574     if (inpresflags & DFL(DC_REDRAW))
575     return;
576     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
577     draw_grids();
578     glFlush();
579 gregl 3.4 qtCompost(100); /* get rid of old values */
580 gregl 3.1 inpresflags |= DFL(DC_REDRAW); /* resend values from server */
581     return;
582     case 'K': /* kill rtrace process(es) */
583     inpresflags |= DFL(DC_KILL);
584     break;
585     case 'R': /* restart rtrace */
586     inpresflags |= DFL(DC_RESTART);
587     break;
588     case 'C': /* clobber holodeck */
589     inpresflags |= DFL(DC_CLOBBER);
590     break;
591     case 'q': /* quit the program */
592     inpresflags |= DFL(DC_QUIT);
593     return;
594     default:
595     XBell(ourdisplay, 0);
596     return;
597     }
598     }
599    
600    
601     static
602     fixwindow(eexp) /* repair damage to window */
603     register XExposeEvent *eexp;
604     {
605 gregl 3.4 int xmin, xmax, ymin, ymax;
606    
607 gregl 3.2 if (odev.hres == 0 || odev.vres == 0) /* first exposure */
608     resizewindow((XConfigureEvent *)eexp);
609 gregl 3.4 xmin = eexp->x; xmax = eexp->x + eexp->width;
610     ymin = odev.vres - eexp->y - eexp->height; ymax = odev.vres - eexp->y;
611     /* clear portion of depth */
612     glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
613     glDepthFunc(GL_ALWAYS);
614     glBegin(GL_POLYGON);
615     glVertex3d((double)xmin/odev.hres, (double)ymin/odev.vres, 0.);
616     glVertex3d((double)xmax/odev.hres, (double)ymin/odev.vres, 0.);
617     glVertex3d((double)xmax/odev.hres, (double)ymax/odev.vres, 0.);
618     glVertex3d((double)xmin/odev.hres, (double)ymax/odev.vres, 0.);
619     glEnd();
620     glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
621     glDepthFunc(GL_LEQUAL);
622     qtRedraw(xmin, ymin, xmax, ymax);
623 gregl 3.1 }
624    
625    
626     static
627     resizewindow(ersz) /* resize window */
628     register XConfigureEvent *ersz;
629     {
630     if (ersz->width == odev.hres && ersz->height == odev.vres)
631     return;
632    
633     odev.hres = ersz->width;
634     odev.vres = ersz->height;
635    
636     odev.v.horiz = 2.*180./PI * atan(0.5/VIEWDIST*pwidth*odev.hres);
637     odev.v.vert = 2.*180./PI * atan(0.5/VIEWDIST*pheight*odev.vres);
638    
639 gregl 3.4 glViewport(0, 0, odev.hres, odev.vres);
640 gregl 3.1
641     inpresflags |= DFL(DC_SETVIEW);
642     }