ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/hd/rhd_glx.c
Revision: 3.18
Committed: Wed Jun 17 15:44:07 1998 UTC (25 years, 10 months ago) by gwlarson
Content type: text/plain
Branch: MAIN
Changes since 3.17: +9 -1 lines
Log Message:
added dev_auxcom() for auxiliary command handling

File Contents

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