ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/hd/rhd_glx1.c
Revision: 3.5
Committed: Fri Jan 7 20:33:02 2005 UTC (19 years, 3 months ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad3R7P2, rad3R7P1
Changes since 3.4: +6 -3 lines
Log Message:
Modernized tone-mapping routines with structure pointer r.t. stack

File Contents

# User Rev Content
1 greg 3.1 #ifndef lint
2 greg 3.5 static const char RCSid[] = "$Id: rhd_glx1.c,v 3.4 2004/03/28 20:33:13 schorsch Exp $";
3 greg 3.1 #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 schorsch 3.3 #include <GL/glu.h>
13 greg 3.1
14 schorsch 3.4 #include "platform.h"
15 greg 3.1 #include "rhd_qtree.h"
16 schorsch 3.3 #include "rhdriver.h"
17     #include "rhdisp.h"
18 greg 3.1 #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 greg 3.5 TMstruct *tmGlobal; /* global tone-mapping structure */
65    
66 greg 3.1 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 schorsch 3.3 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 greg 3.1 {
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 greg 3.5 tmGlobal = tmInit(mytmflags(), dpri, gamval);
148     if (tmGlobal == NULL)
149 greg 3.1 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 schorsch 3.2 odev.v = stdview;
191 greg 3.1 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 schorsch 3.3 extern void
208     dev_close(void) /* close our display and free resources */
209 greg 3.1 {
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 greg 3.5 tmDone(tmGlobal);
218 greg 3.1 freecones();
219     odev.v.type = 0;
220     odev.hres = odev.vres = 0;
221     odev.ifd = -1;
222     }
223    
224    
225 schorsch 3.3 extern void
226     dev_clear(void) /* clear our quadtree */
227 greg 3.1 {
228     qtCompost(100);
229     glClear(GL_DEPTH_BUFFER_BIT);
230     rayqleft = 0; /* hold off update */
231     }
232    
233    
234 schorsch 3.3 extern int
235     dev_view( /* assign new driver view */
236     register VIEW *nv
237     )
238 greg 3.1 {
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 schorsch 3.2 odev.v = *nv;
276 greg 3.1 }
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 schorsch 3.3 extern void
288     dev_section( /* add octree for geometry rendering */
289     char *ofn
290     )
291 greg 3.1 {
292     /* unimplemented */
293     }
294    
295    
296 schorsch 3.3 extern void
297     dev_auxcom( /* process an auxiliary command */
298     char *cmd,
299     char *args
300     )
301 greg 3.1 {
302     sprintf(errmsg, "%s: unknown command", cmd);
303     error(COMMAND, errmsg);
304     }
305    
306    
307 schorsch 3.3 extern VIEW *
308     dev_auxview( /* return nth auxiliary view */
309     int n,
310     int hvres[2]
311     )
312 greg 3.1 {
313     if (n)
314     return(NULL);
315     hvres[0] = odev.hres; hvres[1] = odev.vres;
316     return(&odev.v);
317     }
318    
319    
320 schorsch 3.3 extern int
321     dev_input(void) /* get X11 input */
322 greg 3.1 {
323     inpresflags = 0;
324    
325     do
326     getevent();
327    
328     while (XQLength(ourdisplay) > 0);
329    
330     return(inpresflags);
331     }
332    
333    
334 schorsch 3.3 extern int
335     dev_flush(void) /* flush output */
336 greg 3.1 {
337     qtUpdate();
338     glFlush();
339     rayqleft = RAYQLEN;
340     return(XPending(ourdisplay));
341     }
342    
343    
344 schorsch 3.3 extern void
345     dev_cone( /* render a cone in view coordinates */
346     BYTE rgb[3],
347     FVECT ip,
348     double rad
349     )
350 greg 3.1 {
351     register int ci, j;
352     double apexh, basez;
353     /* is window mapped? */
354     if (!mapped)
355     return;
356     /* compute apex height (0. to 1.) */
357     if (ip[2] > 1e6)
358     apexh = 1. - 1./DEPTHFACT;
359     else {
360     if (ip[2] > nxtzmax)
361     nxtzmax = ip[2];
362     if (ip[2] >= curzmax)
363     apexh = 1. - 1./DEPTHFACT;
364     else
365     apexh = 1. - ip[2]/(curzmax*DEPTHFACT);
366     }
367     rad *= 1.25; /* find conservative cone match */
368     for (ci = 0; ci < MAXCONE-1; ci++)
369     if (cone[ci].rad >= rad)
370     break;
371     /* draw it */
372     glColor3ub(rgb[0], rgb[1], rgb[2]);
373     glBegin(GL_TRIANGLE_FAN);
374     glVertex3d(ip[0], ip[1], apexh); /* start with apex */
375     basez = apexh*cone[ci].va[0][2]; /* base z's all the same */
376     for (j = 0; j < cone[ci].nverts; j++) /* draw each face */
377     glVertex3d(ip[0]+cone[ci].va[j][0], ip[1]+cone[ci].va[j][1],
378     basez);
379     /* connect last to first */
380     glVertex3d(ip[0]+cone[ci].va[0][0], ip[1]+cone[ci].va[0][1], basez);
381     glEnd(); /* all done */
382     }
383    
384    
385     static int
386 schorsch 3.3 mytmflags(void) /* figure out tone mapping flags */
387 greg 3.1 {
388     extern char *progname;
389     register char *cp, *tail;
390     /* find basic name */
391     for (cp = tail = progname; *cp; cp++)
392     if (*cp == '/')
393     tail = cp+1;
394     for (cp = tail; *cp && *cp != '.'; cp++)
395     ;
396     if (cp-tail == 4 && !strncmp(tail, "glx1", 4))
397     return(TM_F_CAMERA|TM_F_NOSTDERR);
398     if (cp-tail == 5 && !strncmp(tail, "glx1h", 5))
399     return(TM_F_HUMAN|TM_F_NOSTDERR);
400     error(USER, "illegal driver name");
401 schorsch 3.3 return -1; /* pro forma return */
402 greg 3.1 }
403    
404    
405 schorsch 3.3 static void
406     initcones(void) /* initialize cone vertices */
407 greg 3.1 {
408     register int i, j;
409     double minrad, d;
410    
411     if (cone[0].nverts)
412     freecones();
413     minrad = 2.*qtMinNodesiz/(double)(DisplayWidth(ourdisplay,ourscreen) +
414     DisplayHeight(ourdisplay,ourscreen));
415     for (i = 0; i < MAXCONE; i++) {
416     d = (double)i/(MAXCONE-1); d *= d; /* x^2 distribution */
417     cone[i].rad = minrad + (1.-minrad)*d;
418     cone[i].nverts = MINVERT + 0.5 + (MAXVERT-MINVERT)*d;
419     cone[i].va = (FVECT *)malloc(cone[i].nverts*sizeof(FVECT));
420     if (cone[i].va == NULL)
421     error(SYSTEM, "out of memory in initcones");
422     for (j = cone[i].nverts; j--; ) {
423     d = 2.*PI * (j+.5) / (cone[i].nverts);
424     cone[i].va[j][0] = cos(d) * cone[i].rad;
425     cone[i].va[j][1] = sin(d) * cone[i].rad;
426     cone[i].va[j][2] = 1. - cone[i].rad;
427     }
428     }
429     }
430    
431    
432 schorsch 3.3 static void
433     freecones(void) /* free cone vertices */
434 greg 3.1 {
435     register int i;
436    
437     for (i = MAXCONE; i--; )
438     if (cone[i].nverts) {
439     free((void *)cone[i].va);
440     cone[i].va = NULL;
441     cone[i].nverts = 0;
442     }
443     }
444    
445    
446 schorsch 3.3 static void
447     getevent(void) /* get next event */
448 greg 3.1 {
449     XNextEvent(ourdisplay, levptr(XEvent));
450     switch (levptr(XEvent)->type) {
451     case ConfigureNotify:
452     resizewindow(levptr(XConfigureEvent));
453     break;
454     case UnmapNotify:
455     mapped = 0;
456     break;
457     case MapNotify:
458     mapped = 1;
459     break;
460     case Expose:
461     fixwindow(levptr(XExposeEvent));
462     break;
463     case KeyPress:
464     getkey(levptr(XKeyPressedEvent));
465     break;
466     case ButtonPress:
467     getmove(levptr(XButtonPressedEvent));
468     break;
469     }
470     }
471    
472    
473 schorsch 3.3 static void
474     draw3dline( /* draw 3d line in world coordinates */
475     register FVECT wp[2]
476     )
477 greg 3.1 {
478     glVertex3d(wp[0][0], wp[0][1], wp[0][2]);
479     glVertex3d(wp[1][0], wp[1][1], wp[1][2]);
480     }
481    
482    
483 schorsch 3.3 static void
484     draw_grids(void) /* draw holodeck section grids */
485 greg 3.1 {
486     static BYTE gridrgba[4] = {0x0, 0xff, 0xff, 0x00};
487     double xmin, xmax, ymin, ymax, zmin, zmax;
488 schorsch 3.3 double d;
489 greg 3.1 /* can we even do it? */
490     if (!mapped || odev.v.type != VT_PER)
491     return;
492     /* compute view frustum */
493     if (normalize(odev.v.vdir) == 0.0)
494     return;
495     zmin = 0.01;
496     zmax = 10000.;
497     if (odev.v.vfore > FTINY)
498     zmin = odev.v.vfore;
499     if (odev.v.vaft > FTINY)
500     zmax = odev.v.vaft;
501     xmax = zmin * tan(PI/180./2. * odev.v.horiz);
502     xmin = -xmax;
503     d = odev.v.hoff * (xmax - xmin);
504     xmin += d; xmax += d;
505     ymax = zmin * tan(PI/180./2. * odev.v.vert);
506     ymin = -ymax;
507     d = odev.v.voff * (ymax - ymin);
508     ymin += d; ymax += d;
509     /* set view matrix */
510     glMatrixMode(GL_PROJECTION);
511     glPushMatrix();
512     glLoadIdentity();
513     glFrustum(xmin, xmax, ymin, ymax, zmin, zmax);
514     gluLookAt(odev.v.vp[0], odev.v.vp[1], odev.v.vp[2],
515     odev.v.vp[0] + odev.v.vdir[0],
516     odev.v.vp[1] + odev.v.vdir[1],
517     odev.v.vp[2] + odev.v.vdir[2],
518     odev.v.vup[0], odev.v.vup[1], odev.v.vup[2]);
519     glDisable(GL_DEPTH_TEST); /* write no depth values */
520     glColor4ub(gridrgba[0], gridrgba[1], gridrgba[2], gridrgba[3]);
521     glBegin(GL_LINES); /* draw each grid line */
522     gridlines(draw3dline);
523     glEnd();
524     glEnable(GL_DEPTH_TEST); /* restore rendering params */
525     glPopMatrix();
526     }
527    
528    
529 schorsch 3.3 static int
530     moveview( /* move our view */
531     int dx,
532     int dy,
533     int mov,
534     int orb
535     )
536 greg 3.1 {
537     VIEW nv;
538     FVECT odir, v1;
539     double d;
540     register int li;
541     /* start with old view */
542 schorsch 3.2 nv = odev.v;
543 greg 3.1 /* change view direction */
544     if (mov | orb) {
545     if ((li = qtFindLeaf(dx, dy)) < 0)
546     return(0); /* not on window */
547     VSUM(odir, qtL.wp[li], nv.vp, -1.);
548     } else {
549     if (viewray(nv.vp, nv.vdir, &odev.v,
550     (dx+.5)/odev.hres, (dy+.5)/odev.vres) < -FTINY)
551     return(0); /* outside view */
552     }
553     if (orb && mov) { /* orbit left/right */
554     spinvector(odir, odir, nv.vup, d=MOVDEG*PI/180.*mov);
555     VSUM(nv.vp, qtL.wp[li], odir, -1.);
556     spinvector(nv.vdir, nv.vdir, nv.vup, d);
557     } else if (orb) { /* orbit up/down */
558     fcross(v1, odir, nv.vup);
559     if (normalize(v1) == 0.)
560     return(0);
561     spinvector(odir, odir, v1, d=MOVDEG*PI/180.*orb);
562     VSUM(nv.vp, qtL.wp[li], odir, -1.);
563     spinvector(nv.vdir, nv.vdir, v1, d);
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 schorsch 3.3 static void
582     getmove( /* get view change */
583     XButtonPressedEvent *ebut
584     )
585 greg 3.1 {
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 schorsch 3.3 static void
625     getkey( /* get input key */
626     register XKeyPressedEvent *ekey
627     )
628 greg 3.1 {
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 schorsch 3.3 static void
697     fixwindow( /* repair damage to window */
698     register XExposeEvent *eexp
699     )
700 greg 3.1 {
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 schorsch 3.3 static void
723     resizewindow( /* resize window */
724     register XConfigureEvent *ersz
725     )
726 greg 3.1 {
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     }