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.3 by gwlarson, Tue Jun 9 15:16:55 1998 UTC vs.
Revision 3.7 by gwlarson, Tue Jul 7 08:58:34 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 30 | Line 33 | static char SCCSid[] = "$SunId$ SGI";
33   #define MOVDEG          (-5)            /* degrees to orbit CW/down /frame */
34   #define MOVORB(s)       ((s)&ShiftMask ? 1 : (s)&ControlMask ? -1 : 0)
35  
33 #define MINWIDTH        480             /* minimum graphics window width */
34 #define MINHEIGHT       400             /* minimum graphics window height */
35
36   #define BORWIDTH        5               /* border width */
37  
38   #define  ourscreen      DefaultScreen(ourdisplay)
# Line 65 | Line 65 | struct {
65  
66   int     currentview = 0;                /* current view number */
67   VIEW    thisview = STDVIEW;             /* displayed view */
68 + double  eyedist = 1;                    /* interocular distance */
69   VIEW    lastview;                       /* last recorded view */
70  
71   char    *progname;                      /* global argv[0] */
# Line 75 | Line 76 | char   *octree;                        /* octree name (NULL if unnec.) */
76  
77   int     rtpd[3];                        /* rtrace process descriptors */
78  
79 + int     silent = 0;                     /* run rad silently? */
80   int     backvis = 1;                    /* back faces visible? */
81 + int     stereo = 0;                     /* do stereo? */
82  
83 + #ifdef NOSTEREO
84 + #define setstereobuf(bid)       0
85 + #else
86 + #define setstereobuf(bid)       (glXWaitGL(), \
87 +                                XSGISetStereoBuffer(ourdisplay, gwind, bid), \
88 +                                glXWaitX())
89 + #endif
90 +
91   int     displist;                       /* our scene display list */
92  
93 < int     in_dev_view = 0;                /* currently in dev_view() */
93 > int     no_render = 0;                  /* don't rerender */
94  
95 < extern char     *fgets(), *fgetline(), *atos(), *scan4var();
95 > #ifdef BSD
96 > #define strchr          index
97 > #endif
98 >
99 > extern char     *strchr(), *fgets(), *fgetline(), *atos(), *scan4var();
100   extern int      nowarn;                 /* turn warnings off? */
101   extern time_t   time();
102  
# Line 103 | Line 118 | char   *argv[];
118                  case 'w':
119                          nowarn = !nowarn;
120                          break;
121 +                case 's':
122 +                        silent = !silent;
123 +                        break;
124 +                case 'S':
125 +                        stereo = !stereo;
126 +                        break;
127                  case 'c':
128                          vwintvl = atoi(argv[++i]);
129                          break;
# Line 114 | Line 135 | char   *argv[];
135                  }
136          if (i >= argc)
137                  goto userr;
138 + #ifdef NOSTEREO
139 +        if (stereo)
140 +                error(INTERNAL, "stereo not supported in this version");
141 + #endif
142                                          /* run rad and get views */
143          runrad(argc-i, argv+i);
144                                          /* check view */
# Line 196 | Line 221 | char   **av;
221                                          /* set rad commmand */
222          strcpy(radcomm, "rad -w -v 0        "); /* look out below! */
223          cp = radcomm + 19;
224 +        if (silent) {
225 +                strcpy(cp, "-s ");
226 +                cp += 3;
227 +        }
228          while (ac--) {
229                  strcpy(cp, *av++);
230                  while (*cp) cp++;
# Line 218 | Line 247 | char   **av;
247                          expval = pow(2., expval);
248                  expval *= 0.5;          /* compensate for local shading */
249          }
250 +                                                /* look for eye separation */
251 +        if ((cp = scan4var(buf, sizeof(buf), "EYESEP", fp)) != NULL)
252 +                eyedist = atof(cp);
253                                                  /* look for materials */
254          while ((cp = scan4var(buf, sizeof(buf), "materials", fp)) != NULL) {
255                  nscenef += wordstring(scene+nscenef, cp);
# Line 258 | Line 290 | char   **av;
290                                                  /* open options file */
291          if ((fp = fopen(optfile, "r")) == NULL)
292                  error(SYSTEM, "cannot open options file");
293 <                                                /* get ambient value */
293 >                                                /* get relevant options */
294          while (fgets(buf, sizeof(buf), fp) != NULL)
295 <                if (!strncmp(buf, "-av ", 4)) {
295 >                if (!strncmp(buf, "-av ", 4))
296                          setcolor(ambval, atof(buf+4),
297                                          atof(sskip2(buf+4,1)),
298                                          atof(sskip2(buf+4,2)));
299 <                        break;
300 <                }
299 >                else if (backvis && !strncmp(buf, "-bv", 3) &&
300 >                                (!buf[3] || strchr(" 0-FfNn", buf[3]) != NULL))
301 >                        backvis = 0;
302          fclose(fp);
303          unlink(optfile);                        /* delete options file */
304   }
# Line 338 | Line 371 | char  *id;
371                                  GLX_DOUBLEBUFFER, GLX_DEPTH_SIZE,15, None};
372          XSetWindowAttributes    ourwinattr;
373          XWMHints        ourxwmhints;
341        XSizeHints      oursizhints;
374                                          /* open display server */
375          ourdisplay = XOpenDisplay(NULL);
376          if (ourdisplay == NULL)
# Line 364 | Line 396 | char  *id;
396          if (gwind == 0)
397                  error(SYSTEM, "cannot create window\n");
398          XStoreName(ourdisplay, gwind, id);
399 + #ifndef NOSTEREO
400 +        if (stereo)                     /* check if stereo working */
401 +                switch (XSGIQueryStereoMode(ourdisplay, gwind)) {
402 +                case STEREO_TOP:
403 +                case STEREO_BOTTOM:
404 +                        break;
405 +                case STEREO_OFF:
406 +                        error(USER,
407 +                "wrong video mode: run \"/usr/gfx/setmon -n STR_TOP\" first");
408 +                case X_STEREO_UNSUPPORTED:
409 +                        error(USER, "stereo not supported on this screen");
410 +                default:
411 +                        error(INTERNAL, "unknown stereo mode");
412 +                }
413 + #endif
414                                          /* set window manager hints */
415          ourxwmhints.flags = InputHint|IconPixmapHint;
416          ourxwmhints.input = True;
417          ourxwmhints.icon_pixmap = XCreateBitmapFromData(ourdisplay,
418                  gwind, glradicon_bits, glradicon_width, glradicon_height);
419          XSetWMHints(ourdisplay, gwind, &ourxwmhints);
373        oursizhints.min_width = MINWIDTH;
374        oursizhints.min_height = MINHEIGHT;
375        oursizhints.flags = PMinSize;
376        XSetNormalHints(ourdisplay, gwind, &oursizhints);
420                                          /* set GLX context */
421          glXMakeCurrent(ourdisplay, gwind, gctx);
422          glEnable(GL_DEPTH_TEST);
423          glDepthFunc(GL_LESS);
424          glShadeModel(GL_SMOOTH);
425          glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
426 <        glLightModelf(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
426 >        glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
427          glEnable(GL_LIGHTING);
428          if (backvis)
429                  glDisable(GL_CULL_FACE);
# Line 395 | Line 438 | char  *id;
438                          DisplayWidth(ourdisplay, ourscreen);
439          pheight = (double)DisplayHeightMM(ourdisplay, ourscreen) /
440                          DisplayHeight(ourdisplay, ourscreen);
441 +        if (stereo) {                   /* set stereo mode */
442 +                setstereobuf(STEREO_BUFFER_LEFT);
443 +                pheight *= 2.;
444 +        }
445                                          /* map the window */
446          XMapWindow(ourdisplay, gwind);
447 +        no_render++;
448          do
449                  dev_input(0);           /* get resize event */
450          while (hres == 0 & vres == 0);
451 +        no_render--;
452          rgl_checkerr("initializing GLX");
453   }
454  
# Line 450 | Line 499 | register VIEW  *nv;
499                          }
500                  }
501                  if (newhres != hres | newvres != vres) {
502 <                        in_dev_view++;
502 >                        no_render++;
503                          XResizeWindow(ourdisplay, gwind, newhres, newvres);
504                          do
505                                  dev_input(0);           /* get resize event */
506                          while (newhres != hres | newvres != vres);
507 <                        in_dev_view--;
507 >                        no_render--;
508                  }
509          }
510          copystruct(&thisview, nv);
# Line 507 | Line 556 | int    nsecs;
556  
557   render()                        /* render our display list and swap buffers */
558   {
559 <        if (!mapped)
559 >        double  d;
560 >
561 >        if (!mapped | no_render)
562                  return;
563          glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
564          glCallList(displist);
565 +        if (stereo) {                           /* do right eye for stereo */
566 +                setstereobuf(STEREO_BUFFER_RIGHT);
567 +                glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
568 +                glMatrixMode(GL_MODELVIEW);
569 +                glPushMatrix();
570 +                d = -eyedist / sqrt(thisview.hn2);
571 +                glTranslated(d*thisview.hvec[0], d*thisview.hvec[1],
572 +                                d*thisview.hvec[2]);
573 +                glCallList(displist);
574 +                glMatrixMode(GL_MODELVIEW);
575 +                glPopMatrix();
576 +                setstereobuf(STEREO_BUFFER_LEFT);
577 +        }
578          glXSwapBuffers(ourdisplay, gwind);      /* calls glFlush() */
579          rgl_checkerr("rendering display list");
580   }
# Line 745 | Line 809 | int    vwnum;
809                          ;
810          else if (vwnum >= MAXVIEW || vwl[vwnum].v == NULL)
811                  vwnum = 0;
812 <        if (vwnum == currentview)
749 <                return;
750 <        /* copylastv("change view"); */
812 >        copylastv("standard view");
813          dev_view(vwl[currentview=vwnum].v);
814   }
815  
# Line 820 | Line 882 | register XConfigureEvent  *ersz;
882          glViewport(0, 0, hres=ersz->width, vres=ersz->height);
883          if (hres > maxhres) maxhres = hres;
884          if (vres > maxvres) maxvres = vres;
885 <        if (in_dev_view)
885 >        if (no_render)
886                  return;
887          wa = (vres*pheight)/(hres*pwidth);
888          va = viewaspect(&thisview);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines