ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/hd/rhd_ogl.c
Revision: 3.24
Committed: Thu Jan 1 11:21:55 2004 UTC (20 years, 3 months ago) by schorsch
Content type: text/plain
Branch: MAIN
Changes since 3.23: +127 -80 lines
Log Message:
Ansification and prototypes.

File Contents

# User Rev Content
1 gwlarson 3.1 #ifndef lint
2 schorsch 3.24 static const char RCSid[] = "$Id: rhd_ogl.c,v 3.23 2003/09/19 18:33:05 greg Exp $";
3 gwlarson 3.1 #endif
4     /*
5     * OpenGL driver for holodeck display.
6     * Based on GLX driver using T-mesh.
7     *
8     * Define symbol STEREO for stereo viewing.
9     * Define symbol DOBJ for display object viewing.
10     */
11    
12     #ifdef NOSTEREO
13     #ifdef STEREO
14     #undef STEREO
15     #else
16     #undef NOSTEREO
17     #endif
18     #endif
19    
20    
21 schorsch 3.24 #include <time.h>
22 gwlarson 3.1 #include <GL/glx.h>
23     #include <GL/glu.h>
24     #ifdef STEREO
25     #include <X11/extensions/SGIStereo.h>
26     #endif
27    
28 schorsch 3.24 #include "standard.h"
29 gwlarson 3.1 #include "rhd_odraw.h"
30 schorsch 3.24 #include "rhdisp.h"
31 gwlarson 3.1 #ifdef DOBJ
32     #include "rhdobj.h"
33     #endif
34    
35     #include "x11icon.h"
36    
37     #ifndef RAYQLEN
38 gwlarson 3.11 #define RAYQLEN 0 /* max. rays to queue before flush */
39 gwlarson 3.1 #endif
40 gwlarson 3.15 #ifndef MINWIDTH
41     #define MINWIDTH 480 /* minimum graphics window width */
42     #define MINHEIGHT 400 /* minimum graphics window height */
43     #endif
44     #ifndef VIEWDIST
45     #define VIEWDIST 356 /* assumed viewing distance (mm) */
46     #endif
47     #ifndef BORWIDTH
48     #define BORWIDTH 5 /* border width */
49     #endif
50 gwlarson 3.1
51     #ifndef FEQ
52     #define FEQ(a,b) ((a)-(b) <= FTINY && (a)-(b) >= -FTINY)
53     #endif
54    
55 gwlarson 3.7 #define VWHEADLOCK 01 /* head position is locked flag */
56     #define VWPERSP 02 /* perspective view is set */
57     #define VWORTHO 04 /* orthographic view is set */
58     #define VWCHANGE 010 /* view has changed */
59     #define VWSTEADY 020 /* view is now steady */
60     #define VWMAPPED 040 /* window is mapped */
61    
62 gwlarson 3.1 #define GAMMA 1.4 /* default gamma correction */
63    
64     #define FRAMESTATE(s) (((s)&(ShiftMask|ControlMask))==(ShiftMask|ControlMask))
65    
66     #define MOVPCT 7 /* percent distance to move /frame */
67     #define MOVDIR(b) ((b)==Button1 ? 1 : (b)==Button2 ? 0 : -1)
68     #define MOVDEG (-5) /* degrees to orbit CW/down /frame */
69     #define MOVORB(s) ((s)&ShiftMask ? 1 : (s)&ControlMask ? -1 : 0)
70    
71     #define setstereobuf(bid) (glXWaitGL(), \
72     XSGISetStereoBuffer(ourdisplay, gwind, bid), \
73     glXWaitX())
74    
75     #define ourscreen DefaultScreen(ourdisplay)
76     #define ourroot RootWindow(ourdisplay,ourscreen)
77     #define ourmask (StructureNotifyMask|ExposureMask|KeyPressMask|\
78     ButtonPressMask|ButtonReleaseMask)
79    
80     #define levptr(etype) ((etype *)&currentevent)
81    
82     struct driver odev; /* global device driver structure */
83    
84     char odev_args[64]; /* command arguments */
85    
86     static GLfloat *depthbuffer = NULL; /* depth buffer */
87    
88     #ifdef STEREO
89     static VIEW vwright; /* right eye view */
90     static GLfloat *depthright = NULL; /* right depth buffer */
91     #endif
92    
93     static int rayqleft = 0; /* rays left to queue before flush */
94    
95     static XEvent currentevent; /* current event */
96    
97     static unsigned long ourblack=0, ourwhite=~0;
98    
99     static Display *ourdisplay = NULL; /* our display */
100     static XVisualInfo *ourvinf; /* our visual information */
101     static Window gwind = 0; /* our graphics window */
102     static GLXContext gctx; /* our GLX context */
103    
104     static double pwidth, pheight; /* pixel dimensions (mm) */
105    
106     static double dev_zmin, dev_zmax; /* fore and aft clipping plane dist. */
107     static double dev_zrat; /* (1. - dev_zmin/dev_zmax) */
108    
109     #define setzrat() (dev_zrat = 1. - dev_zmin/dev_zmax)
110     #define mapdepth(d) ((d)>0.9995 ? FHUGE : dev_zmin/(1.-(d)*dev_zrat))
111    
112     static int inpresflags; /* input result flags */
113    
114 gwlarson 3.7 static int viewflags; /* what's happening with view */
115 gwlarson 3.1
116 schorsch 3.24 /*
117 gwlarson 3.1 static int resizewindow(), getevent(), getkey(), moveview(), wipeclean(),
118 gwlarson 3.2 xferdepth(), freedepth(), setglortho(),
119 gwlarson 3.1 setglpersp(), getframe(), getmove(), fixwindow(), mytmflags();
120    
121     static double getdistance();
122 schorsch 3.24 */
123     static void checkglerr(char *where);
124     static void xferdepth(void);
125     static void freedepth(void);
126     static double getdistance(int dx, int dy, FVECT direc);
127     static int mytmflags(void);
128     static void getevent(void);
129     static void draw3dline(register FVECT wp[2]);
130     static void draw_grids(int fore);
131     static int moveview(int dx, int dy, int mov, int orb);
132     static void getframe(XButtonPressedEvent *ebut);
133     static void getmove(XButtonPressedEvent *ebut);
134     static void getkey(register XKeyPressedEvent *ekey);
135     static void fixwindow(register XExposeEvent *eexp);
136     static void resizewindow(register XConfigureEvent *ersz);
137     static void waitabit(void);
138     static void setglpersp(void);
139     static void setglortho(void);
140     static void wipeclean(void);
141    
142 gwlarson 3.1
143     #ifdef STEREO
144 schorsch 3.24 static void pushright(void);
145     static void popright(void);
146 gwlarson 3.1 #endif
147    
148 gwlarson 3.2 extern int gmPortals; /* GL portal list id */
149    
150 gwlarson 3.1 extern time_t time();
151    
152    
153 schorsch 3.24 extern void
154 gwlarson 3.1 dev_open(id) /* initialize GLX driver */
155     char *id;
156     {
157     extern char *getenv();
158     static RGBPRIMS myprims = STDPRIMS;
159 gwlarson 3.6 static int atlBest[] = {GLX_RGBA, GLX_DOUBLEBUFFER,
160     GLX_RED_SIZE,8, GLX_GREEN_SIZE,8,
161     GLX_BLUE_SIZE,8, GLX_DEPTH_SIZE,15, None};
162     static int atlOK[] = {GLX_RGBA, GLX_DOUBLEBUFFER,
163     GLX_RED_SIZE,4, GLX_GREEN_SIZE,4,
164     GLX_BLUE_SIZE,4, GLX_DEPTH_SIZE,15, None};
165 gwlarson 3.1 char *ev;
166     double gamval = GAMMA;
167     RGBPRIMP dpri = stdprims;
168     XSetWindowAttributes ourwinattr;
169     XWMHints ourxwmhints;
170     XSizeHints oursizhints;
171     /* check for unsupported stereo */
172     #ifdef NOSTEREO
173     error(INTERNAL, "stereo display driver unavailable");
174     #endif
175     /* open display server */
176     ourdisplay = XOpenDisplay(NULL);
177 gwlarson 3.5 CHECK(ourdisplay==NULL, USER,
178     "cannot open X-windows; DISPLAY variable set?");
179 gwlarson 3.1 #ifdef STEREO
180     switch (XSGIQueryStereoMode(ourdisplay, ourroot)) {
181     case STEREO_TOP:
182     case STEREO_BOTTOM:
183     break;
184     case STEREO_OFF:
185     error(USER,
186 gwlarson 3.5 "wrong video mode: run \"/usr/gfx/setmon -n STR_TOP\" first");
187 gwlarson 3.1 case X_STEREO_UNSUPPORTED:
188     error(USER, "stereo mode not supported on this screen");
189     default:
190     error(INTERNAL, "unknown stereo mode");
191     }
192     #endif
193     /* find a usable visual */
194     ourvinf = glXChooseVisual(ourdisplay, ourscreen, atlBest);
195 gwlarson 3.6 if (ourvinf == NULL)
196     ourvinf = glXChooseVisual(ourdisplay, ourscreen, atlOK);
197 gwlarson 3.5 CHECK(ourvinf==NULL, USER, "no suitable visuals available");
198 gwlarson 3.1 /* get a context */
199     gctx = glXCreateContext(ourdisplay, ourvinf, NULL, GL_TRUE);
200     /* set gamma and tone mapping */
201     if ((ev = XGetDefault(ourdisplay, "radiance", "gamma")) != NULL
202     || (ev = getenv("DISPLAY_GAMMA")) != NULL)
203     gamval = atof(ev);
204     if ((ev = getenv("DISPLAY_PRIMARIES")) != NULL &&
205     sscanf(ev, "%f %f %f %f %f %f %f %f",
206     &myprims[RED][CIEX],&myprims[RED][CIEY],
207     &myprims[GRN][CIEX],&myprims[GRN][CIEY],
208     &myprims[BLU][CIEX],&myprims[BLU][CIEY],
209     &myprims[WHT][CIEX],&myprims[WHT][CIEY]) >= 6)
210     dpri = myprims;
211     if (tmInit(mytmflags(), dpri, gamval) == NULL)
212     error(SYSTEM, "not enough memory in dev_open");
213     /* open window */
214     ourwinattr.background_pixel = ourblack;
215     ourwinattr.border_pixel = ourblack;
216     ourwinattr.event_mask = ourmask;
217     /* this is stupid */
218     ourwinattr.colormap = XCreateColormap(ourdisplay, ourroot,
219     ourvinf->visual, AllocNone);
220     gwind = XCreateWindow(ourdisplay, ourroot, 0, 0,
221     DisplayWidth(ourdisplay,ourscreen)-2*BORWIDTH,
222     #ifdef STEREO
223     (DisplayHeight(ourdisplay,ourscreen)-2*BORWIDTH)/2,
224     #else
225     DisplayHeight(ourdisplay,ourscreen)-2*BORWIDTH,
226     #endif
227     BORWIDTH, ourvinf->depth, InputOutput, ourvinf->visual,
228     CWBackPixel|CWBorderPixel|CWColormap|CWEventMask, &ourwinattr);
229 gwlarson 3.5 CHECK(gwind==0, SYSTEM, "cannot create window");
230 gwlarson 3.1 XStoreName(ourdisplay, gwind, id);
231     /* set window manager hints */
232     ourxwmhints.flags = InputHint|IconPixmapHint;
233     ourxwmhints.input = True;
234     ourxwmhints.icon_pixmap = XCreateBitmapFromData(ourdisplay,
235     gwind, x11icon_bits, x11icon_width, x11icon_height);
236     XSetWMHints(ourdisplay, gwind, &ourxwmhints);
237     oursizhints.min_width = MINWIDTH;
238     #ifdef STEREO
239     oursizhints.min_height = MINHEIGHT/2;
240     oursizhints.max_width = DisplayWidth(ourdisplay,ourscreen)-2*BORWIDTH;
241     oursizhints.max_height = (DisplayHeight(ourdisplay,ourscreen) -
242     2*BORWIDTH)/2;
243     oursizhints.flags = PMinSize|PMaxSize;
244     #else
245     oursizhints.min_height = MINHEIGHT;
246     oursizhints.flags = PMinSize;
247     #endif
248     XSetNormalHints(ourdisplay, gwind, &oursizhints);
249     /* set GLX context */
250     glXMakeCurrent(ourdisplay, gwind, gctx);
251     glEnable(GL_DEPTH_TEST);
252     glDepthFunc(GL_LEQUAL);
253 gwlarson 3.9 glClearColor(0, 0, 0, 0);
254 gwlarson 3.1 glFrontFace(GL_CCW);
255     glDisable(GL_CULL_FACE);
256     glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
257     glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
258 gwlarson 3.10 glPixelStorei(GL_PACK_ALIGNMENT, 1);
259     glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
260 gwlarson 3.1 /* figure out sensible view */
261     pwidth = (double)DisplayWidthMM(ourdisplay, ourscreen) /
262     DisplayWidth(ourdisplay, ourscreen);
263     pheight = (double)DisplayHeightMM(ourdisplay, ourscreen) /
264     DisplayHeight(ourdisplay, ourscreen);
265     #ifdef STEREO
266     pheight *= 2.;
267     setstereobuf(STEREO_BUFFER_LEFT);
268     #endif
269     checkglerr("setting rendering parameters");
270 schorsch 3.22 odev.v = stdview;
271 gwlarson 3.1 odev.v.type = VT_PER;
272 gwlarson 3.7 viewflags = VWSTEADY; /* view starts static */
273 gwlarson 3.1 /* map the window */
274     XMapWindow(ourdisplay, gwind);
275     dev_input(); /* sets size and view angles */
276     if (!odInit(DisplayWidth(ourdisplay,ourscreen) *
277 gwlarson 3.11 DisplayHeight(ourdisplay,ourscreen) / 3))
278 gwlarson 3.1 error(SYSTEM, "insufficient memory for value storage");
279     odev.name = id;
280     odev.firstuse = 1; /* can't recycle samples */
281     odev.ifd = ConnectionNumber(ourdisplay);
282     }
283    
284    
285 schorsch 3.24 extern void
286     dev_close(void) /* close our display and free resources */
287 gwlarson 3.1 {
288     #ifdef DOBJ
289     dobj_cleanup();
290     #endif
291 gwlarson 3.2 freedepth();
292     gmEndGeom();
293     gmEndPortal();
294 gwlarson 3.1 odDone();
295     glXMakeCurrent(ourdisplay, None, NULL);
296     glXDestroyContext(ourdisplay, gctx);
297     XDestroyWindow(ourdisplay, gwind);
298     gwind = 0;
299     XCloseDisplay(ourdisplay);
300     ourdisplay = NULL;
301     tmDone(NULL);
302     odev.v.type = 0;
303     odev.hres = odev.vres = 0;
304     odev.ifd = -1;
305     }
306    
307    
308 schorsch 3.24 extern void
309     dev_clear(void) /* clear our representation */
310 gwlarson 3.1 {
311 gwlarson 3.10 viewflags |= VWCHANGE; /* pretend our view has changed */
312     wipeclean(); /* clean off display and samples */
313 gwlarson 3.12 dev_flush(); /* redraw geometry & get depth */
314 gwlarson 3.1 rayqleft = 0; /* hold off update */
315     }
316    
317    
318 schorsch 3.24 extern int
319     dev_view( /* assign new driver view */
320     register VIEW *nv
321     )
322 gwlarson 3.1 {
323     if (nv->type != VT_PER || /* check view legality */
324     nv->horiz > 160. || nv->vert > 160.) {
325     error(COMMAND, "illegal view type/angle");
326     nv->type = odev.v.type;
327     nv->horiz = odev.v.horiz;
328     nv->vert = odev.v.vert;
329     return(0);
330     }
331     if (nv != &odev.v) {
332     /* resize window? */
333     if (!FEQ(nv->horiz,odev.v.horiz) ||
334     !FEQ(nv->vert,odev.v.vert)) {
335     int dw = DisplayWidth(ourdisplay,ourscreen);
336     int dh = DisplayHeight(ourdisplay,ourscreen);
337    
338     dw -= 25; /* for window frame */
339     dh -= 50;
340     #ifdef STEREO
341     dh /= 2;
342     #endif
343     odev.hres = 2.*VIEWDIST/pwidth *
344     tan(PI/180./2.*nv->horiz);
345     odev.vres = 2.*VIEWDIST/pheight *
346     tan(PI/180./2.*nv->vert);
347     if (odev.hres > dw) {
348     odev.vres = dw * odev.vres / odev.hres;
349     odev.hres = dw;
350     }
351     if (odev.vres > dh) {
352     odev.hres = dh * odev.hres / odev.vres;
353     odev.vres = dh;
354     }
355     XResizeWindow(ourdisplay, gwind, odev.hres, odev.vres);
356     dev_input(); /* get resize event */
357     }
358 schorsch 3.22 odev.v = *nv; /* setview() already called */
359 gwlarson 3.14 viewflags |= VWCHANGE;
360     }
361 gwlarson 3.1 #ifdef STEREO
362 schorsch 3.22 vwright = *nv;
363 gwlarson 3.14 d = eyesepdist / sqrt(nv->hn2);
364     VSUM(vwright.vp, nv->vp, nv->hvec, d);
365     /* setview(&vwright); -- Unnecessary */
366 gwlarson 3.1 #endif
367     wipeclean();
368     return(1);
369     }
370    
371    
372 schorsch 3.24 extern void
373     dev_section( /* add octree for geometry rendering */
374     char *gfn,
375     char *pfn
376     )
377 gwlarson 3.1 {
378 gwlarson 3.2 if (gfn == NULL) {
379     gmEndGeom();
380     gmEndPortal();
381 gwlarson 3.4 wipeclean(); /* new geometry, so redraw it */
382 gwlarson 3.2 return;
383     }
384     if (access(gfn, R_OK) == 0)
385     gmNewGeom(gfn);
386 gwlarson 3.1 #ifdef DEBUG
387     else {
388 gwlarson 3.2 sprintf(errmsg, "cannot load octree \"%s\"", gfn);
389 gwlarson 3.1 error(WARNING, errmsg);
390     }
391     #endif
392 gwlarson 3.2 if (pfn != NULL)
393     gmNewPortal(pfn);
394 gwlarson 3.1 }
395    
396    
397 schorsch 3.24 extern void
398     dev_auxcom( /* process an auxiliary command */
399     char *cmd,
400     char *args
401     )
402 gwlarson 3.1 {
403     #ifdef DOBJ
404 gwlarson 3.12 int vischange;
405    
406     if ((vischange = dobj_command(cmd, args)) >= 0) {
407     if (vischange) {
408     imm_mode = beam_sync(1) > 0;
409     dev_clear();
410     }
411 gwlarson 3.1 return;
412 gwlarson 3.12 }
413 gwlarson 3.1 #endif
414     sprintf(errmsg, "%s: unknown command", cmd);
415     error(COMMAND, errmsg);
416     }
417    
418    
419 schorsch 3.24 extern VIEW *
420     dev_auxview( /* return nth auxiliary view */
421     int n,
422     int hvres[2]
423     )
424 gwlarson 3.1 {
425     hvres[0] = odev.hres; hvres[1] = odev.vres;
426     if (n == 0)
427     return(&odev.v);
428     #ifdef STEREO
429     if (n == 1)
430     return(&vwright);
431     #endif
432     return(NULL);
433     }
434    
435    
436 schorsch 3.24 extern int
437     dev_input(void) /* get X11 input */
438 gwlarson 3.1 {
439     inpresflags = 0;
440    
441     do
442     getevent();
443    
444     while (XPending(ourdisplay) > 0);
445    
446     odev.inpready = 0;
447    
448     return(inpresflags);
449     }
450    
451    
452 schorsch 3.24 extern void
453     dev_value( /* add a pixel value to our texture */
454     COLR c,
455     FVECT d,
456     FVECT p
457     )
458 gwlarson 3.1 {
459     #ifdef DOBJ
460     if (dobj_lightsamp != NULL) { /* in light source sampling */
461     (*dobj_lightsamp)(c, d, p);
462     return;
463     }
464     #endif
465     odSample(c, d, p); /* add to display representation */
466     if (!--rayqleft)
467     dev_flush(); /* flush output */
468     }
469    
470    
471 schorsch 3.24 extern int
472     dev_flush(void) /* flush output as appropriate */
473 gwlarson 3.1 {
474     int ndrawn;
475    
476 gwlarson 3.7 if ((viewflags&(VWMAPPED|VWPERSP)) == (VWMAPPED|VWPERSP)) {
477 gwlarson 3.1 #ifdef STEREO
478     pushright(); /* draw right eye */
479 gwlarson 3.3 ndrawn = gmDrawGeom();
480 gwlarson 3.1 #ifdef DOBJ
481 gwlarson 3.3 ndrawn += dobj_render();
482 gwlarson 3.1 #endif
483     checkglerr("rendering right eye");
484     popright(); /* draw left eye */
485     #endif
486 gwlarson 3.3 ndrawn = gmDrawGeom();
487 gwlarson 3.1 #ifdef DOBJ
488     ndrawn += dobj_render();
489     #endif
490 gwlarson 3.6 glXSwapBuffers(ourdisplay, gwind);
491 gwlarson 3.1 checkglerr("rendering base view");
492     }
493 gwlarson 3.7 if ((viewflags&(VWMAPPED|VWSTEADY|VWPERSP|VWORTHO)) ==
494     (VWMAPPED|VWSTEADY|VWPERSP)) {
495     /* first time after steady */
496     if (ndrawn)
497     xferdepth(); /* transfer and clear depth */
498     setglortho(); /* set orthographic view */
499    
500     }
501     if ((viewflags&(VWMAPPED|VWSTEADY|VWPERSP|VWORTHO)) ==
502     (VWMAPPED|VWSTEADY|VWORTHO)) {
503     /* else update cones */
504 gwlarson 3.1 #ifdef STEREO
505 gwlarson 3.7 pushright();
506     odUpdate(1); /* draw right eye */
507     popright();
508 gwlarson 3.1 #endif
509 gwlarson 3.7 odUpdate(0); /* draw left eye */
510     glFlush(); /* flush OpenGL */
511     }
512 gwlarson 3.1 rayqleft = RAYQLEN;
513     /* flush X11 and return # pending */
514     return(odev.inpready = XPending(ourdisplay));
515     }
516    
517    
518 schorsch 3.24 static void
519     checkglerr( /* check for GL or GLU error */
520     char *where
521     )
522 gwlarson 3.1 {
523     register GLenum errcode;
524    
525     while ((errcode = glGetError()) != GL_NO_ERROR) {
526     sprintf(errmsg, "OpenGL error %s: %s",
527     where, gluErrorString(errcode));
528     error(WARNING, errmsg);
529     }
530     }
531    
532    
533 schorsch 3.24 static void
534     xferdepth(void) /* load and clear depth buffer */
535 gwlarson 3.1 {
536     register GLfloat *dbp;
537 gwlarson 3.9 register GLubyte *pbuf;
538 gwlarson 3.1
539 gwlarson 3.3 if (depthbuffer == NULL) { /* allocate private depth buffer */
540 gwlarson 3.1 #ifdef STEREO
541     depthright = (GLfloat *)malloc(
542     odev.hres*odev.vres*sizeof(GLfloat));
543     #endif
544     depthbuffer = (GLfloat *)malloc(
545     odev.hres*odev.vres*sizeof(GLfloat));
546 gwlarson 3.5 CHECK(depthbuffer==NULL, SYSTEM, "out of memory in xferdepth");
547 gwlarson 3.1 }
548 gwlarson 3.3 /* allocate alpha buffer for portals */
549     if (gmPortals)
550 gwlarson 3.10 pbuf = (GLubyte *)malloc(odev.hres*odev.vres*sizeof(GLubyte));
551 gwlarson 3.3 else
552 gwlarson 3.9 pbuf = NULL;
553 gwlarson 3.1 #ifdef STEREO
554 gwlarson 3.12 pushright();
555 gwlarson 3.1 glReadPixels(0, 0, odev.hres, odev.vres,
556     GL_DEPTH_COMPONENT, GL_FLOAT, depthright);
557 gwlarson 3.9 if (pbuf != NULL) {
558     glClear(GL_COLOR_BUFFER_BIT);
559     gmDrawPortals(0xff, -1, -1, -1);
560 gwlarson 3.3 glReadPixels(0, 0, odev.hres, odev.vres,
561 gwlarson 3.10 GL_RED, GL_UNSIGNED_BYTE, pbuf);
562 gwlarson 3.9 }
563 gwlarson 3.3 for (dbp = depthright + odev.hres*odev.vres; dbp-- > depthright; )
564 gwlarson 3.10 if (pbuf != NULL && pbuf[dbp-depthright]&0x40)
565 gwlarson 3.3 *dbp = FHUGE;
566     else
567     *dbp = mapdepth(*dbp);
568     glClear(GL_DEPTH_BUFFER_BIT);
569 gwlarson 3.1 odDepthMap(1, depthright);
570 gwlarson 3.12 popright();
571 gwlarson 3.1 #endif
572 gwlarson 3.2 /* read back depth buffer */
573 gwlarson 3.1 glReadPixels(0, 0, odev.hres, odev.vres,
574     GL_DEPTH_COMPONENT, GL_FLOAT, depthbuffer);
575 gwlarson 3.9 if (pbuf != NULL) {
576     glClear(GL_COLOR_BUFFER_BIT); /* find portals */
577     gmDrawPortals(0xff, -1, -1, -1);
578 gwlarson 3.2 glReadPixels(0, 0, odev.hres, odev.vres,
579 gwlarson 3.10 GL_RED, GL_UNSIGNED_BYTE, pbuf);
580     #ifdef DEBUG
581     glXSwapBuffers(ourdisplay, gwind);
582     #endif
583 gwlarson 3.9 }
584 gwlarson 3.1 for (dbp = depthbuffer + odev.hres*odev.vres; dbp-- > depthbuffer; )
585 gwlarson 3.10 if (pbuf != NULL && pbuf[dbp-depthbuffer]&0x40)
586 gwlarson 3.2 *dbp = FHUGE;
587     else
588     *dbp = mapdepth(*dbp);
589 gwlarson 3.3 glClear(GL_DEPTH_BUFFER_BIT); /* clear system depth buffer */
590 gwlarson 3.1 odDepthMap(0, depthbuffer); /* transfer depth data */
591 gwlarson 3.9 if (pbuf != NULL)
592 greg 3.19 free((void *)pbuf); /* free our portal buffer */
593 gwlarson 3.1 }
594    
595    
596 schorsch 3.24 static void
597     freedepth(void) /* free recorded depth buffer */
598 gwlarson 3.2 {
599     if (depthbuffer == NULL)
600     return;
601     #ifdef STEREO
602     odDepthMap(1, NULL);
603 greg 3.19 free((void *)depthright);
604 gwlarson 3.2 depthright = NULL;
605     #endif
606     odDepthMap(0, NULL);
607 greg 3.19 free((void *)depthbuffer);
608 gwlarson 3.2 depthbuffer = NULL;
609     }
610    
611    
612 gwlarson 3.1 static double
613 schorsch 3.24 getdistance( /* distance from fore plane along view ray */
614     int dx,
615     int dy,
616     FVECT direc
617     )
618 gwlarson 3.1 {
619     GLfloat gldepth;
620     double dist;
621    
622 schorsch 3.24 if ((dx<0) | (dx>=odev.hres) | (dy<0) | (dy>=odev.vres))
623 gwlarson 3.1 return(FHUGE);
624     if (depthbuffer != NULL)
625     dist = depthbuffer[dy*odev.hres + dx];
626     else {
627     glReadPixels(dx,dy, 1,1, GL_DEPTH_COMPONENT,
628     GL_FLOAT, &gldepth);
629 greg 3.23 if (gldepth <= FTINY)
630     return (FHUGE); /* call failed */
631 gwlarson 3.3 dist = mapdepth(gldepth);
632 gwlarson 3.1 }
633     if (dist >= .99*FHUGE)
634     return(FHUGE);
635     return((dist-odev.v.vfore)/DOT(direc,odev.v.vdir));
636     }
637    
638    
639     #ifdef STEREO
640 schorsch 3.24 static void
641     pushright(void) /* push on right view & buffer */
642 gwlarson 3.1 {
643     double d;
644    
645     setstereobuf(STEREO_BUFFER_RIGHT);
646 gwlarson 3.7 if (viewflags & VWPERSP) {
647 gwlarson 3.1 glMatrixMode(GL_MODELVIEW);
648     glPushMatrix();
649     d = -eyesepdist / sqrt(odev.v.hn2);
650     glTranslated(d*odev.v.hvec[0], d*odev.v.hvec[1],
651     d*odev.v.hvec[2]);
652     checkglerr("setting right view");
653     }
654     }
655    
656    
657 schorsch 3.24 static void
658     popright(void) /* pop off right view & buffer */
659 gwlarson 3.1 {
660 gwlarson 3.7 if (viewflags & VWPERSP) {
661 gwlarson 3.1 glMatrixMode(GL_MODELVIEW);
662     glPopMatrix();
663     }
664     setstereobuf(STEREO_BUFFER_LEFT);
665     }
666     #endif
667    
668    
669     static int
670 schorsch 3.24 mytmflags(void) /* figure out tone mapping flags */
671 gwlarson 3.1 {
672     extern char *progname;
673     register char *cp, *tail;
674     /* find basic name */
675     for (cp = tail = progname; *cp; cp++)
676     if (*cp == '/')
677     tail = cp+1;
678     for (cp = tail; *cp && *cp != '.'; cp++)
679     ;
680     #ifdef DEBUG
681     if (cp > tail && cp[-1] == 'h')
682     return(TM_F_HUMAN);
683     else
684     return(TM_F_CAMERA);
685     #else
686     if (cp > tail && cp[-1] == 'h')
687     return(TM_F_HUMAN|TM_F_NOSTDERR);
688     else
689     return(TM_F_CAMERA|TM_F_NOSTDERR);
690     #endif
691     }
692    
693    
694 schorsch 3.24 static void
695     getevent(void) /* get next event */
696 gwlarson 3.1 {
697     XNextEvent(ourdisplay, levptr(XEvent));
698     switch (levptr(XEvent)->type) {
699     case ConfigureNotify:
700     resizewindow(levptr(XConfigureEvent));
701     break;
702     case UnmapNotify:
703 gwlarson 3.7 viewflags &= ~VWMAPPED;
704 gwlarson 3.1 break;
705     case MapNotify:
706 gwlarson 3.2 odRemap(0);
707 gwlarson 3.7 viewflags |= VWMAPPED;
708 gwlarson 3.1 break;
709     case Expose:
710     fixwindow(levptr(XExposeEvent));
711     break;
712     case KeyPress:
713     getkey(levptr(XKeyPressedEvent));
714     break;
715     case ButtonPress:
716     if (FRAMESTATE(levptr(XButtonPressedEvent)->state))
717     getframe(levptr(XButtonPressedEvent));
718     else
719     getmove(levptr(XButtonPressedEvent));
720     break;
721     }
722     }
723    
724    
725 schorsch 3.24 static void
726     draw3dline( /* draw 3d line in world coordinates */
727     register FVECT wp[2]
728     )
729 gwlarson 3.1 {
730     glVertex3d(wp[0][0], wp[0][1], wp[0][2]);
731     glVertex3d(wp[1][0], wp[1][1], wp[1][2]);
732     }
733    
734    
735 schorsch 3.24 static void
736     draw_grids( /* draw holodeck section grids */
737     int fore
738     )
739 gwlarson 3.1 {
740     glPushAttrib(GL_LIGHTING_BIT|GL_ENABLE_BIT);
741     glDisable(GL_LIGHTING);
742     if (fore)
743 gwlarson 3.8 glColor3ub(4, 250, 250);
744 gwlarson 3.1 else
745     glColor3ub(0, 0, 0);
746     glBegin(GL_LINES); /* draw each grid line */
747     gridlines(draw3dline);
748     glEnd();
749     checkglerr("drawing grid lines");
750     glPopAttrib();
751     }
752    
753    
754 schorsch 3.24 static int
755     moveview( /* move our view */
756     int dx,
757     int dy,
758     int mov,
759     int orb
760     )
761 gwlarson 3.1 {
762     VIEW nv;
763     FVECT odir, v1, wip;
764     double d, d1;
765     /* start with old view */
766 schorsch 3.22 nv = odev.v;
767 gwlarson 3.1 /* orient our motion */
768     if (viewray(v1, odir, &odev.v,
769     (dx+.5)/odev.hres, (dy+.5)/odev.vres) < -FTINY)
770     return(0); /* outside view */
771     if (mov | orb) { /* moving relative to geometry */
772     d = getdistance(dx, dy, odir); /* distance from front plane */
773     #ifdef DOBJ
774     d1 = dobj_trace(NULL, v1, odir);
775     if (d1 < d)
776     d = d1;
777     #endif
778     if (d >= .99*FHUGE)
779     d = 0.5*(dev_zmax+dev_zmin); /* just guess */
780     VSUM(wip, v1, odir, d);
781     VSUB(odir, wip, odev.v.vp);
782     } else /* panning with constant viewpoint */
783     VCOPY(nv.vdir, odir);
784     if (orb && mov) { /* orbit left/right */
785     spinvector(odir, odir, nv.vup, d=MOVDEG*PI/180.*mov);
786     VSUM(nv.vp, wip, odir, -1.);
787     spinvector(nv.vdir, nv.vdir, nv.vup, d);
788     } else if (orb) { /* orbit up/down */
789     fcross(v1, odir, nv.vup);
790     if (normalize(v1) == 0.)
791     return(0);
792     spinvector(odir, odir, v1, d=MOVDEG*PI/180.*orb);
793     VSUM(nv.vp, wip, odir, -1.);
794     spinvector(nv.vdir, nv.vdir, v1, d);
795     } else if (mov) { /* move forward/backward */
796     d = MOVPCT/100. * mov;
797     VSUM(nv.vp, nv.vp, odir, d);
798     }
799 gwlarson 3.7 if (!mov ^ !orb && viewflags&VWHEADLOCK) { /* restore height */
800 gwlarson 3.1 VSUM(v1, odev.v.vp, nv.vp, -1.);
801     d = DOT(v1, nv.vup);
802     VSUM(nv.vp, nv.vp, odev.v.vup, d);
803     }
804     if (setview(&nv) != NULL)
805     return(0); /* illegal view */
806     dev_view(&nv);
807 gwlarson 3.2 inpresflags |= DFL(DC_SETVIEW);
808 gwlarson 3.1 return(1);
809     }
810    
811    
812 schorsch 3.24 static void
813     getframe( /* get focus frame */
814     XButtonPressedEvent *ebut
815     )
816 gwlarson 3.1 {
817     int startx = ebut->x, starty = ebut->y;
818     int endx, endy;
819    
820     XMaskEvent(ourdisplay, ButtonReleaseMask, levptr(XEvent));
821     endx = levptr(XButtonReleasedEvent)->x;
822     endy = levptr(XButtonReleasedEvent)->y;
823 schorsch 3.24 if ((endx == startx) | (endy == starty)) {
824 gwlarson 3.1 XBell(ourdisplay, 0);
825     return;
826     }
827     if (endx < startx) {register int c = endx; endx = startx; startx = c;}
828     if (endy < starty) {register int c = endy; endy = starty; starty = c;}
829     sprintf(odev_args, "%.3f %.3f %.3f %.3f",
830     (startx+.5)/odev.hres, 1.-(endy+.5)/odev.vres,
831     (endx+.5)/odev.hres, 1.-(starty+.5)/odev.vres);
832     inpresflags |= DFL(DC_FOCUS);
833     }
834    
835    
836 schorsch 3.24 static void
837     waitabit(void) /* pause a moment */
838 greg 3.19 {
839     struct timespec ts;
840     ts.tv_sec = 0;
841 greg 3.23 ts.tv_nsec = 100000000L;
842 greg 3.19 nanosleep(&ts, NULL);
843     }
844    
845    
846 schorsch 3.24 static void
847     getmove( /* get view change */
848     XButtonPressedEvent *ebut
849     )
850 gwlarson 3.1 {
851     int movdir = MOVDIR(ebut->button);
852     int movorb = MOVORB(ebut->state);
853 gwlarson 3.2 int ndrawn;
854 gwlarson 3.1 Window rootw, childw;
855     int rootx, rooty, wx, wy;
856     unsigned int statemask;
857    
858     XNoOp(ourdisplay); /* makes sure we're not idle */
859    
860 gwlarson 3.7 viewflags &= ~VWSTEADY; /* flag moving view */
861 gwlarson 3.11 setglpersp(); /* start us off in perspective */
862 gwlarson 3.1 while (!XCheckMaskEvent(ourdisplay,
863     ButtonReleaseMask, levptr(XEvent))) {
864 greg 3.19 /* pause so as not to move too fast */
865     waitabit();
866 gwlarson 3.1 /* get cursor position */
867     if (!XQueryPointer(ourdisplay, gwind, &rootw, &childw,
868     &rootx, &rooty, &wx, &wy, &statemask))
869     break; /* on another screen */
870     /* compute view motion */
871     if (!moveview(wx, odev.vres-1-wy, movdir, movorb)) {
872     sleep(1);
873     continue; /* cursor in bad place */
874     }
875     draw_grids(1); /* redraw grid */
876     #ifdef STEREO
877     pushright();
878     draw_grids(1);
879 gwlarson 3.3 ndrawn = gmDrawGeom();
880 gwlarson 3.1 #ifdef DOBJ
881 gwlarson 3.3 ndrawn += dobj_render();
882 gwlarson 3.1 #endif
883     popright();
884     #endif
885     /* redraw octrees */
886 gwlarson 3.3 ndrawn = gmDrawGeom();
887 gwlarson 3.1 #ifdef DOBJ
888 gwlarson 3.2 ndrawn += dobj_render(); /* redraw objects */
889 gwlarson 3.1 #endif
890 gwlarson 3.6 glXSwapBuffers(ourdisplay, gwind);
891     if (!ndrawn)
892 gwlarson 3.2 sleep(1); /* for reasonable interaction */
893 gwlarson 3.1 }
894     if (!(inpresflags & DFL(DC_SETVIEW))) { /* do final motion */
895     movdir = MOVDIR(levptr(XButtonReleasedEvent)->button);
896     wx = levptr(XButtonReleasedEvent)->x;
897     wy = levptr(XButtonReleasedEvent)->y;
898     moveview(wx, odev.vres-1-wy, movdir, movorb);
899     }
900 gwlarson 3.7 viewflags |= VWSTEADY; /* done goofing around */
901 gwlarson 3.1 }
902    
903    
904 schorsch 3.24 static void
905     setglpersp(void) /* set perspective view in GL */
906 gwlarson 3.1 {
907     double d, xmin, xmax, ymin, ymax;
908     GLfloat vec[4];
909     double depthlim[2];
910     /* set depth limits */
911 gwlarson 3.2 gmDepthLimit(depthlim, odev.v.vp, odev.v.vdir);
912 gwlarson 3.1 if (depthlim[0] >= depthlim[1]) {
913     dev_zmin = 1.;
914     dev_zmax = 100.;
915     } else {
916     dev_zmin = 0.5*depthlim[0];
917 gwlarson 3.13 dev_zmax = 1.25*depthlim[1];
918 gwlarson 3.1 if (dev_zmin > dev_zmax/5.)
919     dev_zmin = dev_zmax/5.;
920     }
921     if (odev.v.vfore > FTINY)
922     dev_zmin = odev.v.vfore;
923     if (odev.v.vaft > FTINY)
924     dev_zmax = odev.v.vaft;
925 gwlarson 3.18 if (dev_zmin*500. < dev_zmax)
926 greg 3.19 dev_zmin = dev_zmax/500.;
927 gwlarson 3.1 setzrat();
928     xmax = dev_zmin * tan(PI/180./2. * odev.v.horiz);
929     xmin = -xmax;
930     d = odev.v.hoff * (xmax - xmin);
931     xmin += d; xmax += d;
932     ymax = dev_zmin * tan(PI/180./2. * odev.v.vert);
933     ymin = -ymax;
934     d = odev.v.voff * (ymax - ymin);
935     ymin += d; ymax += d;
936     /* set view matrix */
937     glMatrixMode(GL_PROJECTION);
938     glLoadIdentity();
939     glFrustum(xmin, xmax, ymin, ymax, dev_zmin, dev_zmax);
940     gluLookAt(odev.v.vp[0], odev.v.vp[1], odev.v.vp[2],
941     odev.v.vp[0] + odev.v.vdir[0],
942     odev.v.vp[1] + odev.v.vdir[1],
943     odev.v.vp[2] + odev.v.vdir[2],
944     odev.v.vup[0], odev.v.vup[1], odev.v.vup[2]);
945     checkglerr("setting perspective view");
946     vec[0] = vec[1] = vec[2] = 0.; vec[3] = 1.;
947     glLightModelfv(GL_LIGHT_MODEL_AMBIENT, vec);
948     vec[0] = -odev.v.vdir[0];
949     vec[1] = -odev.v.vdir[1];
950     vec[2] = -odev.v.vdir[2];
951     vec[3] = 0.;
952     glLightfv(GL_LIGHT0, GL_POSITION, vec);
953     vec[0] = vec[1] = vec[2] = .7; vec[3] = 1.;
954     glLightfv(GL_LIGHT0, GL_SPECULAR, vec);
955     glLightfv(GL_LIGHT0, GL_DIFFUSE, vec);
956     vec[0] = vec[1] = vec[2] = .3; vec[3] = 1.;
957     glLightfv(GL_LIGHT0, GL_AMBIENT, vec);
958     glEnable(GL_LIGHT0);
959     glEnable(GL_LIGHTING); /* light our GL objects */
960     glShadeModel(GL_SMOOTH);
961 gwlarson 3.7 viewflags &= ~VWORTHO;
962     viewflags |= VWPERSP;
963 gwlarson 3.1 }
964    
965    
966 schorsch 3.24 static void
967     setglortho(void) /* set up orthographic view for cone drawing */
968 gwlarson 3.1 {
969 gwlarson 3.6 glDrawBuffer(GL_FRONT); /* use single-buffer mode */
970 gwlarson 3.1 /* set view matrix */
971     glMatrixMode(GL_PROJECTION);
972     glLoadIdentity();
973     glOrtho(0., (double)odev.hres, 0., (double)odev.vres,
974     0.001*OMAXDEPTH, 1.001*(-OMAXDEPTH));
975     checkglerr("setting orthographic view");
976     glDisable(GL_LIGHTING); /* cones are constant color */
977     glShadeModel(GL_FLAT);
978 gwlarson 3.7 viewflags &= ~VWPERSP;
979     viewflags |= VWORTHO;
980 gwlarson 3.1 }
981    
982    
983 schorsch 3.24 static void
984     wipeclean(void) /* prepare for redraw */
985 gwlarson 3.1 {
986 gwlarson 3.6 glDrawBuffer(GL_BACK); /* use double-buffer mode */
987 gwlarson 3.9 glReadBuffer(GL_BACK);
988 gwlarson 3.6 /* clear buffers */
989 gwlarson 3.1 #ifdef STEREO
990     setstereobuf(STEREO_BUFFER_RIGHT);
991 gwlarson 3.6 glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT);
992 gwlarson 3.1 setstereobuf(STEREO_BUFFER_LEFT);
993     #endif
994 gwlarson 3.6 glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT);
995     freedepth();
996 gwlarson 3.7 if ((viewflags&(VWCHANGE|VWSTEADY)) ==
997     (VWCHANGE|VWSTEADY)) { /* clear samples if new */
998 gwlarson 3.1 odClean();
999 gwlarson 3.7 viewflags &= ~VWCHANGE; /* change noted */
1000 gwlarson 3.10 } else if (viewflags & VWSTEADY)
1001     odRedrawAll();
1002 gwlarson 3.17 setglpersp(); /* reset view & clipping planes */
1003 gwlarson 3.1 }
1004    
1005    
1006 schorsch 3.24 static void
1007     getkey( /* get input key */
1008     register XKeyPressedEvent *ekey
1009     )
1010 gwlarson 3.1 {
1011     Window rootw, childw;
1012     int rootx, rooty, wx, wy;
1013     unsigned int statemask;
1014     int n;
1015     char buf[8];
1016    
1017     n = XLookupString(ekey, buf, sizeof(buf), NULL, NULL);
1018     if (n != 1)
1019     return;
1020     switch (buf[0]) {
1021     case 'h': /* turn on height motion lock */
1022 gwlarson 3.7 viewflags |= VWHEADLOCK;
1023 gwlarson 3.1 return;
1024     case 'H': /* turn off height motion lock */
1025 gwlarson 3.7 viewflags &= ~VWHEADLOCK;
1026 gwlarson 3.1 return;
1027     case 'l': /* retrieve last view */
1028     inpresflags |= DFL(DC_LASTVIEW);
1029     return;
1030     case 'p': /* pause computation */
1031     inpresflags |= DFL(DC_PAUSE);
1032     return;
1033     case 'v': /* spit out view */
1034     inpresflags |= DFL(DC_GETVIEW);
1035     return;
1036     case 'f': /* frame view position */
1037     if (!XQueryPointer(ourdisplay, gwind, &rootw, &childw,
1038     &rootx, &rooty, &wx, &wy, &statemask))
1039     return; /* on another screen */
1040     sprintf(odev_args, "%.4f %.4f", (wx+.5)/odev.hres,
1041     1.-(wy+.5)/odev.vres);
1042     inpresflags |= DFL(DC_FOCUS);
1043     return;
1044     case 'F': /* unfocus */
1045     odev_args[0] = '\0';
1046     inpresflags |= DFL(DC_FOCUS);
1047     return;
1048     case '\n':
1049     case '\r': /* resume computation */
1050     inpresflags |= DFL(DC_RESUME);
1051     return;
1052     case CTRL('R'): /* redraw screen */
1053 gwlarson 3.10 odRemap(0); /* new tone mapping */
1054 gwlarson 3.6 glClear(GL_DEPTH_BUFFER_BIT);
1055 gwlarson 3.1 #ifdef STEREO
1056     setstereobuf(STEREO_BUFFER_RIGHT);
1057 gwlarson 3.6 glClear(GL_DEPTH_BUFFER_BIT);
1058 gwlarson 3.1 setstereobuf(STEREO_BUFFER_LEFT);
1059     #endif
1060     return;
1061     case CTRL('L'): /* refresh from server */
1062     if (inpresflags & DFL(DC_REDRAW))
1063 gwlarson 3.12 return; /* already called */
1064 gwlarson 3.1 XRaiseWindow(ourdisplay, gwind);
1065 gwlarson 3.11 XFlush(ourdisplay); /* raise up window */
1066 gwlarson 3.10 sleep(1); /* wait for restacking */
1067 gwlarson 3.11 dev_clear(); /* clear buffer and samples */
1068 gwlarson 3.10 odRemap(1); /* start fresh histogram */
1069 gwlarson 3.1 inpresflags |= DFL(DC_REDRAW); /* resend values from server */
1070     return;
1071     case 'K': /* kill rtrace process(es) */
1072     inpresflags |= DFL(DC_KILL);
1073     break;
1074     case 'R': /* restart rtrace */
1075     inpresflags |= DFL(DC_RESTART);
1076     break;
1077     case 'C': /* clobber holodeck */
1078     inpresflags |= DFL(DC_CLOBBER);
1079     break;
1080     case 'q': /* quit the program */
1081     inpresflags |= DFL(DC_QUIT);
1082     return;
1083     default:
1084     XBell(ourdisplay, 0);
1085     return;
1086     }
1087     }
1088    
1089    
1090 schorsch 3.24 static void
1091     fixwindow( /* repair damage to window */
1092     register XExposeEvent *eexp
1093     )
1094 gwlarson 3.1 {
1095     int xmin, ymin, xmax, ymax;
1096    
1097 schorsch 3.24 if ((odev.hres == 0) | (odev.vres == 0)) { /* first exposure */
1098 gwlarson 3.1 resizewindow((XConfigureEvent *)eexp);
1099     return;
1100     }
1101     xmin = eexp->x; xmax = eexp->x + eexp->width;
1102     ymin = odev.vres - eexp->y - eexp->height; ymax = odev.vres - eexp->y;
1103 gwlarson 3.10
1104     if (xmin <= 0 && xmax >= odev.hres-1 &&
1105     ymin <= 0 && ymax >= odev.vres) {
1106     DCHECK(eexp->count, WARNING, "multiple clear in fixwindow");
1107 gwlarson 3.11 wipeclean(); /* make sure we're go */
1108 gwlarson 3.10 return;
1109     }
1110 gwlarson 3.1 /* clear portion of depth */
1111 gwlarson 3.2 glPushAttrib(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT);
1112 gwlarson 3.1 glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
1113     glDepthFunc(GL_ALWAYS);
1114     glBegin(GL_POLYGON);
1115     glVertex3i(xmin, ymin, OMAXDEPTH);
1116     glVertex3i(xmax, ymin, OMAXDEPTH);
1117     glVertex3i(xmax, ymax, OMAXDEPTH);
1118     glVertex3i(xmin, ymax, OMAXDEPTH);
1119     glEnd();
1120     #ifdef STEREO
1121     setstereobuf(STEREO_BUFFER_RIGHT);
1122     glBegin(GL_POLYGON);
1123     glVertex3i(xmin, ymin, OMAXDEPTH);
1124     glVertex3i(xmax, ymin, OMAXDEPTH);
1125     glVertex3i(xmax, ymax, OMAXDEPTH);
1126     glVertex3i(xmin, ymax, OMAXDEPTH);
1127     glEnd();
1128     odRedraw(1, xmin, ymin, xmax, ymax);
1129     setstereobuf(STEREO_BUFFER_LEFT);
1130     #endif
1131 gwlarson 3.2 glPopAttrib();
1132 gwlarson 3.1 odRedraw(0, xmin, ymin, xmax, ymax);
1133     }
1134    
1135    
1136 schorsch 3.24 static void
1137     resizewindow( /* resize window */
1138     register XConfigureEvent *ersz
1139     )
1140 gwlarson 3.1 {
1141     glViewport(0, 0, ersz->width, ersz->height);
1142    
1143     if (ersz->width == odev.hres && ersz->height == odev.vres)
1144     return;
1145    
1146     odev.hres = ersz->width;
1147     odev.vres = ersz->height;
1148    
1149     odev.v.horiz = 2.*180./PI * atan(0.5/VIEWDIST*pwidth*odev.hres);
1150     odev.v.vert = 2.*180./PI * atan(0.5/VIEWDIST*pheight*odev.vres);
1151    
1152 gwlarson 3.2 inpresflags |= DFL(DC_SETVIEW);
1153 gwlarson 3.7 viewflags |= VWCHANGE;
1154 gwlarson 3.1 }