ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/hd/rhd_glx1.c
Revision: 3.3
Committed: Thu Jan 1 11:21:55 2004 UTC (20 years, 3 months ago) by schorsch
Content type: text/plain
Branch: MAIN
Changes since 3.2: +91 -59 lines
Log Message:
Ansification and prototypes.

File Contents

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