ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/hd/rhd_glx1.c
Revision: 3.7
Committed: Fri May 20 02:06:39 2011 UTC (12 years, 10 months ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad4R1
Changes since 3.6: +3 -3 lines
Log Message:
Changed every instance of BYTE to uby8 to avoid conflicts

File Contents

# User Rev Content
1 greg 3.1 #ifndef lint
2 greg 3.7 static const char RCSid[] = "$Id: rhd_glx1.c,v 3.6 2006/06/07 17:52:04 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 schorsch 3.6 char *gfn,
290     char *pfn
291 schorsch 3.3 )
292 greg 3.1 {
293     /* unimplemented */
294     }
295    
296    
297 schorsch 3.3 extern void
298     dev_auxcom( /* process an auxiliary command */
299     char *cmd,
300     char *args
301     )
302 greg 3.1 {
303     sprintf(errmsg, "%s: unknown command", cmd);
304     error(COMMAND, errmsg);
305     }
306    
307    
308 schorsch 3.3 extern VIEW *
309     dev_auxview( /* return nth auxiliary view */
310     int n,
311     int hvres[2]
312     )
313 greg 3.1 {
314     if (n)
315     return(NULL);
316     hvres[0] = odev.hres; hvres[1] = odev.vres;
317     return(&odev.v);
318     }
319    
320    
321 schorsch 3.3 extern int
322     dev_input(void) /* get X11 input */
323 greg 3.1 {
324     inpresflags = 0;
325    
326     do
327     getevent();
328    
329     while (XQLength(ourdisplay) > 0);
330    
331     return(inpresflags);
332     }
333    
334    
335 schorsch 3.3 extern int
336     dev_flush(void) /* flush output */
337 greg 3.1 {
338     qtUpdate();
339     glFlush();
340     rayqleft = RAYQLEN;
341     return(XPending(ourdisplay));
342     }
343    
344    
345 schorsch 3.3 extern void
346     dev_cone( /* render a cone in view coordinates */
347 greg 3.7 uby8 rgb[3],
348 schorsch 3.3 FVECT ip,
349     double rad
350     )
351 greg 3.1 {
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 schorsch 3.3 mytmflags(void) /* figure out tone mapping flags */
388 greg 3.1 {
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 schorsch 3.3 return -1; /* pro forma return */
403 greg 3.1 }
404    
405    
406 schorsch 3.3 static void
407     initcones(void) /* initialize cone vertices */
408 greg 3.1 {
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 schorsch 3.3 static void
434     freecones(void) /* free cone vertices */
435 greg 3.1 {
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 schorsch 3.3 static void
448     getevent(void) /* get next event */
449 greg 3.1 {
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 schorsch 3.3 static void
475     draw3dline( /* draw 3d line in world coordinates */
476     register FVECT wp[2]
477     )
478 greg 3.1 {
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 schorsch 3.3 static void
485     draw_grids(void) /* draw holodeck section grids */
486 greg 3.1 {
487 greg 3.7 static uby8 gridrgba[4] = {0x0, 0xff, 0xff, 0x00};
488 greg 3.1 double xmin, xmax, ymin, ymax, zmin, zmax;
489 schorsch 3.3 double d;
490 greg 3.1 /* 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 schorsch 3.3 static int
531     moveview( /* move our view */
532     int dx,
533     int dy,
534     int mov,
535     int orb
536     )
537 greg 3.1 {
538     VIEW nv;
539     FVECT odir, v1;
540     double d;
541     register int li;
542     /* start with old view */
543 schorsch 3.2 nv = odev.v;
544 greg 3.1 /* 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     fcross(v1, odir, nv.vup);
560     if (normalize(v1) == 0.)
561     return(0);
562     spinvector(odir, odir, v1, d=MOVDEG*PI/180.*orb);
563     VSUM(nv.vp, qtL.wp[li], odir, -1.);
564     spinvector(nv.vdir, nv.vdir, v1, d);
565     } else if (mov) { /* move forward/backward */
566     d = MOVPCT/100. * mov;
567     VSUM(nv.vp, nv.vp, odir, d);
568     }
569     if (!mov ^ !orb && headlocked) { /* restore head height */
570     VSUM(v1, odev.v.vp, nv.vp, -1.);
571     d = DOT(v1, odev.v.vup);
572     VSUM(nv.vp, nv.vp, odev.v.vup, d);
573     }
574     if (setview(&nv) != NULL)
575     return(0); /* illegal view */
576     dev_view(&nv);
577     inpresflags |= DFL(DC_SETVIEW);
578     return(1);
579     }
580    
581    
582 schorsch 3.3 static void
583     getmove( /* get view change */
584     XButtonPressedEvent *ebut
585     )
586 greg 3.1 {
587     int movdir = MOVDIR(ebut->button);
588     int movorb = MOVORB(ebut->state);
589     int oldnodesiz = qtMinNodesiz;
590     Window rootw, childw;
591     int rootx, rooty, wx, wy;
592     unsigned int statemask;
593    
594     qtMinNodesiz = 24; /* accelerate update rate */
595     XNoOp(ourdisplay);
596    
597     while (!XCheckMaskEvent(ourdisplay,
598     ButtonReleaseMask, levptr(XEvent))) {
599    
600     if (!XQueryPointer(ourdisplay, gwind, &rootw, &childw,
601     &rootx, &rooty, &wx, &wy, &statemask))
602     break; /* on another screen */
603    
604     if (!moveview(wx, odev.vres-1-wy, movdir, movorb)) {
605     sleep(1);
606     continue;
607     }
608     glClear(GL_COLOR_BUFFER_BIT);
609     qtUpdate();
610     draw_grids();
611     glFlush();
612     }
613     if (!(inpresflags & DFL(DC_SETVIEW))) { /* do final motion */
614     movdir = MOVDIR(levptr(XButtonReleasedEvent)->button);
615     wx = levptr(XButtonReleasedEvent)->x;
616     wy = levptr(XButtonReleasedEvent)->y;
617     moveview(wx, odev.vres-1-wy, movdir, movorb);
618     }
619     dev_flush();
620    
621     qtMinNodesiz = oldnodesiz; /* restore quadtree resolution */
622     }
623    
624    
625 schorsch 3.3 static void
626     getkey( /* get input key */
627     register XKeyPressedEvent *ekey
628     )
629 greg 3.1 {
630     int n;
631     char buf[8];
632    
633     n = XLookupString(ekey, buf, sizeof(buf), NULL, NULL);
634     if (n != 1)
635     return;
636     switch (buf[0]) {
637     case 'h': /* turn on height motion lock */
638     headlocked = 1;
639     return;
640     case 'H': /* turn off height motion lock */
641     headlocked = 0;
642     return;
643     case 'l': /* retrieve last view */
644     inpresflags |= DFL(DC_LASTVIEW);
645     return;
646     case 'p': /* pause computation */
647     inpresflags |= DFL(DC_PAUSE);
648     return;
649     case 'v': /* spit out view */
650     inpresflags |= DFL(DC_GETVIEW);
651     return;
652     case '\n':
653     case '\r': /* resume computation */
654     inpresflags |= DFL(DC_RESUME);
655     return;
656     case CTRL('R'): /* redraw screen */
657     if (nxtzmax > FTINY) {
658     curzmax = nxtzmax;
659     nxtzmax = 0.;
660     }
661     glClear(GL_DEPTH_BUFFER_BIT);
662     qtRedraw(0, 0, odev.hres, odev.vres);
663     return;
664     case CTRL('L'): /* refresh from server */
665     if (inpresflags & DFL(DC_REDRAW))
666     return;
667     if (nxtzmax > FTINY) {
668     curzmax = nxtzmax;
669     nxtzmax = 0.;
670     }
671     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
672     draw_grids();
673     glFlush();
674     qtCompost(100); /* get rid of old values */
675     inpresflags |= DFL(DC_REDRAW); /* resend values from server */
676     rayqleft = 0; /* hold off update */
677     return;
678     case 'K': /* kill rtrace process(es) */
679     inpresflags |= DFL(DC_KILL);
680     break;
681     case 'R': /* restart rtrace */
682     inpresflags |= DFL(DC_RESTART);
683     break;
684     case 'C': /* clobber holodeck */
685     inpresflags |= DFL(DC_CLOBBER);
686     break;
687     case 'q': /* quit the program */
688     inpresflags |= DFL(DC_QUIT);
689     return;
690     default:
691     XBell(ourdisplay, 0);
692     return;
693     }
694     }
695    
696    
697 schorsch 3.3 static void
698     fixwindow( /* repair damage to window */
699     register XExposeEvent *eexp
700     )
701 greg 3.1 {
702     int xmin, xmax, ymin, ymax;
703    
704     if (odev.hres == 0 || odev.vres == 0) /* first exposure */
705     resizewindow((XConfigureEvent *)eexp);
706     xmin = eexp->x; xmax = eexp->x + eexp->width;
707     ymin = odev.vres - eexp->y - eexp->height; ymax = odev.vres - eexp->y;
708     /* clear portion of depth */
709     glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
710     glDepthFunc(GL_ALWAYS);
711     glBegin(GL_POLYGON);
712     glVertex3d((double)xmin/odev.hres, (double)ymin/odev.vres, 0.);
713     glVertex3d((double)xmax/odev.hres, (double)ymin/odev.vres, 0.);
714     glVertex3d((double)xmax/odev.hres, (double)ymax/odev.vres, 0.);
715     glVertex3d((double)xmin/odev.hres, (double)ymax/odev.vres, 0.);
716     glEnd();
717     glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
718     glDepthFunc(GL_LEQUAL);
719     qtRedraw(xmin, ymin, xmax, ymax);
720     }
721    
722    
723 schorsch 3.3 static void
724     resizewindow( /* resize window */
725     register XConfigureEvent *ersz
726     )
727 greg 3.1 {
728     glViewport(0, 0, ersz->width, ersz->height);
729    
730     if (ersz->width == odev.hres && ersz->height == odev.vres)
731     return;
732    
733     odev.hres = ersz->width;
734     odev.vres = ersz->height;
735    
736     odev.v.horiz = 2.*180./PI * atan(0.5/VIEWDIST*pwidth*odev.hres);
737     odev.v.vert = 2.*180./PI * atan(0.5/VIEWDIST*pheight*odev.vres);
738    
739     inpresflags |= DFL(DC_SETVIEW);
740     }