ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/hd/rhd_glx1.c
Revision: 3.8
Committed: Thu Sep 6 00:07:43 2012 UTC (11 years, 6 months ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad4R2P2, rad5R0, rad4R2, rad4R2P1
Changes since 3.7: +4 -5 lines
Log Message:
Created geodesic() function for vector rotation along great circles

File Contents

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