ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/hd/rhd_glx2.c
Revision: 3.1
Committed: Sat Feb 22 02:07:24 2003 UTC (21 years, 2 months ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad3R5
Log Message:
Changes and check-in for 3.5 release
Includes new source files and modifications not recorded for many years
See ray/doc/notes/ReleaseNotes for notes between 3.1 and 3.5 release

File Contents

# User Rev Content
1 greg 3.1 #ifndef lint
2     static const char RCSid[] = "$Id$";
3     #endif
4     /*
5     * OpenGL GLX driver for holodeck display.
6     * Based on standard GLX driver.
7     */
8    
9     #include "standard.h"
10     #include "rhd_sample.h"
11    
12     #include <sys/types.h>
13     #include <GL/glx.h>
14     #include <GL/glu.h>
15     #include <X11/extensions/SGIStereo.h>
16     #include <gl/get.h>
17    
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     #define GAMMA 1.4 /* default gamma correction */
29    
30     #define MOVPCT 7 /* percent distance to move /frame */
31     #define MOVDIR(b) ((b)==Button1 ? 1 : (b)==Button2 ? 0 : -1)
32     #define MOVDEG (-5) /* degrees to orbit CW/down /frame */
33     #define MOVORB(s) ((s)&ShiftMask ? 1 : (s)&ControlMask ? -1 : 0)
34    
35     #ifndef TARGETFPS
36     #define TARGETFPS 4.0 /* target frames/sec during motion */
37     #endif
38    
39     #define MINWIDTH 480 /* minimum stereo window width */
40     #define MINHEIGHT 400 /* minimum stereo window height */
41    
42     #define VIEWDIST 356 /* assumed viewing distance (mm) */
43    
44     #define BORWIDTH 5 /* border width */
45    
46     #define setstereobuf(bid) (glXWaitGL(), \
47     XSGISetStereoBuffer(ourdisplay, gwind, bid), \
48     glXWaitX())
49    
50     #define ourscreen DefaultScreen(ourdisplay)
51     #define ourroot RootWindow(ourdisplay,ourscreen)
52     #define ourmask (StructureNotifyMask|ExposureMask|KeyPressMask|\
53     ButtonPressMask|ButtonReleaseMask)
54    
55     #define levptr(etype) ((etype *)&currentevent)
56    
57     struct driver odev; /* global device driver structure */
58    
59     static VIEW vwright; /* right eye view */
60    
61     static int rayqleft = 0; /* rays left to queue before flush */
62    
63     static XEvent currentevent; /* current event */
64    
65     static int mapped = 0; /* window is mapped? */
66     static unsigned long ourblack=0, ourwhite=~0;
67    
68     static Display *ourdisplay = NULL; /* our display */
69     static XVisualInfo *ourvinf; /* our visual information */
70     static Window gwind = 0; /* our graphics window */
71     static GLXContext gctx; /* our GLX context */
72    
73     static double pwidth, pheight; /* pixel dimensions (mm) */
74    
75     static int inpresflags; /* input result flags */
76    
77     static int headlocked = 0; /* lock vertical motion */
78    
79     static int resizewindow(), getevent(), getkey(), moveview(), eyeview(),
80     wipeclean(), setglpersp(), getmove(), fixwindow(),
81     pushright(), popright(), mytmflags();
82    
83     extern time_t time();
84     extern long getmonitor();
85    
86    
87     dev_open(id) /* initialize GLX driver */
88     char *id;
89     {
90     extern char *getenv();
91     static RGBPRIMS myprims = STDPRIMS;
92     static int atlBest[] = {GLX_RGBA, GLX_RED_SIZE,8,
93     GLX_GREEN_SIZE,8, GLX_BLUE_SIZE,8,
94     GLX_DEPTH_SIZE,15, None};
95     char *ev;
96     double gamval = GAMMA;
97     RGBPRIMP dpri = stdprims;
98     int firstevent, firsterror;
99     XSetWindowAttributes ourwinattr;
100     XWMHints ourxwmhints;
101     XSizeHints oursizhints;
102     /* open display server */
103     ourdisplay = XOpenDisplay(NULL);
104     if (ourdisplay == NULL)
105     error(USER, "cannot open X-windows; DISPLAY variable set?\n");
106     switch (XSGIQueryStereoMode(ourdisplay, ourroot)) {
107     case STEREO_TOP:
108     case STEREO_BOTTOM:
109     break;
110     case STEREO_OFF:
111     error(USER,
112     "wrong video mode: run \"/usr/gfx/setmon -n STR_TOP\" first");
113     case X_STEREO_UNSUPPORTED:
114     error(USER, "stereo mode not supported on this screen");
115     default:
116     error(INTERNAL, "unknown stereo mode");
117     }
118     /* find a usable visual */
119     ourvinf = glXChooseVisual(ourdisplay, ourscreen, atlBest);
120     if (ourvinf == NULL)
121     error(USER, "no suitable visuals available");
122     /* get a context */
123     gctx = glXCreateContext(ourdisplay, ourvinf, NULL, GL_TRUE);
124     /* set gamma and tone mapping */
125     if ((ev = XGetDefault(ourdisplay, "radiance", "gamma")) != NULL
126     || (ev = getenv("DISPLAY_GAMMA")) != NULL)
127     gamval = atof(ev);
128     if ((ev = getenv("DISPLAY_PRIMARIES")) != NULL &&
129     sscanf(ev, "%f %f %f %f %f %f %f %f",
130     &myprims[RED][CIEX],&myprims[RED][CIEY],
131     &myprims[GRN][CIEX],&myprims[GRN][CIEY],
132     &myprims[BLU][CIEX],&myprims[BLU][CIEY],
133     &myprims[WHT][CIEX],&myprims[WHT][CIEY]) >= 6)
134     dpri = myprims;
135     if (tmInit(mytmflags(), dpri, gamval) == NULL)
136     error(SYSTEM, "not enough memory in dev_open");
137     /* open window */
138     ourwinattr.background_pixel = ourblack;
139     ourwinattr.border_pixel = ourblack;
140     ourwinattr.event_mask = ourmask;
141     /* this is stupid */
142     ourwinattr.colormap = XCreateColormap(ourdisplay, ourroot,
143     ourvinf->visual, AllocNone);
144     gwind = XCreateWindow(ourdisplay, ourroot, 0, 0,
145     DisplayWidth(ourdisplay,ourscreen)-2*BORWIDTH,
146     (DisplayHeight(ourdisplay,ourscreen)-2*BORWIDTH)/2,
147     BORWIDTH, ourvinf->depth, InputOutput, ourvinf->visual,
148     CWBackPixel|CWBorderPixel|CWColormap|CWEventMask, &ourwinattr);
149     if (gwind == 0)
150     error(SYSTEM, "cannot create window\n");
151     XStoreName(ourdisplay, gwind, id);
152     /* set window manager hints */
153     ourxwmhints.flags = InputHint|IconPixmapHint;
154     ourxwmhints.input = True;
155     ourxwmhints.icon_pixmap = XCreateBitmapFromData(ourdisplay,
156     gwind, x11icon_bits, x11icon_width, x11icon_height);
157     XSetWMHints(ourdisplay, gwind, &ourxwmhints);
158     oursizhints.min_width = MINWIDTH;
159     oursizhints.min_height = MINHEIGHT/2;
160     oursizhints.max_width = DisplayWidth(ourdisplay,ourscreen)-2*BORWIDTH;
161     oursizhints.max_height = (DisplayHeight(ourdisplay,ourscreen) -
162     2*BORWIDTH)/2;
163     oursizhints.flags = PMinSize|PMaxSize;
164     XSetNormalHints(ourdisplay, gwind, &oursizhints);
165     /* set GLX context */
166     glXMakeCurrent(ourdisplay, gwind, gctx);
167     glEnable(GL_DEPTH_TEST);
168     glDepthFunc(GL_LEQUAL);
169     glShadeModel(GL_SMOOTH);
170     glDisable(GL_DITHER);
171     glDisable(GL_CULL_FACE);
172     /* figure out sensible view */
173     pwidth = (double)DisplayWidthMM(ourdisplay, ourscreen) /
174     DisplayWidth(ourdisplay, ourscreen);
175     pheight = 2.0 * (double)DisplayHeightMM(ourdisplay, ourscreen) /
176     DisplayHeight(ourdisplay, ourscreen);
177     copystruct(&odev.v, &stdview);
178     odev.v.type = VT_PER;
179     /* map the window */
180     setstereobuf(STEREO_BUFFER_LEFT);
181     XMapWindow(ourdisplay, gwind);
182     dev_input(); /* sets size and view angles */
183     /* allocate our samples */
184     if (!smInit(DisplayWidth(ourdisplay,ourscreen) *
185     DisplayHeight(ourdisplay,ourscreen) / 10))
186     error(SYSTEM, "insufficient memory for value storage");
187     odev.name = id;
188     odev.ifd = ConnectionNumber(ourdisplay);
189     }
190    
191    
192     dev_close() /* close our display and free resources */
193     {
194     smInit(0);
195     glXMakeCurrent(ourdisplay, None, NULL);
196     glXDestroyContext(ourdisplay, gctx);
197     XDestroyWindow(ourdisplay, gwind);
198     gwind = 0;
199     XCloseDisplay(ourdisplay);
200     ourdisplay = NULL;
201     tmDone(NULL);
202     odev.v.type = 0;
203     odev.hres = odev.vres = 0;
204     odev.ifd = -1;
205     }
206    
207    
208     dev_clear() /* clear our representation */
209     {
210     smInit(rsL.maxsamp);
211     wipeclean();
212     rayqleft = 0; /* hold off update */
213     }
214    
215    
216     int
217     dev_view(nv) /* assign new driver view */
218     register VIEW *nv;
219     {
220     double d;
221    
222     if (nv->type != VT_PER || /* check view legality */
223     nv->horiz > 160. || nv->vert > 160.) {
224     error(COMMAND, "illegal view type/angle");
225     nv->type = odev.v.type;
226     nv->horiz = odev.v.horiz;
227     nv->vert = odev.v.vert;
228     return(0);
229     }
230     if (nv != &odev.v) {
231     if (!FEQ(nv->horiz,odev.v.horiz) || /* resize window? */
232     !FEQ(nv->vert,odev.v.vert)) {
233     int dw = DisplayWidth(ourdisplay,ourscreen);
234     int dh = DisplayHeight(ourdisplay,ourscreen)/2;
235    
236     dw -= 25; /* for window frame */
237     dh -= 50*2;
238     odev.hres = 2.*VIEWDIST/pwidth *
239     tan(PI/180./2.*nv->horiz);
240     odev.vres = 2.*VIEWDIST/pheight *
241     tan(PI/180./2.*nv->vert);
242     if (odev.hres > dw) {
243     odev.vres = dw * odev.vres / odev.hres;
244     odev.hres = dw;
245     }
246     if (odev.vres > dh) {
247     odev.hres = dh * odev.hres / odev.vres;
248     odev.vres = dh;
249     }
250     XResizeWindow(ourdisplay, gwind, odev.hres, odev.vres);
251     dev_input(); /* get resize event */
252     }
253     copystruct(&odev.v, nv); /* setview() already called */
254     setglpersp(&odev.v);
255     copystruct(&vwright, nv);
256     d = eyesepdist / sqrt(nv->hn2);
257     VSUM(vwright.vp, nv->vp, nv->hvec, d);
258     /* setview(&vwright); -- Unnecessary */
259     checkglerr("setting view");
260     }
261     wipeclean();
262     return(1);
263     }
264    
265    
266     dev_auxcom(cmd, args) /* process an auxiliary command */
267     char *cmd, *args;
268     {
269     sprintf(errmsg, "%s: unknown command", cmd);
270     error(COMMAND, errmsg);
271     }
272    
273    
274     VIEW *
275     dev_auxview(n, hvres) /* return nth auxiliary view */
276     int n;
277     int hvres[2];
278     {
279     hvres[0] = odev.hres; hvres[1] = odev.vres;
280     if (n == 0)
281     return(&odev.v);
282     if (n == 1)
283     return(&vwright);
284     return(NULL);
285     }
286    
287    
288     int
289     dev_input() /* get X11 input */
290     {
291     inpresflags = 0;
292    
293     do
294     getevent();
295    
296     while (XQLength(ourdisplay) > 0);
297    
298     return(inpresflags);
299     }
300    
301    
302     dev_value(c, p, v) /* add a pixel value to our quadtree */
303     COLR c;
304     FVECT p, v;
305     {
306     smNewsamp(c, p, v); /* add to display representation */
307     if (!--rayqleft)
308     dev_flush(); /* flush output */
309     }
310    
311    
312     int
313     dev_flush() /* flush output */
314     {
315     pushright(); /* update right eye */
316     glClear(GL_DEPTH_BUFFER_BIT);
317     smUpdate(&vwright, 100);
318     popright(); /* update left eye */
319     glClear(GL_DEPTH_BUFFER_BIT);
320     smUpdate(&odev.v, 100);
321     glFlush(); /* flush OGL */
322     checkglerr("flushing display");
323     rayqleft = RAYQLEN;
324     return(XPending(ourdisplay)); /* flush X11 and return # pending */
325     }
326    
327    
328     checkglerr(where) /* check for GL or GLU error */
329     char *where;
330     {
331     register GLenum errcode;
332    
333     while ((errcode = glGetError()) != GL_NO_ERROR) {
334     sprintf(errmsg, "OpenGL error %s: %s",
335     where, gluErrorString(errcode));
336     error(WARNING, errmsg);
337     }
338     }
339    
340    
341     static
342     pushright() /* push on right view */
343     {
344     double d;
345    
346     setstereobuf(STEREO_BUFFER_RIGHT);
347     glMatrixMode(GL_MODELVIEW);
348     glPushMatrix();
349     d = -eyesepdist / sqrt(odev.v.hn2);
350     glTranslated(d*odev.v.hvec[0], d*odev.v.hvec[1], d*odev.v.hvec[2]);
351     }
352    
353    
354     static
355     popright() /* pop off right view */
356     {
357     glMatrixMode(GL_MODELVIEW);
358     glPopMatrix();
359     setstereobuf(STEREO_BUFFER_LEFT);
360     }
361    
362    
363     static int
364     mytmflags() /* figure out tone mapping flags */
365     {
366     extern char *progname;
367     register char *cp, *tail;
368     /* find basic name */
369     for (cp = tail = progname; *cp; cp++)
370     if (*cp == '/')
371     tail = cp+1;
372     for (cp = tail; *cp && *cp != '.'; cp++)
373     ;
374     if (cp-tail == 3 && !strncmp(tail, "glx2", 3))
375     return(TM_F_CAMERA|TM_F_NOSTDERR);
376     if (cp-tail == 4 && !strncmp(tail, "glx2h", 4))
377     return(TM_F_HUMAN|TM_F_NOSTDERR);
378     error(USER, "illegal driver name");
379     }
380    
381    
382     static
383     getevent() /* get next event */
384     {
385     XNextEvent(ourdisplay, levptr(XEvent));
386     switch (levptr(XEvent)->type) {
387     case ConfigureNotify:
388     resizewindow(levptr(XConfigureEvent));
389     break;
390     case UnmapNotify:
391     mapped = 0;
392     break;
393     case MapNotify:
394     mapped = 1;
395     break;
396     case Expose:
397     fixwindow(levptr(XExposeEvent));
398     break;
399     case KeyPress:
400     getkey(levptr(XKeyPressedEvent));
401     break;
402     case ButtonPress:
403     getmove(levptr(XButtonPressedEvent));
404     break;
405     }
406     }
407    
408    
409     static
410     draw3dline(wp) /* draw 3d line in world coordinates */
411     register FVECT wp[2];
412     {
413     glVertex3d(wp[0][0], wp[0][1], wp[0][2]);
414     glVertex3d(wp[1][0], wp[1][1], wp[1][2]);
415     }
416    
417    
418     static
419     draw_grids() /* draw holodeck section grids */
420     {
421     static BYTE gridrgba[4] = {0x0, 0xff, 0xff, 0x00};
422    
423     if (!mapped)
424     return;
425     glColor4ub(gridrgba[0], gridrgba[1], gridrgba[2], gridrgba[3]);
426     glBegin(GL_LINES); /* draw each grid line */
427     gridlines(draw3dline);
428     glEnd();
429     }
430    
431    
432     static
433     moveview(dx, dy, mov, orb) /* move our view */
434     int dx, dy, mov, orb;
435     {
436     VIEW nv;
437     FVECT odir, v1;
438     double d;
439     register int li;
440     /* start with old view */
441     copystruct(&nv, &odev.v);
442     /* change view direction */
443     if (viewray(v1, odir, &odev.v,
444     (dx+.5)/odev.hres, (dy+.5)/odev.vres) < -FTINY)
445     return(0); /* outside view */
446     if (mov | orb) {
447     if ((li = smFindsamp(v1, odir)) < 0)
448     return(0); /* not on window */
449     VSUM(odir, rsL.wp[li], nv.vp, -1.);
450     } else
451     VCOPY(nv.vdir, odir);
452     if (orb && mov) { /* orbit left/right */
453     spinvector(odir, odir, nv.vup, d=MOVDEG*PI/180.*mov);
454     VSUM(nv.vp, rsL.wp[li], odir, -1.);
455     spinvector(nv.vdir, nv.vdir, nv.vup, d);
456     } else if (orb) { /* orbit up/down */
457     fcross(v1, odir, nv.vup);
458     if (normalize(v1) == 0.)
459     return(0);
460     spinvector(odir, odir, v1, d=MOVDEG*PI/180.*orb);
461     VSUM(nv.vp, rsL.wp[li], odir, -1.);
462     spinvector(nv.vdir, nv.vdir, v1, d);
463     } else if (mov) { /* move forward/backward */
464     d = MOVPCT/100. * mov;
465     VSUM(nv.vp, nv.vp, odir, d);
466     }
467     if (!mov ^ !orb && headlocked) { /* restore head height */
468     VSUM(v1, odev.v.vp, nv.vp, -1.);
469     d = DOT(v1, odev.v.vup);
470     VSUM(nv.vp, nv.vp, odev.v.vup, d);
471     }
472     if (setview(&nv) != NULL)
473     return(0); /* illegal view */
474     dev_view(&nv);
475     inpresflags |= DFL(DC_SETVIEW);
476     return(1);
477     }
478    
479    
480     static
481     getmove(ebut) /* get view change */
482     XButtonPressedEvent *ebut;
483     {
484     int movdir = MOVDIR(ebut->button);
485     int movorb = MOVORB(ebut->state);
486     int qlevel = 100;
487     time_t lasttime, thistime;
488     int nframes;
489     Window rootw, childw;
490     int rootx, rooty, wx, wy;
491     unsigned int statemask;
492    
493     XNoOp(ourdisplay);
494    
495     lasttime = time(0); nframes = 0;
496     while (!XCheckMaskEvent(ourdisplay,
497     ButtonReleaseMask, levptr(XEvent))) {
498    
499     if (!XQueryPointer(ourdisplay, gwind, &rootw, &childw,
500     &rootx, &rooty, &wx, &wy, &statemask))
501     break; /* on another screen */
502    
503     if (!moveview(wx, odev.vres-1-wy, movdir, movorb)) {
504     sleep(1);
505     lasttime++;
506     continue;
507     }
508     pushright();
509     draw_grids();
510     smUpdate(&vwright, qlevel);
511     popright();
512     draw_grids();
513     smUpdate(&odev.v, qlevel);
514     glFlush();
515     checkglerr("moving view");
516     nframes++;
517     thistime = time(0);
518     if (thistime - lasttime >= 3 ||
519     nframes > (int)(3*3*TARGETFPS)) {
520     qlevel = thistime<=lasttime ? 1000 :
521     (int)((double)nframes/(thistime-lasttime)
522     / TARGETFPS * qlevel + 0.5);
523     lasttime = thistime; nframes = 0;
524     if (qlevel > 100) {
525     if (qlevel > 300) { /* put on the brakes */
526     sleep(1);
527     lasttime++;
528     }
529     qlevel = 100;
530     } else if (qlevel < 1)
531     qlevel = 1;
532     }
533     }
534     if (!(inpresflags & DFL(DC_SETVIEW))) { /* do final motion */
535     movdir = MOVDIR(levptr(XButtonReleasedEvent)->button);
536     wx = levptr(XButtonReleasedEvent)->x;
537     wy = levptr(XButtonReleasedEvent)->y;
538     moveview(wx, odev.vres-1-wy, movdir, movorb);
539     }
540     }
541    
542    
543     static
544     setglpersp(vp) /* set perspective view in GL */
545     register VIEW *vp;
546     {
547     double d, xmin, xmax, ymin, ymax, zmin, zmax;
548    
549     zmin = 0.1;
550     zmax = 1000.;
551     if (odev.v.vfore > FTINY)
552     zmin = odev.v.vfore;
553     if (odev.v.vaft > FTINY)
554     zmax = odev.v.vaft;
555     xmax = zmin * tan(PI/180./2. * odev.v.horiz);
556     xmin = -xmax;
557     d = odev.v.hoff * (xmax - xmin);
558     xmin += d; xmax += d;
559     ymax = zmin * tan(PI/180./2. * odev.v.vert);
560     ymin = -ymax;
561     d = odev.v.voff * (ymax - ymin);
562     ymin += d; ymax += d;
563     /* set view matrix */
564     glMatrixMode(GL_PROJECTION);
565     glLoadIdentity();
566     glFrustum(xmin, xmax, ymin, ymax, zmin, zmax);
567     gluLookAt(odev.v.vp[0], odev.v.vp[1], odev.v.vp[2],
568     odev.v.vp[0] + odev.v.vdir[0],
569     odev.v.vp[1] + odev.v.vdir[1],
570     odev.v.vp[2] + odev.v.vdir[2],
571     odev.v.vup[0], odev.v.vup[1], odev.v.vup[2]);
572     }
573    
574    
575     wipeclean() /* prepare for redraw */
576     {
577     setstereobuf(STEREO_BUFFER_RIGHT);
578     glClear(GL_DEPTH_BUFFER_BIT);
579     setstereobuf(STEREO_BUFFER_LEFT);
580     glClear(GL_DEPTH_BUFFER_BIT);
581     smClean();
582     }
583    
584    
585     static
586     getkey(ekey) /* get input key */
587     register XKeyPressedEvent *ekey;
588     {
589     int n;
590     char buf[8];
591    
592     n = XLookupString(ekey, buf, sizeof(buf), NULL, NULL);
593     if (n != 1)
594     return;
595     switch (buf[0]) {
596     case 'h': /* turn on height motion lock */
597     headlocked = 1;
598     return;
599     case 'H': /* turn off height motion lock */
600     headlocked = 0;
601     return;
602     case 'l': /* retrieve last view */
603     inpresflags |= DFL(DC_LASTVIEW);
604     return;
605     case 'p': /* pause computation */
606     inpresflags |= DFL(DC_PAUSE);
607     return;
608     case 'v': /* spit out view */
609     inpresflags |= DFL(DC_GETVIEW);
610     return;
611     case '\n':
612     case '\r': /* resume computation */
613     inpresflags |= DFL(DC_RESUME);
614     return;
615     case CTRL('R'): /* redraw screen */
616     wipeclean();
617     return;
618     case CTRL('L'): /* refresh from server */
619     if (inpresflags & DFL(DC_REDRAW))
620     return;
621     eyeview(VWRIGHT);
622     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
623     draw_grids();
624     eyeview(VWLEFT);
625     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
626     draw_grids();
627     glFlush();
628     smInit(rsL.maxsamp); /* get rid of old values */
629     inpresflags |= DFL(DC_REDRAW); /* resend values from server */
630     rayqleft = 0; /* hold off update */
631     return;
632     case 'K': /* kill rtrace process(es) */
633     inpresflags |= DFL(DC_KILL);
634     break;
635     case 'R': /* restart rtrace */
636     inpresflags |= DFL(DC_RESTART);
637     break;
638     case 'C': /* clobber holodeck */
639     inpresflags |= DFL(DC_CLOBBER);
640     break;
641     case 'q': /* quit the program */
642     inpresflags |= DFL(DC_QUIT);
643     return;
644     default:
645     XBell(ourdisplay, 0);
646     return;
647     }
648     }
649    
650    
651     static
652     fixwindow(eexp) /* repair damage to window */
653     register XExposeEvent *eexp;
654     {
655     if (odev.hres == 0 | odev.vres == 0) { /* first exposure */
656     resizewindow((XConfigureEvent *)eexp);
657     return;
658     }
659     if (eexp->count) /* wait for final exposure */
660     return;
661     wipeclean(); /* clear depth */
662     }
663    
664    
665     static
666     resizewindow(ersz) /* resize window */
667     register XConfigureEvent *ersz;
668     {
669     /* glViewport(0, 0, ersz->width, ersz->height); */
670    
671     if (ersz->width == odev.hres && ersz->height == odev.vres)
672     return;
673    
674     odev.hres = ersz->width;
675     odev.vres = ersz->height;
676    
677     odev.v.horiz = 2.*180./PI * atan(0.5/VIEWDIST*pwidth*odev.hres);
678     odev.v.vert = 2.*180./PI * atan(0.5/VIEWDIST*pheight*odev.vres);
679    
680     inpresflags |= DFL(DC_SETVIEW);
681     }