ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/hd/rhd_glx1.c
Revision: 3.4
Committed: Sun Mar 28 20:33:13 2004 UTC (20 years ago) by schorsch
Content type: text/plain
Branch: MAIN
CVS Tags: rad3R6, rad3R6P1
Changes since 3.3: +2 -1 lines
Log Message:
Continued ANSIfication, and other fixes and clarifications.

File Contents

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