ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/hd/rhd_glx.c
Revision: 3.7
Committed: Fri Dec 26 16:50:03 1997 UTC (26 years, 3 months ago) by gregl
Content type: text/plain
Branch: MAIN
Changes since 3.6: +0 -1 lines
Log Message:
removed unnecessary call to glClear()

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 gregl 3.4 /* allocate our leaf pile */
165     if (!qtAllocLeaves(2 * DisplayWidth(ourdisplay,ourscreen) *
166     DisplayHeight(ourdisplay,ourscreen) /
167     (qtMinNodesiz*qtMinNodesiz)))
168 gregl 3.2 error(SYSTEM, "insufficient memory for value storage");
169 gregl 3.1 odev.name = id;
170     odev.ifd = ConnectionNumber(ourdisplay);
171 gregl 3.4 /* initialize cone array */
172     initcones();
173 gregl 3.1 }
174    
175    
176     dev_close() /* close our display and free resources */
177     {
178     glXMakeCurrent(ourdisplay, None, NULL);
179     glXDestroyContext(ourdisplay, gctx);
180     XDestroyWindow(ourdisplay, gwind);
181     gwind = 0;
182     XCloseDisplay(ourdisplay);
183     ourdisplay = NULL;
184 gregl 3.4 qtFreeLeaves();
185 gregl 3.1 tmDone(NULL);
186 gregl 3.4 freecones();
187 gregl 3.1 odev.v.type = 0;
188     odev.hres = odev.vres = 0;
189     odev.ifd = -1;
190     }
191    
192    
193     int
194     dev_view(nv) /* assign new driver view */
195     register VIEW *nv;
196     {
197 gregl 3.4 if (nv->type == VT_PAR || /* check view legality */
198     nv->horiz > 160. || nv->vert > 160.) {
199 gregl 3.1 error(COMMAND, "illegal view type/angle");
200 gregl 3.4 nv->type = odev.v.type;
201 gregl 3.1 nv->horiz = odev.v.horiz;
202     nv->vert = odev.v.vert;
203     return(0);
204     }
205 gregl 3.4 if (nv->vfore > FTINY) {
206     error(COMMAND, "cannot handle fore clipping");
207     nv->vfore = 0.;
208     return(0);
209     }
210 gregl 3.1 if (nv != &odev.v) {
211     if (!FEQ(nv->horiz,odev.v.horiz) || /* resize window? */
212     !FEQ(nv->vert,odev.v.vert)) {
213     int dw = DisplayWidth(ourdisplay,ourscreen);
214     int dh = DisplayHeight(ourdisplay,ourscreen);
215    
216     dw -= 25; /* for window frame */
217     dh -= 50;
218     odev.hres = 2.*VIEWDIST/pwidth *
219     tan(PI/180./2.*nv->horiz);
220     odev.vres = 2.*VIEWDIST/pheight *
221     tan(PI/180./2.*nv->vert);
222     if (odev.hres > dw) {
223     odev.vres = dw * odev.vres / odev.hres;
224     odev.hres = dw;
225     }
226     if (odev.vres > dh) {
227     odev.hres = dh * odev.hres / odev.vres;
228     odev.vres = dh;
229     }
230     XResizeWindow(ourdisplay, gwind, odev.hres, odev.vres);
231 gregl 3.2 dev_input(); /* get resize event */
232 gregl 3.1 }
233     copystruct(&odev.v, nv);
234     }
235 gregl 3.4 if (nxtzmax > FTINY) {
236     curzmax = nxtzmax;
237     nxtzmax = 0.;
238     }
239     glClear(GL_DEPTH_BUFFER_BIT);
240     qtReplant();
241 gregl 3.1 return(1);
242     }
243    
244    
245     int
246     dev_input() /* get X11 input */
247     {
248     inpresflags = 0;
249    
250     do
251     getevent();
252    
253     while (XQLength(ourdisplay) > 0);
254    
255     return(inpresflags);
256     }
257    
258    
259 gregl 3.4 int
260     dev_flush() /* flush output */
261 gregl 3.1 {
262 gregl 3.4 qtUpdate();
263     glFlush();
264     return(XPending(ourdisplay));
265 gregl 3.1 }
266    
267    
268 gregl 3.4 dev_cone(rgb, ip, rad) /* render a cone in view coordinates */
269     BYTE rgb[3];
270     FVECT ip;
271     double rad;
272 gregl 3.1 {
273 gregl 3.4 register int ci, j;
274     double apexh, basez;
275     /* compute apex height (0. to 1.) */
276     if (ip[2] > 1e6)
277     apexh = 1. - 1./DEPTHFACT;
278     else {
279     if (ip[2] > nxtzmax)
280     nxtzmax = ip[2];
281     if (ip[2] >= curzmax)
282     apexh = 1. - 1./DEPTHFACT;
283     else
284     apexh = 1. - ip[2]/(curzmax*DEPTHFACT);
285 gregl 3.1 }
286 gregl 3.5 rad *= 1.25; /* find conservative cone match */
287 gregl 3.4 for (ci = 0; ci < MAXCONE-1; ci++)
288     if (cone[ci].rad >= rad)
289     break;
290     /* draw it */
291     glColor3ub(rgb[0], rgb[1], rgb[2]);
292     glBegin(GL_TRIANGLE_FAN);
293     glVertex3d(ip[0], ip[1], apexh); /* start with apex */
294     basez = apexh*cone[ci].va[0][2]; /* base z's all the same */
295     for (j = 0; j < cone[ci].nverts; j++) /* draw each face */
296     glVertex3d(ip[0]+cone[ci].va[j][0], ip[1]+cone[ci].va[j][1],
297     basez);
298     /* connect last to first */
299     glVertex3d(ip[0]+cone[ci].va[0][0], ip[1]+cone[ci].va[0][1], basez);
300     glEnd(); /* all done */
301 gregl 3.1 }
302    
303    
304     static int
305     mytmflags() /* figure out tone mapping flags */
306     {
307     extern char *progname;
308     register char *cp, *tail;
309     /* find basic name */
310     for (cp = tail = progname; *cp; cp++)
311     if (*cp == '/')
312     tail = cp+1;
313     for (cp = tail; *cp && *cp != '.'; cp++)
314     ;
315     if (cp-tail == 3 && !strncmp(tail, "glx", 3))
316     return(TM_F_CAMERA);
317     if (cp-tail == 4 && !strncmp(tail, "glxh", 4))
318     return(TM_F_HUMAN);
319     error(USER, "illegal driver name");
320     }
321    
322    
323     static
324 gregl 3.4 initcones() /* initialize cone vertices */
325 gregl 3.1 {
326     register int i, j;
327 gregl 3.4 double minrad, d;
328 gregl 3.1
329 gregl 3.4 if (cone[0].nverts)
330     freecones();
331     minrad = 2.*qtMinNodesiz/(double)(DisplayWidth(ourdisplay,ourscreen) +
332     DisplayHeight(ourdisplay,ourscreen));
333     for (i = 0; i < MAXCONE; i++) {
334     d = (double)i/(MAXCONE-1); d *= d; /* x^2 distribution */
335     cone[i].rad = minrad + (1.-minrad)*d;
336     cone[i].nverts = MINVERT + (MAXVERT-MINVERT)*d;
337     cone[i].va = (FVECT *)malloc(cone[i].nverts*sizeof(FVECT));
338     if (cone[i].va == NULL)
339     error(SYSTEM, "out of memory in initcones");
340     for (j = cone[i].nverts; j--; ) {
341     d = 2.*PI * (j+.5) / (cone[i].nverts);
342     cone[i].va[j][0] = cos(d) * cone[i].rad;
343     cone[i].va[j][1] = sin(d) * cone[i].rad;
344     cone[i].va[j][2] = 1. - cone[i].rad;
345 gregl 3.2 }
346     }
347     }
348    
349    
350     static
351 gregl 3.4 freecones() /* free cone vertices */
352 gregl 3.2 {
353 gregl 3.4 register int i;
354 gregl 3.2
355 gregl 3.4 for (i = MAXCONE; i--; )
356     if (cone[i].nverts) {
357     free((char *)cone[i].va);
358     cone[i].va = NULL;
359     cone[i].nverts = 0;
360 gregl 3.2 }
361     }
362    
363    
364     static
365 gregl 3.1 getevent() /* get next event */
366     {
367     XNextEvent(ourdisplay, levptr(XEvent));
368     switch (levptr(XEvent)->type) {
369     case ConfigureNotify:
370     resizewindow(levptr(XConfigureEvent));
371     break;
372     case UnmapNotify:
373     mapped = 0;
374     break;
375     case MapNotify:
376     mapped = 1;
377     break;
378     case Expose:
379     fixwindow(levptr(XExposeEvent));
380     break;
381     case KeyPress:
382     getkey(levptr(XKeyPressedEvent));
383     break;
384     case ButtonPress:
385     getmove(levptr(XButtonPressedEvent));
386     break;
387     }
388     }
389    
390    
391     static
392     draw3dline(wp) /* draw 3d line in world coordinates */
393     register FVECT wp[2];
394     {
395     glVertex3d(wp[0][0], wp[0][1], wp[0][2]);
396     glVertex3d(wp[1][0], wp[1][1], wp[1][2]);
397     }
398    
399    
400     static
401     draw_grids() /* draw holodeck section grids */
402     {
403 gregl 3.2 static BYTE gridrgba[4] = {0x0, 0xff, 0xff, 0x00};
404 gregl 3.4 double xmin, xmax, ymin, ymax, zmin, zmax;
405     double d, cx, sx, crad;
406     FVECT vx, vy;
407     register int i, j;
408     /* can we even do it? */
409     if (!mapped || odev.v.type != VT_PER)
410 gregl 3.1 return;
411 gregl 3.4 /* compute view frustum */
412     if (normalize(odev.v.vdir) == 0.0)
413     return;
414     zmin = 0.01;
415     zmax = 10000.;
416     if (odev.v.vfore > FTINY)
417     zmin = odev.v.vfore;
418     if (odev.v.vaft > FTINY)
419     zmax = odev.v.vaft;
420     xmax = zmin * tan(PI/180./2. * odev.v.horiz);
421     xmin = -xmax;
422     d = odev.v.hoff * (xmax - xmin);
423     xmin += d; xmax += d;
424     ymax = zmin * tan(PI/180./2. * odev.v.vert);
425     ymin = -ymax;
426     d = odev.v.voff * (ymax - ymin);
427     ymin += d; ymax += d;
428     /* set view matrix */
429     glMatrixMode(GL_PROJECTION);
430     glPushMatrix();
431     glLoadIdentity();
432     glFrustum(xmin, xmax, ymin, ymax, zmin, zmax);
433     gluLookAt(odev.v.vp[0], odev.v.vp[1], odev.v.vp[2],
434     odev.v.vp[0] + odev.v.vdir[0],
435     odev.v.vp[1] + odev.v.vdir[1],
436     odev.v.vp[2] + odev.v.vdir[2],
437     odev.v.vup[0], odev.v.vup[1], odev.v.vup[2]);
438     glDisable(GL_DEPTH_TEST); /* write no depth values */
439 gregl 3.1 glColor4ub(gridrgba[0], gridrgba[1], gridrgba[2], gridrgba[3]);
440 gregl 3.4 glBegin(GL_LINES); /* draw each grid line */
441 gregl 3.1 gridlines(draw3dline);
442     glEnd();
443 gregl 3.4 glEnable(GL_DEPTH_TEST); /* restore rendering params */
444     glPopMatrix();
445 gregl 3.1 }
446    
447    
448     static
449     moveview(dx, dy, mov, orb) /* move our view */
450     int dx, dy, mov, orb;
451     {
452     VIEW nv;
453     FVECT odir, v1;
454     double d;
455     register int li;
456     /* start with old view */
457     copystruct(&nv, &odev.v);
458     /* change view direction */
459     if (mov | orb) {
460 gregl 3.4 if ((li = qtFindLeaf(dx, dy)) < 0)
461 gregl 3.1 return(0); /* not on window */
462 gregl 3.4 VSUM(odir, qtL.wp[li], nv.vp, -1.);
463 gregl 3.1 } else {
464     if (viewray(nv.vp, nv.vdir, &odev.v,
465     (dx+.5)/odev.hres, (dy+.5)/odev.vres) < -FTINY)
466     return(0); /* outside view */
467     }
468     if (orb && mov) { /* orbit left/right */
469     spinvector(odir, odir, nv.vup, d=MOVDEG*PI/180.*mov);
470 gregl 3.4 VSUM(nv.vp, qtL.wp[li], odir, -1.);
471 gregl 3.1 spinvector(nv.vdir, nv.vdir, nv.vup, d);
472     } else if (orb) { /* orbit up/down */
473     fcross(v1, odir, nv.vup);
474     if (normalize(v1) == 0.)
475     return(0);
476     spinvector(odir, odir, v1, d=MOVDEG*PI/180.*orb);
477 gregl 3.4 VSUM(nv.vp, qtL.wp[li], odir, -1.);
478 gregl 3.1 spinvector(nv.vdir, nv.vdir, v1, d);
479     } else if (mov) { /* move forward/backward */
480     d = MOVPCT/100. * mov;
481     VSUM(nv.vp, nv.vp, odir, d);
482     }
483     if (!mov ^ !orb && headlocked) { /* restore head height */
484     VSUM(v1, odev.v.vp, nv.vp, -1.);
485     d = DOT(v1, odev.v.vup);
486     VSUM(nv.vp, nv.vp, odev.v.vup, d);
487     }
488     if (setview(&nv) != NULL)
489     return(0); /* illegal view */
490     dev_view(&nv);
491     inpresflags |= DFL(DC_SETVIEW);
492     return(1);
493     }
494    
495    
496     static
497     getmove(ebut) /* get view change */
498     XButtonPressedEvent *ebut;
499     {
500     int movdir = MOVDIR(ebut->button);
501     int movorb = MOVORB(ebut->state);
502 gregl 3.4 int oldnodesiz = qtMinNodesiz;
503 gregl 3.1 Window rootw, childw;
504     int rootx, rooty, wx, wy;
505     unsigned int statemask;
506    
507 gregl 3.4 qtMinNodesiz = 24; /* accelerate update rate */
508 gregl 3.1 XNoOp(ourdisplay);
509    
510     while (!XCheckMaskEvent(ourdisplay,
511     ButtonReleaseMask, levptr(XEvent))) {
512    
513     if (!XQueryPointer(ourdisplay, gwind, &rootw, &childw,
514     &rootx, &rooty, &wx, &wy, &statemask))
515     break; /* on another screen */
516    
517     if (!moveview(wx, odev.vres-1-wy, movdir, movorb)) {
518     sleep(1);
519     continue;
520     }
521 gregl 3.4 glClear(GL_COLOR_BUFFER_BIT);
522     qtUpdate();
523 gregl 3.1 draw_grids();
524 gregl 3.4 glFlush();
525 gregl 3.1 }
526     if (!(inpresflags & DFL(DC_SETVIEW))) { /* do final motion */
527     movdir = MOVDIR(levptr(XButtonReleasedEvent)->button);
528     wx = levptr(XButtonReleasedEvent)->x;
529     wy = levptr(XButtonReleasedEvent)->y;
530     moveview(wx, odev.vres-1-wy, movdir, movorb);
531     }
532     dev_flush();
533 gregl 3.4
534     qtMinNodesiz = oldnodesiz; /* restore quadtree resolution */
535 gregl 3.1 }
536    
537    
538     static
539     getkey(ekey) /* get input key */
540     register XKeyPressedEvent *ekey;
541     {
542     int n;
543     char buf[8];
544    
545     n = XLookupString(ekey, buf, sizeof(buf), NULL, NULL);
546     if (n != 1)
547     return;
548     switch (buf[0]) {
549     case 'h': /* turn on height motion lock */
550     headlocked = 1;
551     return;
552     case 'H': /* turn off height motion lock */
553     headlocked = 0;
554     return;
555     case 'l': /* retrieve last view */
556     inpresflags |= DFL(DC_LASTVIEW);
557     return;
558     case 'p': /* pause computation */
559     inpresflags |= DFL(DC_PAUSE);
560     return;
561     case 'v': /* spit out view */
562     inpresflags |= DFL(DC_GETVIEW);
563     return;
564     case '\n':
565     case '\r': /* resume computation */
566     inpresflags |= DFL(DC_RESUME);
567     return;
568     case CTRL('R'): /* redraw screen */
569 gregl 3.2 glClear(GL_DEPTH_BUFFER_BIT);
570 gregl 3.4 qtRedraw(0, 0, odev.hres, odev.vres);
571 gregl 3.1 return;
572     case CTRL('L'): /* refresh from server */
573     if (inpresflags & DFL(DC_REDRAW))
574     return;
575     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
576     draw_grids();
577     glFlush();
578 gregl 3.4 qtCompost(100); /* get rid of old values */
579 gregl 3.1 inpresflags |= DFL(DC_REDRAW); /* resend values from server */
580     return;
581     case 'K': /* kill rtrace process(es) */
582     inpresflags |= DFL(DC_KILL);
583     break;
584     case 'R': /* restart rtrace */
585     inpresflags |= DFL(DC_RESTART);
586     break;
587     case 'C': /* clobber holodeck */
588     inpresflags |= DFL(DC_CLOBBER);
589     break;
590     case 'q': /* quit the program */
591     inpresflags |= DFL(DC_QUIT);
592     return;
593     default:
594     XBell(ourdisplay, 0);
595     return;
596     }
597     }
598    
599    
600     static
601     fixwindow(eexp) /* repair damage to window */
602     register XExposeEvent *eexp;
603     {
604 gregl 3.4 int xmin, xmax, ymin, ymax;
605    
606 gregl 3.2 if (odev.hres == 0 || odev.vres == 0) /* first exposure */
607     resizewindow((XConfigureEvent *)eexp);
608 gregl 3.4 xmin = eexp->x; xmax = eexp->x + eexp->width;
609     ymin = odev.vres - eexp->y - eexp->height; ymax = odev.vres - eexp->y;
610     /* clear portion of depth */
611     glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
612     glDepthFunc(GL_ALWAYS);
613     glBegin(GL_POLYGON);
614     glVertex3d((double)xmin/odev.hres, (double)ymin/odev.vres, 0.);
615     glVertex3d((double)xmax/odev.hres, (double)ymin/odev.vres, 0.);
616     glVertex3d((double)xmax/odev.hres, (double)ymax/odev.vres, 0.);
617     glVertex3d((double)xmin/odev.hres, (double)ymax/odev.vres, 0.);
618     glEnd();
619     glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
620     glDepthFunc(GL_LEQUAL);
621     qtRedraw(xmin, ymin, xmax, ymax);
622 gregl 3.1 }
623    
624    
625     static
626     resizewindow(ersz) /* resize window */
627     register XConfigureEvent *ersz;
628     {
629 gregl 3.6 glViewport(0, 0, ersz->width, ersz->height);
630    
631 gregl 3.1 if (ersz->width == odev.hres && ersz->height == odev.vres)
632     return;
633    
634     odev.hres = ersz->width;
635     odev.vres = ersz->height;
636    
637     odev.v.horiz = 2.*180./PI * atan(0.5/VIEWDIST*pwidth*odev.hres);
638     odev.v.vert = 2.*180./PI * atan(0.5/VIEWDIST*pheight*odev.vres);
639    
640     inpresflags |= DFL(DC_SETVIEW);
641     }