ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/hd/rhd_glx.c
(Generate patch)

Comparing ray/src/hd/rhd_glx.c (file contents):
Revision 3.1 by gregl, Tue Dec 23 18:31:00 1997 UTC vs.
Revision 3.31 by greg, Fri Sep 19 18:33:04 2003 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1997 Silicon Graphics, Inc. */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ SGI";
2 > static const char       RCSid[] = "$Id$";
3   #endif
6
4   /*
5   * OpenGL GLX driver for holodeck display.
6 < * Based on rview driver.
6 > * Based on old GLX driver using cones.
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   #include "standard.h"
13 #include "tonemap.h"
14 #include "rhdriver.h"
21  
22 < #include  <GL/glx.h>
23 <
24 < #include  "x11icon.h"
25 <
20 < #ifndef FEQ
21 < #define FEQ(a,b)        ((a)-(b) <= FTINY && (a)-(b) >= -FTINY)
22 > #include <GL/glx.h>
23 > #include <GL/glu.h>
24 > #ifdef STEREO
25 > #include <X11/extensions/SGIStereo.h>
26   #endif
27  
28 < #ifndef int4
29 < #define int4    int
28 > #include "rhd_sample.h"
29 > #ifdef DOBJ
30 > #include "rhdobj.h"
31   #endif
32  
33 < #ifndef FREEPCT
34 < #define FREEPCT         25              /* percentage of values to free */
33 > #include "x11icon.h"
34 >
35 > #ifndef RAYQLEN
36 > #define RAYQLEN         1024            /* max. rays to queue before flush */
37   #endif
38  
39 < #ifndef NCONEV
40 < #define NCONEV          7               /* number of cone base vertices */
39 > #ifndef FEQ
40 > #define FEQ(a,b)        ((a)-(b) <= FTINY && (a)-(b) >= -FTINY)
41   #endif
35 #ifndef CONEH
36 #define CONEH           0.25            /* cone height (fraction of depth) */
37 #endif
38 #ifndef CONEW
39 #define CONEW           0.035           /* cone width (fraction of screen) */
40 #endif
42  
43 < #define GAMMA           2.2             /* default gamma correction */
43 > #define GAMMA           1.4             /* default gamma correction */
44  
45 + #define FRAMESTATE(s)   (((s)&(ShiftMask|ControlMask))==(ShiftMask|ControlMask))
46 +
47   #define MOVPCT          7               /* percent distance to move /frame */
48   #define MOVDIR(b)       ((b)==Button1 ? 1 : (b)==Button2 ? 0 : -1)
49   #define MOVDEG          (-5)            /* degrees to orbit CW/down /frame */
50   #define MOVORB(s)       ((s)&ShiftMask ? 1 : (s)&ControlMask ? -1 : 0)
51  
52 + #ifndef TARGETFPS
53 + #define TARGETFPS       2.0             /* target frames/sec during motion */
54 + #endif
55 +
56   #define MINWIDTH        480             /* minimum graphics window width */
57   #define MINHEIGHT       400             /* minimum graphics window height */
58  
# Line 53 | Line 60 | static char SCCSid[] = "$SunId$ SGI";
60  
61   #define BORWIDTH        5               /* border width */
62  
63 + #define setstereobuf(bid)       (glXWaitGL(), \
64 +                                XSGISetStereoBuffer(ourdisplay, gwind, bid), \
65 +                                glXWaitX())
66 +
67   #define  ourscreen      DefaultScreen(ourdisplay)
68   #define  ourroot        RootWindow(ourdisplay,ourscreen)
69   #define  ourmask        (StructureNotifyMask|ExposureMask|KeyPressMask|\
# Line 62 | Line 73 | static char SCCSid[] = "$SunId$ SGI";
73  
74   struct driver   odev;                   /* global device driver structure */
75  
76 + char odev_args[64];                     /* command arguments */
77 +
78 + #ifdef STEREO
79 + static VIEW     vwright;                /* right eye view */
80 + #endif
81 +
82 + static int      rayqleft = 0;           /* rays left to queue before flush */
83 +
84   static XEvent  currentevent;            /* current event */
85  
86   static int  mapped = 0;                 /* window is mapped? */
68 static unsigned long  *pixval = NULL;   /* allocated pixels */
87   static unsigned long  ourblack=0, ourwhite=~0;
88  
89   static Display  *ourdisplay = NULL;     /* our display */
# Line 73 | Line 91 | static XVisualInfo  *ourvinf;          /* our visual informati
91   static Window  gwind = 0;               /* our graphics window */
92   static GLXContext       gctx;           /* our GLX context */
93  
76 static double   mindepth = FHUGE;       /* minimum depth value so far */
77 static double   maxdepth = 0.;          /* maximum depth value */
78
94   static double   pwidth, pheight;        /* pixel dimensions (mm) */
95  
96 < static FVECT    conev[NCONEV];          /* drawing cone */
82 < static double   coneh;                  /* cone height */
96 > static double   mindpth, maxdpth;       /* min. and max. depth */
97  
98 + double  dev_zmin, dev_zmax;             /* fore and aft clipping plane dist. */
99 +
100   static int      inpresflags;            /* input result flags */
101  
102   static int      headlocked = 0;         /* lock vertical motion */
103  
104 < static struct {
105 <        float           (*wp)[3];       /* world intersection point array */
90 <        int4            *wd;            /* world direction array */
91 <        TMbright        *brt;           /* encoded brightness array */
92 <        BYTE            (*chr)[3];      /* encoded chrominance array */
93 <        BYTE            (*rgb)[3];      /* tone-mapped color array */
94 <        BYTE            *alpha;         /* alpha values */
95 <        int             nl;             /* count of values */
96 <        int             bl, tl;         /* bottom and top (next) value index */
97 <        int             tml;            /* next value needing tone-mapping */
98 <        int             drl;            /* next value in need of drawing */
99 <        char            *base;          /* base of allocated memory */
100 < }       rV;                     /* our collection of values */
104 > static int  resizewindow(), getevent(), getkey(), moveview(), wipeclean(),
105 >                setglpersp(), getframe(), getmove(), fixwindow(), mytmflags();
106  
107 < #define redraw()        (rV.drl = rV.bl)
107 > #ifdef STEREO
108 > static int  pushright(), popright();
109 > #endif
110 > static double   getdistance();
111 > #define mapdepth(d) ((d)> 0.9995 ? FHUGE: dev_zmin/ \
112 >                     (1.-(d)*(1.-dev_zmin/dev_zmax)))
113  
114 < static int  resizewindow(), getevent(), getkey(), moveview(),
105 <                setGLview(), getmove(), fixwindow(), mytmflags(),
106 <                newvalue(), drawvalue(), Compost(),
107 <                FindValue(), AllocValues(), TMapValues(), FreeValues();
114 > extern time_t   time();
115  
116  
117 < dev_open(id)                    /* initialize X11 driver */
117 > dev_open(id)                    /* initialize GLX driver */
118   char  *id;
119   {
120          extern char     *getenv();
121 +        static RGBPRIMS myprims = STDPRIMS;
122          static int      atlBest[] = {GLX_RGBA, GLX_RED_SIZE,8,
123                                  GLX_GREEN_SIZE,8, GLX_BLUE_SIZE,8,
124 <                                GLX_ALPHA_SIZE,8, GLX_DEPTH_SIZE,23,
125 <                                /*GLX_DOUBLEBUFFER,*/ None};
118 <        static int      atlOK[] = {GLX_RGBA, GLX_RED_SIZE,4,
119 <                                GLX_GREEN_SIZE,4, GLX_BLUE_SIZE,4,
120 <                                GLX_ALPHA_SIZE,4, GLX_DEPTH_SIZE,15,
121 <                                /*GLX_DOUBLEBUFFER,*/ None};
122 <        char    *gv;
124 >                                GLX_DEPTH_SIZE,15, None};
125 >        char    *ev;
126          double  gamval = GAMMA;
127 +        RGBPRIMP        dpri = stdprims;
128          XSetWindowAttributes    ourwinattr;
129          XWMHints        ourxwmhints;
130          XSizeHints      oursizhints;
131 +                                        /* check for unsupported stereo */
132 + #ifdef NOSTEREO
133 +        error(INTERNAL, "stereo display driver unavailable");
134 + #endif
135                                          /* open display server */
136          ourdisplay = XOpenDisplay(NULL);
137          if (ourdisplay == NULL)
138                  error(USER, "cannot open X-windows; DISPLAY variable set?\n");
139 + #ifdef STEREO
140 +        switch (XSGIQueryStereoMode(ourdisplay, ourroot)) {
141 +        case STEREO_TOP:
142 +        case STEREO_BOTTOM:
143 +                break;
144 +        case STEREO_OFF:
145 +                error(USER,
146 +        "wrong video mode: run \"/usr/gfx/setmon -n STR_TOP\" first");
147 +        case X_STEREO_UNSUPPORTED:
148 +                error(USER, "stereo mode not supported on this screen");
149 +        default:
150 +                error(INTERNAL, "unknown stereo mode");
151 +        }
152 + #endif
153                                          /* find a usable visual */
154          ourvinf = glXChooseVisual(ourdisplay, ourscreen, atlBest);
155          if (ourvinf == NULL)
134                ourvinf = glXChooseVisual(ourdisplay, ourscreen, atlOK);
135        if (ourvinf == NULL)
156                  error(USER, "no suitable visuals available");
157                                          /* get a context */
158          gctx = glXCreateContext(ourdisplay, ourvinf, NULL, GL_TRUE);
159                                          /* set gamma and tone mapping */
160 <        if ((gv = XGetDefault(ourdisplay, "radiance", "gamma")) != NULL
161 <                        || (gv = getenv("DISPLAY_GAMMA")) != NULL)
162 <                gamval = atof(gv);
163 <        if (tmInit(mytmflags(), stdprims, gamval) == NULL)
160 >        if ((ev = XGetDefault(ourdisplay, "radiance", "gamma")) != NULL
161 >                        || (ev = getenv("DISPLAY_GAMMA")) != NULL)
162 >                gamval = atof(ev);
163 >        if ((ev = getenv("DISPLAY_PRIMARIES")) != NULL &&
164 >                        sscanf(ev, "%f %f %f %f %f %f %f %f",
165 >                                &myprims[RED][CIEX],&myprims[RED][CIEY],
166 >                                &myprims[GRN][CIEX],&myprims[GRN][CIEY],
167 >                                &myprims[BLU][CIEX],&myprims[BLU][CIEY],
168 >                                &myprims[WHT][CIEX],&myprims[WHT][CIEY]) >= 6)
169 >                dpri = myprims;
170 >        if (tmInit(mytmflags(), dpri, gamval) == NULL)
171                  error(SYSTEM, "not enough memory in dev_open");
172                                          /* open window */
173          ourwinattr.background_pixel = ourblack;
# Line 151 | Line 178 | char  *id;
178                                  ourvinf->visual, AllocNone);
179          gwind = XCreateWindow(ourdisplay, ourroot, 0, 0,
180                  DisplayWidth(ourdisplay,ourscreen)-2*BORWIDTH,
181 + #ifdef STEREO
182 +                (DisplayHeight(ourdisplay,ourscreen)-2*BORWIDTH)/2,
183 + #else
184                  DisplayHeight(ourdisplay,ourscreen)-2*BORWIDTH,
185 + #endif
186                  BORWIDTH, ourvinf->depth, InputOutput, ourvinf->visual,
187                  CWBackPixel|CWBorderPixel|CWColormap|CWEventMask, &ourwinattr);
188          if (gwind == 0)
# Line 164 | Line 195 | char  *id;
195                          gwind, x11icon_bits, x11icon_width, x11icon_height);
196          XSetWMHints(ourdisplay, gwind, &ourxwmhints);
197          oursizhints.min_width = MINWIDTH;
198 + #ifdef STEREO
199 +        oursizhints.min_height = MINHEIGHT/2;
200 +        oursizhints.max_width = DisplayWidth(ourdisplay,ourscreen)-2*BORWIDTH;
201 +        oursizhints.max_height = (DisplayHeight(ourdisplay,ourscreen) -
202 +                                        2*BORWIDTH)/2;
203 +        oursizhints.flags = PMinSize|PMaxSize;
204 + #else
205          oursizhints.min_height = MINHEIGHT;
206          oursizhints.flags = PMinSize;
207 + #endif
208          XSetNormalHints(ourdisplay, gwind, &oursizhints);
209 <                                        /* map the window and get its size */
210 <        XMapWindow(ourdisplay, gwind);
211 <        dev_input();
212 <                                        /* allocate our value list */
213 <        if (!AllocValues(DisplayWidth(ourdisplay,ourscreen) *
214 <                        DisplayHeight(ourdisplay,ourscreen) / 4))
215 <                error(SYSTEM, "insufficient memory for value storage");
209 >                                        /* set GLX context */
210 >        glXMakeCurrent(ourdisplay, gwind, gctx);
211 >        glEnable(GL_DEPTH_TEST);
212 >        glDepthFunc(GL_LEQUAL);
213 >        glShadeModel(GL_SMOOTH);
214 >        glDisable(GL_DITHER);
215 >        glDisable(GL_CULL_FACE);
216                                          /* figure out sensible view */
217          pwidth = (double)DisplayWidthMM(ourdisplay, ourscreen) /
218                          DisplayWidth(ourdisplay, ourscreen);
219          pheight = (double)DisplayHeightMM(ourdisplay, ourscreen) /
220                          DisplayHeight(ourdisplay, ourscreen);
221 <        copystruct(&odev.v, &stdview);
221 > #ifdef STEREO
222 >        pheight *= 2.;
223 >        setstereobuf(STEREO_BUFFER_LEFT);
224 > #endif
225 >        checkglerr("setting rendering parameters");
226 >        odev.v = stdview;
227          odev.v.type = VT_PER;
228 <        odev.v.horiz = 2.*180./PI * atan(0.5/VIEWDIST*pwidth*odev.hres);
229 <        odev.v.vert = 2.*180./PI * atan(0.5/VIEWDIST*pheight*odev.vres);
228 >                                        /* map the window */
229 >        XMapWindow(ourdisplay, gwind);
230 >        dev_input();                    /* sets size and view angles */
231 >                                        /* allocate our samples */
232 >        if (!smInit(DisplayWidth(ourdisplay,ourscreen) *
233 >                        DisplayHeight(ourdisplay,ourscreen) / 10))
234 >                error(SYSTEM, "insufficient memory for value storage");
235 >        mindpth = FHUGE; maxdpth = FTINY;
236          odev.name = id;
237          odev.ifd = ConnectionNumber(ourdisplay);
188                                        /* set GLX context and clear buffers */
189        glXMakeCurrent(ourdisplay, gwind, gctx);
190        glEnable(GL_DEPTH_TEST);
191        glDepthFunc(GL_LEQUAL);
192        glShadeModel(GL_FLAT);
193        glDisable(GL_DITHER);
194        glDrawBuffer(GL_FRONT_AND_BACK);
195        glReadBuffer(GL_BACK);
196        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
197        setGLview();                    /* initialize view */
238   }
239  
240  
241   dev_close()                     /* close our display and free resources */
242   {
243 +        smInit(0);
244 + #ifdef DOBJ
245 +        dobj_cleanup();
246 + #endif
247          glXMakeCurrent(ourdisplay, None, NULL);
248          glXDestroyContext(ourdisplay, gctx);
249          XDestroyWindow(ourdisplay, gwind);
# Line 207 | Line 251 | dev_close()                    /* close our display and free resources
251          XCloseDisplay(ourdisplay);
252          ourdisplay = NULL;
253          tmDone(NULL);
210        FreeValues();
254          odev.v.type = 0;
255          odev.hres = odev.vres = 0;
256          odev.ifd = -1;
257   }
258  
259  
260 + dev_clear()                     /* clear our representation */
261 + {
262 +        smInit(rsL.max_samp);
263 +        wipeclean(1);
264 +        rayqleft = 0;                   /* hold off update */
265 + }
266 +
267 +
268   int
269   dev_view(nv)                    /* assign new driver view */
270   register VIEW   *nv;
271   {
272 +        double  d;
273 +
274          if (nv->type != VT_PER ||               /* check view legality */
275 <                        nv->horiz > 120. || nv->vert > 120.) {
275 >                        nv->horiz > 160. || nv->vert > 160.) {
276                  error(COMMAND, "illegal view type/angle");
277 <                nv->type = VT_PER;
277 >                nv->type = odev.v.type;
278                  nv->horiz = odev.v.horiz;
279                  nv->vert = odev.v.vert;
280                  return(0);
281          }
282          if (nv != &odev.v) {
283 <                if (!FEQ(nv->horiz,odev.v.horiz) ||     /* resize window? */
283 >                                                /* resize window? */
284 >                if (!FEQ(nv->horiz,odev.v.horiz) ||
285                                  !FEQ(nv->vert,odev.v.vert)) {
286                          int     dw = DisplayWidth(ourdisplay,ourscreen);
287                          int     dh = DisplayHeight(ourdisplay,ourscreen);
288  
289                          dw -= 25;       /* for window frame */
290                          dh -= 50;
291 + #ifdef STEREO
292 +                        dh /= 2;
293 + #endif
294                          odev.hres = 2.*VIEWDIST/pwidth *
295                                          tan(PI/180./2.*nv->horiz);
296                          odev.vres = 2.*VIEWDIST/pheight *
# Line 247 | Line 304 | register VIEW  *nv;
304                                  odev.vres = dh;
305                          }
306                          XResizeWindow(ourdisplay, gwind, odev.hres, odev.vres);
307 +                        dev_input();    /* get resize event */
308                  }
309 <                copystruct(&odev.v, nv);
252 <                setGLview();
309 >                odev.v = *nv;   /* setview() already called */
310          }
311 <        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
312 <        redraw();
311 > #ifdef STEREO
312 >        vwright = *nv;
313 >        d = eyesepdist / sqrt(nv->hn2);
314 >        VSUM(vwright.vp, nv->vp, nv->hvec, d);
315 >        /* setview(&vwright);   -- Unnecessary */
316 > #endif
317 >        wipeclean(0);
318          return(1);
319   }
320  
321  
322 + dev_section(gfn, pfn)           /* add octree for geometry rendering */
323 + char    *gfn, *pfn;
324 + {
325 +        /* unimplemented */
326 + }
327 +
328 +
329 + dev_auxcom(cmd, args)           /* process an auxiliary command */
330 + char    *cmd, *args;
331 + {
332 + #ifdef DOBJ
333 +        if (dobj_command(cmd, args) >= 0)
334 +                return;
335 + #endif
336 +        sprintf(errmsg, "%s: unknown command", cmd);
337 +        error(COMMAND, errmsg);
338 + }
339 +
340 +
341 + VIEW *
342 + dev_auxview(n, hvres)           /* return nth auxiliary view */
343 + int     n;
344 + int     hvres[2];
345 + {
346 +        hvres[0] = odev.hres; hvres[1] = odev.vres;
347 +        if (n == 0)
348 +                return(&odev.v);
349 + #ifdef STEREO
350 +        if (n == 1)
351 +                return(&vwright);
352 + #endif
353 +        return(NULL);
354 + }
355 +
356 +
357   int
358   dev_input()                     /* get X11 input */
359   {
# Line 265 | Line 362 | dev_input()                    /* get X11 input */
362          do
363                  getevent();
364  
365 <        while (XQLength(ourdisplay) > 0);
365 >        while (XPending(ourdisplay) > 0);
366  
367 +        odev.inpready = 0;
368 +
369          return(inpresflags);
370   }
371  
372  
373 < dev_value(c, p, v)              /* add a pixel value to our list */
373 > dev_value(c, d, p)              /* add a pixel value to our mesh */
374   COLR    c;
375 < FVECT   p, v;
375 > FVECT   d, p;
376   {
377 <        register int    li;
378 <
379 <        li = newvalue();
380 <        VCOPY(rV.wp[li], p);
381 <        rV.wd[li] = encodedir(v);
382 <        tmCvColrs(&rV.brt[li], rV.chr[li], c, 1);
377 >        double  depth;
378 > #ifdef DOBJ
379 >        if (dobj_lightsamp != NULL) {   /* in light source sampling */
380 >                (*dobj_lightsamp)(c, d, p);
381 >                return;
382 >        }
383 > #endif
384 >        if (p != NULL) {                /* add depth to our range */
385 >                depth = (p[0] - odev.v.vp[0])*d[0] +
386 >                        (p[1] - odev.v.vp[1])*d[1] +
387 >                        (p[2] - odev.v.vp[2])*d[2];
388 >                if (depth > FTINY) {
389 >                        if (depth < mindpth)
390 >                                mindpth = depth;
391 >                        if (depth > maxdpth)
392 >                                maxdpth = depth;
393 >                }
394 >        }
395 >        smNewSamp(c, d, p);             /* add to display representation */
396 >        if (!--rayqleft)
397 >                dev_flush();            /* flush output */
398   }
399  
400  
# Line 288 | Line 402 | int
402   dev_flush()                     /* flush output */
403   {
404          if (mapped) {
405 <                TMapValues(0);
406 <                while (rV.drl != rV.tl) {
407 <                        drawvalue(rV.drl);
408 <                        if (++rV.drl >= rV.nl)
409 <                                rV.drl = 0;
410 <                }
411 <                glFlush();
405 > #ifdef STEREO
406 >                pushright();                    /* update right eye */
407 >                smUpdate(&vwright, MAXQUALITY);
408 > #ifdef DOBJ
409 >                dobj_render();                  /* usually in foreground */
410 > #endif
411 >                popright();                     /* update left eye */
412 > #endif
413 >                smUpdate(&odev.v, MAXQUALITY);
414 >                checkglerr("rendering mesh");
415 > #ifdef DOBJ
416 >                dobj_render();
417 > #endif
418 >                glFlush();                      /* flush OGL */
419          }
420 <        return(XPending(ourdisplay));
420 >        rayqleft = RAYQLEN;
421 >                                        /* flush X11 and return # pending */
422 >        return(odev.inpready = XPending(ourdisplay));
423   }
424  
425  
426 < static int
427 < mytmflags()                     /* figure out tone mapping flags */
426 > checkglerr(where)               /* check for GL or GLU error */
427 > char    *where;
428   {
429 <        extern char     *progname;
307 <        register char   *cp, *tail;
308 <                                        /* find basic name */
309 <        for (cp = tail = progname; *cp; cp++)
310 <                if (*cp == '/')
311 <                        tail = cp+1;
312 <        for (cp = tail; *cp && *cp != '.'; cp++)
313 <                ;
314 <        if (cp-tail == 3 && !strncmp(tail, "glx", 3))
315 <                return(TM_F_CAMERA);
316 <        if (cp-tail == 4 && !strncmp(tail, "glxh", 4))
317 <                return(TM_F_HUMAN);
318 <        error(USER, "illegal driver name");
319 < }
429 >        register GLenum errcode;
430  
431 <
432 < static
433 < setGLview()                     /* set our GL view */
434 < {
325 <        double  xmin, xmax, ymin, ymax, zmin, zmax;
326 <        double  d, cx, sx, crad;
327 <        FVECT   vx, vy;
328 <        register int    i, j;
329 <                                        /* compute view frustum */
330 <        if (normalize(odev.v.vdir) == 0.0)
331 <                return;
332 <        if (mindepth < maxdepth) {
333 <                zmin = 0.25*mindepth;
334 <                zmax = 8.0*maxdepth;
335 <        } else {
336 <                zmin = 0.01;
337 <                zmax = 1000.;
431 >        while ((errcode = glGetError()) != GL_NO_ERROR) {
432 >                sprintf(errmsg, "OpenGL error %s: %s",
433 >                                where, gluErrorString(errcode));
434 >                error(WARNING, errmsg);
435          }
339        if (odev.v.vfore > FTINY)
340                zmin = odev.v.vfore;
341        if (odev.v.vaft > FTINY)
342                zmax = odev.v.vaft;
343        xmax = zmin * tan(PI/180./2. * odev.v.horiz);
344        xmin = -xmax;
345        d = odev.v.hoff * (xmax - xmin);
346        xmin += d; xmax += d;
347        ymax = zmin * tan(PI/180./2. * odev.v.vert);
348        ymin = -ymax;
349        d = odev.v.voff * (ymax - ymin);
350        ymin += d; ymax += d;
351                                        /* set view matrix */
352        glMatrixMode(GL_PROJECTION);
353        glLoadIdentity();
354        glFrustum(xmin, xmax, ymin, ymax, zmin, zmax);
355        gluLookAt(odev.v.vp[0], odev.v.vp[1], odev.v.vp[2],
356                odev.v.vp[0] + odev.v.vdir[0],
357                odev.v.vp[1] + odev.v.vdir[1],
358                odev.v.vp[2] + odev.v.vdir[2],
359                odev.v.vup[0], odev.v.vup[1], odev.v.vup[2]);
360                                        /* set viewport */
361        glViewport(0, 0, odev.hres, odev.vres);
362                                        /* initialize cone for Vornoi polys */
363        coneh = CONEH*(zmax - zmin);
364        crad = 0.5 * CONEW * 0.5*(xmax-xmin + ymax-ymin) * (zmin+coneh)/zmin;
365        vy[0] = vy[1] = vy[2] = 0.;
366        for (i = 0; i < 3; i++)
367                if (odev.v.vdir[i] < 0.6 && odev.v.vdir[i] > -0.6)
368                        break;
369        vy[i] = 1.;
370        fcross(vx, vy, odev.v.vdir);
371        normalize(vx);
372        fcross(vy, odev.v.vdir, vx);
373        for (j = 0, d = 0.; j < NCONEV; j++, d += 2.*PI/NCONEV) {
374                cx = crad*cos(d); sx = crad*sin(d);
375                for (i = 0; i < 3; i++)
376                        conev[j][i] = coneh*odev.v.vdir[i] +
377                                        cx*vx[i] + sx*vy[i];
378        }
436   }
437  
438  
439 < static int
383 < newvalue()                      /* allocate a leaf from our pile */
384 < {
385 <        int     li;
386 <        
387 <        li = rV.tl++;
388 <        if (rV.tl >= rV.nl)     /* get next leaf in ring */
389 <                rV.tl = 0;
390 <        if (rV.tl == rV.bl)     /* need to shake some free */
391 <                Compost(FREEPCT);
392 <        return(li);
393 < }
394 <
395 <
439 > #ifdef STEREO
440   static
441 < drawvalue(li)                   /* draw a pixel value as a cone */
398 < register int    li;
441 > pushright()                     /* push on right view */
442   {
443 <        static FVECT    apex, disp;
401 <        double  d, h, v;
402 <        register int    i;
403 <                                        /* compute cone's base displacement */
404 <        VCOPY(apex, rV.wp[li]);
405 <        disp[0] = apex[0] - odev.v.vp[0];
406 <        disp[1] = apex[1] - odev.v.vp[1];
407 <        disp[2] = apex[2] - odev.v.vp[2];
408 <        if ((d = DOT(disp,odev.v.vdir)) <= odev.v.vfore || d <= FTINY)
409 <                return;
410 <        if (d > 1e5) {          /* background region */
411 <                if (odev.v.vaft > FTINY)
412 <                        return;
413 <                h = maxdepth/d;
414 <                disp[0] *= h; disp[1] *= h; disp[2] *= h;
415 <                apex[0] = odev.v.vp[0] + disp[0];
416 <                apex[1] = odev.v.vp[1] + disp[1];
417 <                apex[2] = odev.v.vp[2] + disp[2];
418 <                d = maxdepth;
419 <        } else if (d > maxdepth)
420 <                maxdepth = d;
421 <        h = DOT(disp,odev.v.hvec)/(d*odev.v.hn2);
422 <        v = DOT(disp,odev.v.vvec)/(d*odev.v.vn2);
423 <        if (fabs(h - odev.v.hoff) < 0.5 && fabs(v - odev.v.voff) < 0.5 &&
424 <                        d < mindepth)
425 < {
426 < fprintf(stderr, "min depth now %lf (%lf,%lf,%lf)\n", d, apex[0], apex[1], apex[2]);
427 <                mindepth = d;
428 < }
429 <        for (i = 0; i < 3; i++)
430 <                disp[i] = apex[i] + coneh*(h*odev.v.hvec[i] + v*odev.v.vvec[i]);
431 <                                        /* draw pyramid (cone approx.) */
432 <        glColor4ub(rV.rgb[li][0], rV.rgb[li][1], rV.rgb[li][2], rV.alpha[li]);
433 <        glBegin(GL_TRIANGLE_FAN);
434 <        glVertex3f(apex[0], apex[1], apex[2]);
435 <        for (i = 0; i < NCONEV; i++)
436 <                glVertex3d(conev[i][0] + disp[0], conev[i][1] + disp[1],
437 <                                conev[i][2] + disp[2]);
438 <                                        /* connect last side to first */
439 <        glVertex3d(conev[0][0] + disp[0], conev[0][1] + disp[1],
440 <                        conev[0][2] + disp[2]);
441 <        glEnd();                        /* done */
442 < }
443 >        double  d;
444  
445 <
446 < #define LEAFSIZ         (3*sizeof(float)+sizeof(int4)+\
447 <                        sizeof(TMbright)+7*sizeof(BYTE))
448 <
449 < static
450 < AllocValues(n)                  /* allocate space for n values */
450 < register int    n;
451 < {
452 <        unsigned        nbytes;
453 <        register unsigned       i;
454 <
455 <        if (n <= 0)
456 <                return(0);
457 <        if (rV.nl >= n)
458 <                return(rV.nl);
459 <        else if (rV.nl > 0)
460 <                free(rV.base);
461 <                                /* round space up to nearest power of 2 */
462 <        nbytes = n*LEAFSIZ + 8;
463 <        for (i = 1024; nbytes > i; i <<= 1)
464 <                ;
465 <        n = (i - 8) / LEAFSIZ;  /* should we make sure n is even? */
466 <        rV.base = (char *)malloc(n*LEAFSIZ);
467 <        if (rV.base == NULL)
468 <                return(0);
469 <                                /* assign larger alignment types earlier */
470 <        rV.wp = (float (*)[3])rV.base;
471 <        rV.wd = (int4 *)(rV.wp + n);
472 <        rV.brt = (TMbright *)(rV.wd + n);
473 <        rV.chr = (BYTE (*)[3])(rV.brt + n);
474 <        rV.rgb = (BYTE (*)[3])(rV.chr + n);
475 <        rV.alpha = (BYTE *)(rV.rgb + n);
476 <        rV.nl = n;
477 <        rV.drl = rV.tml = rV.bl = rV.tl = 0;
478 <        return(n);
445 >        setstereobuf(STEREO_BUFFER_RIGHT);
446 >        glMatrixMode(GL_MODELVIEW);
447 >        glPushMatrix();
448 >        d = -eyesepdist / sqrt(odev.v.hn2);
449 >        glTranslated(d*odev.v.hvec[0], d*odev.v.hvec[1], d*odev.v.hvec[2]);
450 >        checkglerr("setting right view");
451   }
452  
481 #undef  LEAFSIZ
453  
483
454   static
455 < FreeValues()                    /* free our allocated values */
455 > popright()                      /* pop off right view */
456   {
457 <        if (rV.nl <= 0)
458 <                return;
459 <        free(rV.base);
490 <        rV.base = NULL;
491 <        rV.nl = 0;
457 >        glMatrixMode(GL_MODELVIEW);
458 >        glPopMatrix();
459 >        setstereobuf(STEREO_BUFFER_LEFT);
460   }
461 + #endif
462  
463  
495 static
496 TMapValues(redo)                /* map our values to RGB */
497 int     redo;
498 {
499        int     aorg, alen, borg, blen;
500                                        /* recompute mapping? */
501        if (redo)
502                rV.tml = rV.bl;
503                                        /* already done? */
504        if (rV.tml == rV.tl)
505                return(1);
506                                        /* compute segments */
507        aorg = rV.tml;
508        if (rV.tl >= aorg) {
509                alen = rV.tl - aorg;
510                blen = 0;
511        } else {
512                alen = rV.nl - aorg;
513                borg = 0;
514                blen = rV.tl;
515        }
516                                        /* (re)compute tone mapping? */
517        if (rV.tml == rV.bl) {
518                tmClearHisto();
519                tmAddHisto(rV.brt+aorg, alen, 1);
520                if (blen > 0)
521                        tmAddHisto(rV.brt+borg, blen, 1);
522                if (tmComputeMapping(0., 0., 0.) != TM_E_OK)
523                        return(0);
524                rV.drl = rV.bl;
525        }
526        if (tmMapPixels(rV.rgb+aorg, rV.brt+aorg,
527                        rV.chr+aorg, alen) != TM_E_OK)
528                return(0);
529        if (blen > 0)
530                tmMapPixels(rV.rgb+borg, rV.brt+borg,
531                                rV.chr+borg, blen);
532                                        /* compute unique alpha values */
533        rV.tml = rV.tl;
534        return(1);
535 }
536
537
464   static int
465 < Compost(pct)                    /* free up some values */
540 < int     pct;
465 > mytmflags()                     /* figure out tone mapping flags */
466   {
467 <        int     nused, nclear, nmapped, ndrawn;
468 <                                /* figure out how many values to clear */
469 <        nclear = rV.nl * pct / 100;
470 <        nused = rV.tl - rV.bl;
471 <        if (nused <= 0) nused += rV.nl;
472 <        nclear -= rV.nl - nused;
473 <        if (nclear <= 0)
474 <                return(0);
475 <        if (nclear >= nused) {  /* clear them all */
476 <                rV.drl = rV.tml = rV.bl = rV.tl = 0;
477 <                return(nused);
478 <        }
554 <                                /* else clear values from bottom */
555 <        ndrawn = rV.drl - rV.bl;
556 <        if (ndrawn < 0) ndrawn += rV.nl;
557 <        nmapped = rV.tml - rV.bl;
558 <        if (nmapped < 0) nmapped += rV.nl;
559 <        rV.bl += nclear;
560 <        if (rV.bl >= rV.nl) rV.bl -= rV.nl;
561 <        if (ndrawn < nclear) rV.drl = rV.bl;
562 <        if (nmapped < nclear) rV.tml = rV.bl;
563 <        return(nclear);
467 >        extern char     *progname;
468 >        register char   *cp, *tail;
469 >                                        /* find basic name */
470 >        for (cp = tail = progname; *cp; cp++)
471 >                if (*cp == '/')
472 >                        tail = cp+1;
473 >        for (cp = tail; *cp && *cp != '.'; cp++)
474 >                ;
475 >        if (cp > tail && cp[-1] == 'h')
476 >                return(TM_F_HUMAN|TM_F_NOSTDERR);
477 >        else
478 >                return(TM_F_CAMERA|TM_F_NOSTDERR);
479   }
480  
481  
# Line 585 | Line 500 | getevent()                     /* get next event */
500                  getkey(levptr(XKeyPressedEvent));
501                  break;
502          case ButtonPress:
503 <                getmove(levptr(XButtonPressedEvent));
503 >                if (FRAMESTATE(levptr(XButtonPressedEvent)->state))
504 >                        getframe(levptr(XButtonPressedEvent));
505 >                else
506 >                        getmove(levptr(XButtonPressedEvent));
507                  break;
508          }
509   }
# Line 601 | Line 519 | register FVECT wp[2];
519  
520  
521   static
522 < draw_grids()                    /* draw holodeck section grids */
522 > draw_grids(fore)                /* draw holodeck section grids */
523 > int     fore;
524   {
525 <        static GLubyte  gridrgba[4] = {0x0, 0xff, 0xff, 0x00};
526 <
527 <        if (!mapped)
528 <                return;
529 <        glColor4ub(gridrgba[0], gridrgba[1], gridrgba[2], gridrgba[3]);
611 <                                        /* draw each grid line */
612 <        glBegin(GL_LINES);
525 >        if (fore)
526 >                glColor4ub(0, 255, 255, 0);
527 >        else
528 >                glColor4ub(0, 0, 0, 0);
529 >        glBegin(GL_LINES);              /* draw each grid line */
530          gridlines(draw3dline);
531          glEnd();
532 +        checkglerr("drawing grid lines");
533   }
534  
535 <
536 < static int
619 < FindValue(dx, dy)               /* find a value on the display */
535 > static double
536 > getdistance(dx, dy, direc)      /* distance from fore plane along view ray */
537   int     dx, dy;
538 + FVECT   direc;
539   {
540 <        return(-1);             /* not found */
540 >        GLfloat gldepth;
541 >        double  dist;
542 >
543 >        if (dx<0 | dx>=odev.hres | dy<0 | dy>=odev.vres)
544 >                return(FHUGE);
545 >        glReadPixels(dx,dy, 1,1, GL_DEPTH_COMPONENT,GL_FLOAT, &gldepth);
546 >        if (gldepth <= FTINY)
547 >                return (FHUGE); /* call failed */
548 >        dist = mapdepth(gldepth);
549 >        if (dist >= .99*FHUGE)
550 >                return(FHUGE);
551 >        return((dist-odev.v.vfore)/DOT(direc,odev.v.vdir));
552   }
553  
554  
# Line 628 | Line 557 | moveview(dx, dy, mov, orb)     /* move our view */
557   int     dx, dy, mov, orb;
558   {
559          VIEW    nv;
560 <        FVECT   odir, v1;
561 <        double  d;
560 >        FVECT   odir, v1, wip;
561 >        double  d,d1;
562          register int    li;
563                                  /* start with old view */
564 <        copystruct(&nv, &odev.v);
565 <                                /* change view direction */
566 <        if (mov | orb) {
567 <                if ((li = FindValue(dx, dy)) < 0)
568 <                        return(0);      /* not on window */
569 <                VSUM(odir, rV.wp[li], nv.vp, -1.);
570 <        } else {
571 <                if (viewray(nv.vp, nv.vdir, &odev.v,
572 <                                (dx+.5)/odev.hres, (dy+.5)/odev.vres) < -FTINY)
573 <                        return(0);      /* outside view */
574 <        }
564 >        nv = odev.v;
565 >                                /* orient our motion */
566 >        if (viewray(v1, odir, &odev.v,
567 >                        (dx+.5)/odev.hres, (dy+.5)/odev.vres) < -FTINY)
568 >                return(0);              /* outside view */
569 >        if (mov | orb) {        /* moving relative to geometry */
570 >                d = getdistance(dx, dy, odir);/*distance from front plane */
571 > #ifdef DOBJ
572 >                d1 = dobj_trace(NULL, v1, odir);        /* check objects */
573 >                                                /* check holodeck */
574 >                if (d1 < d)
575 >                        d = d1;
576 > #endif
577 >                if (d >= .99*FHUGE)
578 >                        d = 0.5*(dev_zmax+dev_zmin);    /* just guess */
579 >                VSUM(wip, v1, odir, d);
580 >                VSUB(odir, wip, odev.v.vp);
581 > #if 0
582 >                fprintf(stderr, "moveview: hit %s at (%f,%f,%f) (t=%f)\n",
583 >                                li < 0 ? "object" : "mesh",
584 >                                wip[0], wip[1], wip[2],
585 >                                (wip[0]-odev.v.vp[0])*odir[0] +
586 >                                (wip[1]-odev.v.vp[1])*odir[1] +
587 >                                (wip[2]-odev.v.vp[2])*odir[2]);
588 > #endif
589 >        } else                  /* panning with constant viewpoint */
590 >                VCOPY(nv.vdir, odir);
591          if (orb && mov) {               /* orbit left/right */
592                  spinvector(odir, odir, nv.vup, d=MOVDEG*PI/180.*mov);
593 <                VSUM(nv.vp, rV.wp[li], odir, -1.);
593 >                VSUM(nv.vp, wip, odir, -1.);
594                  spinvector(nv.vdir, nv.vdir, nv.vup, d);
595          } else if (orb) {               /* orbit up/down */
596                  fcross(v1, odir, nv.vup);
597                  if (normalize(v1) == 0.)
598                          return(0);
599                  spinvector(odir, odir, v1, d=MOVDEG*PI/180.*orb);
600 <                VSUM(nv.vp, rV.wp[li], odir, -1.);
600 >                VSUM(nv.vp, wip, odir, -1.);
601                  spinvector(nv.vdir, nv.vdir, v1, d);
602          } else if (mov) {               /* move forward/backward */
603                  d = MOVPCT/100. * mov;
# Line 660 | Line 605 | int    dx, dy, mov, orb;
605          }
606          if (!mov ^ !orb && headlocked) {        /* restore head height */
607                  VSUM(v1, odev.v.vp, nv.vp, -1.);
608 <                d = DOT(v1, odev.v.vup);
608 >                d = DOT(v1, nv.vup);
609                  VSUM(nv.vp, nv.vp, odev.v.vup, d);
610          }
611          if (setview(&nv) != NULL)
# Line 672 | Line 617 | int    dx, dy, mov, orb;
617  
618  
619   static
620 + getframe(ebut)                          /* get focus frame */
621 + XButtonPressedEvent     *ebut;
622 + {
623 +        int     startx = ebut->x, starty = ebut->y;
624 +        int     endx, endy;
625 +
626 +        XMaskEvent(ourdisplay, ButtonReleaseMask, levptr(XEvent));
627 +        endx = levptr(XButtonReleasedEvent)->x;
628 +        endy = levptr(XButtonReleasedEvent)->y;
629 +        if (endx == startx | endy == starty) {
630 +                XBell(ourdisplay, 0);
631 +                return;
632 +        }
633 +        if (endx < startx) {register int c = endx; endx = startx; startx = c;}
634 +        if (endy < starty) {register int c = endy; endy = starty; starty = c;}
635 +        sprintf(odev_args, "%.3f %.3f %.3f %.3f",
636 +                        (startx+.5)/odev.hres, 1.-(endy+.5)/odev.vres,
637 +                        (endx+.5)/odev.hres, 1.-(starty+.5)/odev.vres);
638 +        inpresflags |= DFL(DC_FOCUS);
639 + }
640 +
641 +
642 + static
643   getmove(ebut)                           /* get view change */
644   XButtonPressedEvent     *ebut;
645   {
646          int     movdir = MOVDIR(ebut->button);
647          int     movorb = MOVORB(ebut->state);
648 +        int     qlevel = MAXQUALITY-1;
649 +        time_t  lasttime, thistime;
650 +        int     nframes;
651          Window  rootw, childw;
652          int     rootx, rooty, wx, wy;
653          unsigned int    statemask;
654  
655 <        XNoOp(ourdisplay);
655 >        XNoOp(ourdisplay);              /* makes sure we're not idle */
656  
657 +        nframes = 0;
658          while (!XCheckMaskEvent(ourdisplay,
659                          ButtonReleaseMask, levptr(XEvent))) {
660 <
660 >                                        /* get cursor position */
661                  if (!XQueryPointer(ourdisplay, gwind, &rootw, &childw,
662                                  &rootx, &rooty, &wx, &wy, &statemask))
663                          break;          /* on another screen */
664  
665 +                draw_grids(0);          /* clear old grid lines */
666 + #ifdef STEREO
667 +                pushright(); draw_grids(0); popright();
668 + #endif
669 +                                        /* compute view motion */
670                  if (!moveview(wx, odev.vres-1-wy, movdir, movorb)) {
671                          sleep(1);
672 +                        lasttime++;
673 +                        continue;       /* cursor in bad place */
674 +                }
675 +                draw_grids(1);          /* redraw grid */
676 + #ifdef STEREO
677 +                pushright();
678 +                draw_grids(1);
679 +                smUpdate(&vwright, qlevel);
680 + #ifdef DOBJ
681 +                dobj_render();
682 + #endif
683 +                popright();
684 + #endif
685 +                                        /* redraw mesh */
686 +                smUpdate(&odev.v, qlevel);
687 + #ifdef DOBJ
688 +                dobj_render();          /* redraw object */
689 + #endif
690 +                glFlush();
691 +                                        /* figure out good quality level */
692 +                if (!nframes++) {               /* ignore first frame */
693 +                        lasttime = time(0);
694                          continue;
695                  }
696 <                draw_grids();
697 <                dev_flush();
696 >                thistime = time(0);
697 >                if (thistime - lasttime >= 6 ||
698 >                                nframes > (int)(3*3*TARGETFPS)) {
699 >                        qlevel = thistime<=lasttime ? 3*MAXQUALITY :
700 >                                (int)((double)nframes/(thistime-lasttime)
701 >                                        / TARGETFPS * qlevel + 0.5);
702 >                        nframes = 0;
703 >                        if (qlevel >= MAXQUALITY) {
704 >                                if (qlevel >= 3*MAXQUALITY) {   /* brakes!! */
705 >                                        sleep(1);
706 >                                        lasttime++;
707 >                                }
708 >                                qlevel = MAXQUALITY-1;
709 >                        } else if (qlevel < 1)
710 >                                qlevel = 1;
711 >                }
712          }
713          if (!(inpresflags & DFL(DC_SETVIEW))) { /* do final motion */
714                  movdir = MOVDIR(levptr(XButtonReleasedEvent)->button);
# Line 703 | Line 716 | XButtonPressedEvent    *ebut;
716                  wy = levptr(XButtonReleasedEvent)->y;
717                  moveview(wx, odev.vres-1-wy, movdir, movorb);
718          }
706        dev_flush();
719   }
720  
721  
722   static
723 + setglpersp(vp)                  /* set perspective view in GL */
724 + register VIEW   *vp;
725 + {
726 +        double  d, xmin, xmax, ymin, ymax;
727 +
728 +        if (mindpth >= maxdpth) {
729 +                dev_zmin = 1.;
730 +                dev_zmax = 100.;
731 +        } else {
732 +                dev_zmin = 0.1*mindpth;
733 +                dev_zmax = 5.0*maxdpth;
734 +        }
735 +        if (odev.v.vfore > FTINY)
736 +                dev_zmin = odev.v.vfore;
737 +        if (odev.v.vaft > FTINY)
738 +                dev_zmax = odev.v.vaft;
739 +        if (dev_zmin*500. < dev_zmax)
740 +                dev_zmax = dev_zmin*500.;
741 +        xmax = dev_zmin * tan(PI/180./2. * odev.v.horiz);
742 +        xmin = -xmax;
743 +        d = odev.v.hoff * (xmax - xmin);
744 +        xmin += d; xmax += d;
745 +        ymax = dev_zmin * tan(PI/180./2. * odev.v.vert);
746 +        ymin = -ymax;
747 +        d = odev.v.voff * (ymax - ymin);
748 +        ymin += d; ymax += d;
749 +                                        /* set view matrix */
750 +        glMatrixMode(GL_PROJECTION);
751 +        glLoadIdentity();
752 +        glFrustum(xmin, xmax, ymin, ymax, dev_zmin, dev_zmax);
753 +        gluLookAt(odev.v.vp[0], odev.v.vp[1], odev.v.vp[2],
754 +                odev.v.vp[0] + odev.v.vdir[0],
755 +                odev.v.vp[1] + odev.v.vdir[1],
756 +                odev.v.vp[2] + odev.v.vdir[2],
757 +                odev.v.vup[0], odev.v.vup[1], odev.v.vup[2]);
758 +        checkglerr("setting perspective view");
759 + }
760 +
761 +
762 + static
763 + wipeclean(tmflag)                       /* prepare for redraw */
764 + int     tmflag;
765 + {
766 +                                        /* clear depth buffer */
767 + #ifdef STEREO
768 +        setstereobuf(STEREO_BUFFER_RIGHT);
769 +        glClear(GL_DEPTH_BUFFER_BIT);
770 +        setstereobuf(STEREO_BUFFER_LEFT);
771 + #endif
772 +        glClear(GL_DEPTH_BUFFER_BIT);
773 +        smClean(tmflag);                /* reset drawing routines */
774 +        setglpersp(&odev.v);            /* reset view & clipping planes */
775 + }
776 +
777 +
778 + static
779   getkey(ekey)                            /* get input key */
780   register XKeyPressedEvent  *ekey;
781   {
782 +        Window  rootw, childw;
783 +        int     rootx, rooty, wx, wy;
784 +        unsigned int    statemask;
785          int  n;
786          char    buf[8];
787  
# Line 733 | Line 804 | register XKeyPressedEvent  *ekey;
804          case 'v':                       /* spit out view */
805                  inpresflags |= DFL(DC_GETVIEW);
806                  return;
807 +        case 'f':                       /* frame view position */
808 +                if (!XQueryPointer(ourdisplay, gwind, &rootw, &childw,
809 +                                &rootx, &rooty, &wx, &wy, &statemask))
810 +                        return;         /* on another screen */
811 +                sprintf(odev_args, "%.4f %.4f", (wx+.5)/odev.hres,
812 +                                1.-(wy+.5)/odev.vres);
813 +                inpresflags |= DFL(DC_FOCUS);
814 +                return;
815 +        case 'F':                       /* unfocus */
816 +                odev_args[0] = '\0';
817 +                inpresflags |= DFL(DC_FOCUS);
818 +                return;
819          case '\n':
820          case '\r':                      /* resume computation */
821                  inpresflags |= DFL(DC_RESUME);
822                  return;
823          case CTRL('R'):                 /* redraw screen */
824 <                TMapValues(1);
742 <                redraw();
824 >                wipeclean(1);
825                  return;
826          case CTRL('L'):                 /* refresh from server */
827                  if (inpresflags & DFL(DC_REDRAW))
828                          return;
829 +                setglpersp(&odev.v);            /* reset clipping planes */
830                  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
831 <                glDrawBuffer(GL_FRONT);
832 <                glDisable(GL_DEPTH_TEST);
833 <                draw_grids();
831 >                glDisable(GL_DEPTH_TEST);       /* so grids will clear */
832 >                draw_grids(1);
833 > #ifdef STEREO
834 >                pushright();
835 >                glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
836 >                draw_grids(1);
837 >                popright();
838 > #endif
839                  glEnable(GL_DEPTH_TEST);
752                glDrawBuffer(GL_FRONT_AND_BACK);
840                  glFlush();
841 <                Compost(100);                   /* get rid of old values */
841 >                smInit(rsL.max_samp);           /* get rid of old values */
842                  inpresflags |= DFL(DC_REDRAW);  /* resend values from server */
843 +                rayqleft = 0;                   /* hold off update */
844                  return;
845          case 'K':                       /* kill rtrace process(es) */
846                  inpresflags |= DFL(DC_KILL);
# Line 777 | Line 865 | static
865   fixwindow(eexp)                         /* repair damage to window */
866   register XExposeEvent  *eexp;
867   {
868 <        if (odev.hres == 0 || odev.vres == 0) { /* first exposure */
869 <                odev.hres = eexp->width;
870 <                odev.vres = eexp->height;
868 >        if (odev.hres == 0 | odev.vres == 0) {  /* first exposure */
869 >                resizewindow((XConfigureEvent *)eexp);
870 >                return;
871          }
872 <        if (eexp->width == odev.hres && eexp->height == odev.vres)
873 <                TMapValues(1);
874 <        if (!eexp->count)
787 <                redraw();
872 >        if (eexp->count)                /* wait for final exposure */
873 >                return;
874 >        wipeclean(0);                   /* clear depth */
875   }
876  
877  
# Line 792 | Line 879 | static
879   resizewindow(ersz)                      /* resize window */
880   register XConfigureEvent  *ersz;
881   {
882 +        glViewport(0, 0, ersz->width, ersz->height);
883 +
884          if (ersz->width == odev.hres && ersz->height == odev.vres)
885                  return;
886  
# Line 800 | Line 889 | register XConfigureEvent  *ersz;
889  
890          odev.v.horiz = 2.*180./PI * atan(0.5/VIEWDIST*pwidth*odev.hres);
891          odev.v.vert = 2.*180./PI * atan(0.5/VIEWDIST*pheight*odev.vres);
803
804        setGLview();
892  
893          inpresflags |= DFL(DC_SETVIEW);
894   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines