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

Comparing ray/src/util/glrad.c (file contents):
Revision 3.1 by gwlarson, Tue Jun 9 11:43:18 1998 UTC vs.
Revision 3.4 by gwlarson, Wed Jun 10 17:52:18 1998 UTC

# Line 13 | Line 13 | static char SCCSid[] = "$SunId$ SGI";
13   #include "paths.h"
14   #include <sys/types.h>
15   #include <GL/glx.h>
16 + #ifndef NOSTEREO
17 + #include <X11/extensions/SGIStereo.h>
18 + #endif
19   #include <ctype.h>
20   #include "glradicon.h"
21  
# Line 65 | Line 68 | struct {
68  
69   int     currentview = 0;                /* current view number */
70   VIEW    thisview = STDVIEW;             /* displayed view */
71 + double  eyedist = 1;                    /* interocular distance */
72   VIEW    lastview;                       /* last recorded view */
69 char    *lastvc = NULL;                 /* cause of last view change */
73  
74   char    *progname;                      /* global argv[0] */
75   char    *radfile;                       /* rad input file */
# Line 76 | Line 79 | char   *octree;                        /* octree name (NULL if unnec.) */
79  
80   int     rtpd[3];                        /* rtrace process descriptors */
81  
82 + int     silent = 0;                     /* run rad silently? */
83   int     backvis = 1;                    /* back faces visible? */
84 + int     stereo = 0;                     /* do stereo? */
85  
86 + #ifdef NOSTEREO
87 + #define setstereobuf(bid)       0
88 + #else
89 + #define setstereobuf(bid)       (glXWaitGL(), \
90 +                                XSGISetStereoBuffer(ourdisplay, gwind, bid), \
91 +                                glXWaitX())
92 + #endif
93 +
94   int     displist;                       /* our scene display list */
95  
96 < extern char     *fgets(), *fgetline(), *atos(), *scan4var();
96 > int     in_dev_view = 0;                /* currently in dev_view() */
97 >
98 > #ifdef BSD
99 > #define strchr          index
100 > #endif
101 >
102 > extern char     *strchr(), *fgets(), *fgetline(), *atos(), *scan4var();
103   extern int      nowarn;                 /* turn warnings off? */
104   extern time_t   time();
105  
# Line 102 | Line 121 | char   *argv[];
121                  case 'w':
122                          nowarn = !nowarn;
123                          break;
124 +                case 's':
125 +                        silent = !silent;
126 +                        break;
127 +                case 'S':
128 +                        stereo = !stereo;
129 +                        break;
130                  case 'c':
131                          vwintvl = atoi(argv[++i]);
132                          break;
# Line 113 | Line 138 | char   *argv[];
138                  }
139          if (i >= argc)
140                  goto userr;
141 + #ifdef NOSTEREO
142 +        if (stereo)
143 +                error(INTERNAL, "stereo not supported in this version");
144 + #endif
145                                          /* run rad and get views */
146          runrad(argc-i, argv+i);
147                                          /* check view */
148 <        if (viewsel != NULL && (currentview = findvw(viewsel)) < 0) {
149 <                fprintf(stderr, "%s: no such view\n", viewsel);
150 <                quit(1);
151 <        }
148 >        if (viewsel != NULL)
149 >                if (viewsel[0] == '-') {
150 >                        char    *ve = viewsel;
151 >                        if (!sscanview(&thisview, viewsel) ||
152 >                                        (ve = setview(&thisview)) != NULL) {
153 >                                fprintf(stderr, "%s: bad view: %s\n",
154 >                                                progname, ve);
155 >                                quit(1);
156 >                        }
157 >                        currentview = -1;
158 >                } else if ((currentview = findvw(viewsel)) < 0) {
159 >                        fprintf(stderr, "%s: no such view: %s\n",
160 >                                                progname, viewsel);
161 >                        quit(1);
162 >                }
163                                          /* open GL */
164          dev_open(radfile = argv[i]);
165                                          /* load octree or scene files */
# Line 129 | Line 169 | char   *argv[];
169          } else
170                  displist = rgl_filelist(nscenef, scene);
171                                          /* set initial view */
172 <        dev_view(vwl[currentview].v);
172 >        dev_view(currentview < 0 ? &thisview : vwl[currentview].v);
173                                          /* input/render loop */
174          while (dev_input(vwintvl))
175                  ;
176                                          /* all done */
177          quit(0);
178   userr:
179 <        fprintf(stderr, "Usage: %s [-w][-c #secs][-v view] rfile [VAR=value]..\n",
179 >        fprintf(stderr, "Usage: %s [-w][-b][-v view] rfile [VAR=value]..\n",
180                          argv[0]);
181          quit(1);
182   }
# Line 184 | Line 224 | char   **av;
224                                          /* set rad commmand */
225          strcpy(radcomm, "rad -w -v 0        "); /* look out below! */
226          cp = radcomm + 19;
227 +        if (silent) {
228 +                strcpy(cp, "-s ");
229 +                cp += 3;
230 +        }
231          while (ac--) {
232                  strcpy(cp, *av++);
233                  while (*cp) cp++;
# Line 204 | Line 248 | char   **av;
248                  expval = atof(cp);
249                  if (*cp == '-' | *cp == '+')
250                          expval = pow(2., expval);
251 +                expval *= 0.5;          /* compensate for local shading */
252          }
253 +                                                /* look for eye separation */
254 +        if ((cp = scan4var(buf, sizeof(buf), "EYESEP", fp)) != NULL)
255 +                eyedist = atof(cp);
256                                                  /* look for materials */
257          while ((cp = scan4var(buf, sizeof(buf), "materials", fp)) != NULL) {
258                  nscenef += wordstring(scene+nscenef, cp);
# Line 245 | Line 293 | char   **av;
293                                                  /* open options file */
294          if ((fp = fopen(optfile, "r")) == NULL)
295                  error(SYSTEM, "cannot open options file");
296 <                                                /* get ambient value */
296 >                                                /* get relevant options */
297          while (fgets(buf, sizeof(buf), fp) != NULL)
298 <                if (!strncmp(buf, "-av ", 4)) {
298 >                if (!strncmp(buf, "-av ", 4))
299                          setcolor(ambval, atof(buf+4),
300                                          atof(sskip2(buf+4,1)),
301                                          atof(sskip2(buf+4,2)));
302 <                        break;
303 <                }
302 >                else if (backvis && !strncmp(buf, "-bv", 3) &&
303 >                                (!buf[3] || strchr(" 0-FfNn", buf[3]) != NULL))
304 >                        backvis = 0;
305          fclose(fp);
306          unlink(optfile);                        /* delete options file */
307   }
# Line 351 | Line 400 | char  *id;
400          if (gwind == 0)
401                  error(SYSTEM, "cannot create window\n");
402          XStoreName(ourdisplay, gwind, id);
403 + #ifndef NOSTEREO
404 +        if (stereo)                     /* check if stereo working */
405 +                switch (XSGIQueryStereoMode(ourdisplay, gwind)) {
406 +                case STEREO_TOP:
407 +                case STEREO_BOTTOM:
408 +                        break;
409 +                case STEREO_OFF:
410 +                        error(USER,
411 +                "wrong video mode: run \"/usr/gfx/setmon -n STR_TOP\" first");
412 +                case X_STEREO_UNSUPPORTED:
413 +                        error(USER, "stereo not supported on this screen");
414 +                default:
415 +                        error(INTERNAL, "unknown stereo mode");
416 +                }
417 + #endif
418                                          /* set window manager hints */
419          ourxwmhints.flags = InputHint|IconPixmapHint;
420          ourxwmhints.input = True;
# Line 358 | Line 422 | char  *id;
422                  gwind, glradicon_bits, glradicon_width, glradicon_height);
423          XSetWMHints(ourdisplay, gwind, &ourxwmhints);
424          oursizhints.min_width = MINWIDTH;
425 <        oursizhints.min_height = MINHEIGHT;
425 >        oursizhints.min_height = stereo ? MINHEIGHT/2 : MINHEIGHT;
426          oursizhints.flags = PMinSize;
427          XSetNormalHints(ourdisplay, gwind, &oursizhints);
428                                          /* set GLX context */
# Line 382 | Line 446 | char  *id;
446                          DisplayWidth(ourdisplay, ourscreen);
447          pheight = (double)DisplayHeightMM(ourdisplay, ourscreen) /
448                          DisplayHeight(ourdisplay, ourscreen);
449 +        if (stereo) {                   /* set stereo mode */
450 +                setstereobuf(STEREO_BUFFER_LEFT);
451 +                pheight *= 2.;
452 +        }
453                                          /* map the window */
454          XMapWindow(ourdisplay, gwind);
455 +        do
456 +                dev_input(0);           /* get resize event */
457 +        while (hres == 0 & vres == 0);
458          rgl_checkerr("initializing GLX");
459   }
460  
# Line 419 | Line 490 | register VIEW  *nv;
490          }
491          if (hres != 0 & vres != 0) {
492                  wa = (vres*pheight)/(hres*pwidth);
493 <                va = viewaspect(&thisview);
493 >                va = viewaspect(nv);
494                  if (va > wa+.05) {
495                          newvres = (pwidth/pheight)*va*newhres + .5;
496                          if (newvres > maxvres) {
# Line 434 | Line 505 | register VIEW  *nv;
505                          }
506                  }
507                  if (newhres != hres | newvres != vres) {
508 +                        in_dev_view++;
509                          XResizeWindow(ourdisplay, gwind, newhres, newvres);
510                          do
511                                  dev_input(0);           /* get resize event */
512                          while (newhres != hres | newvres != vres);
513 +                        in_dev_view--;
514                  }
515          }
516          copystruct(&thisview, nv);
# Line 489 | Line 562 | int    nsecs;
562  
563   render()                        /* render our display list and swap buffers */
564   {
565 +        double  d;
566 +
567          if (!mapped)
568                  return;
569          glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
570          glCallList(displist);
571 +        if (stereo) {                           /* do right eye for stereo */
572 +                setstereobuf(STEREO_BUFFER_RIGHT);
573 +                glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
574 +                glMatrixMode(GL_MODELVIEW);
575 +                glPushMatrix();
576 +                d = -eyedist / sqrt(thisview.hn2);
577 +                glTranslated(d*thisview.hvec[0], d*thisview.hvec[1],
578 +                                d*thisview.hvec[2]);
579 +                glCallList(displist);
580 +                glMatrixMode(GL_MODELVIEW);
581 +                glPopMatrix();
582 +                setstereobuf(STEREO_BUFFER_LEFT);
583 +        }
584          glXSwapBuffers(ourdisplay, gwind);      /* calls glFlush() */
585          rgl_checkerr("rendering display list");
586   }
# Line 554 | Line 642 | XButtonPressedEvent    *ebut;
642          int     rootx, rooty, wx, wy;
643          unsigned int    statemask;
644  
645 <        copylastv("moving");
645 >        copylastv( movorb ? (movdir ? "left/right" : "up/down") :
646 >                        (movdir ? "fore/back" : "rotate") );
647          XNoOp(ourdisplay);
648  
649          while (!XCheckMaskEvent(ourdisplay,
# Line 609 | Line 698 | register VIEW  *vp;
698   {
699          double  d, xmin, xmax, ymin, ymax, zmin, zmax;
700  
701 <        zmin = 0.05;
702 <        zmax = 5000.;
701 >        zmin = 0.1;
702 >        zmax = 1000.;
703          if (thisview.vfore > FTINY)
704                  zmin = thisview.vfore;
705          if (thisview.vaft > FTINY)
# Line 654 | Line 743 | register XKeyPressedEvent  *ekey;
743                  headlocked = 0;
744                  break;
745          case 'l':                       /* retrieve last (premouse) view */
746 <                if (lastvc != NULL) {
746 >                if (lastview.type) {
747                          VIEW    vtmp;
748                          copystruct(&vtmp, &thisview);
749                          dev_view(&lastview);
# Line 728 | Line 817 | int    vwnum;
817                  vwnum = 0;
818          if (vwnum == currentview)
819                  return;
820 +        copylastv("standard view");
821          dev_view(vwl[currentview=vwnum].v);
822   }
823  
# Line 768 | Line 858 | VIEW   *vp;
858   copylastv(cause)                        /* copy last view position */
859   char    *cause;
860   {
861 +        static char     *lastvc;
862 +
863          if (cause == lastvc)
864                  return;                 /* only record one view per cause */
865          lastvc = cause;
# Line 798 | Line 890 | register XConfigureEvent  *ersz;
890          glViewport(0, 0, hres=ersz->width, vres=ersz->height);
891          if (hres > maxhres) maxhres = hres;
892          if (vres > maxvres) maxvres = vres;
893 +        if (in_dev_view)
894 +                return;
895          wa = (vres*pheight)/(hres*pwidth);
896          va = viewaspect(&thisview);
897          if (va > wa+.05) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines