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.6 by gwlarson, Fri Jun 19 11:29:50 1998 UTC vs.
Revision 3.18 by schorsch, Fri Jan 2 12:51:54 2004 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1998 Silicon Graphics, Inc. */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ SGI";
2 > static const char       RCSid[] = "$Id$";
3   #endif
6
4   /*
5   * Program to display Radiance scene using OpenGL.
6   */
7  
11 #include "radogl.h"
12 #include "view.h"
13 #include "paths.h"
8   #include <sys/types.h>
9   #include <GL/glx.h>
10   #ifndef NOSTEREO
11   #include <X11/extensions/SGIStereo.h>
12   #endif
13   #include <ctype.h>
14 + #include <string.h>
15 + #include <time.h>
16 +
17 + #include "radogl.h"
18 + #include "view.h"
19 + #include "paths.h"
20   #include "glradicon.h"
21 + #include "rtprocess.h"
22  
23   #ifndef MAXVIEW
24   #define MAXVIEW         63              /* maximum number of standard views */
# Line 74 | Line 75 | char   *scene[MAXSCENE+1];             /* material and scene file l
75   int     nscenef = 0;                    /* number of scene files */
76   char    *octree;                        /* octree name (NULL if unnec.) */
77  
78 < int     rtpd[3];                        /* rtrace process descriptors */
78 > SUBPROC rtpd;                   /* rtrace process descriptors */
79  
80   int     silent = 0;                     /* run rad silently? */
81   int     backvis = 1;                    /* back faces visible? */
82   int     stereo = 0;                     /* do stereo? */
83  
84   #ifdef NOSTEREO
85 < #define setstereobuf(bid)       0
85 > #define setstereobuf(bid)      
86   #else
87   #define setstereobuf(bid)       (glXWaitGL(), \
88                                  XSGISetStereoBuffer(ourdisplay, gwind, bid), \
# Line 92 | Line 93 | int    displist;                       /* our scene display list */
93  
94   int     no_render = 0;                  /* don't rerender */
95  
95 #ifdef BSD
96 #define strchr          index
97 #endif
98
99 extern char     *strchr(), *fgets(), *fgetline(), *atos(), *scan4var();
96   extern int      nowarn;                 /* turn warnings off? */
101 extern time_t   time();
97  
98 + static void startrtrace(char    *octname);
99 + static void runrad(int  ac, char        **av);
100 + static int findvw(register char *nm);
101 + static int varmatch(register char       *s, register char       *vn);
102 + static char * scan4var(char     *buf, int       buflen, char    *vname, FILE    *fp);
103 + static void dev_open(char  *id);
104 + static void dev_close(void);
105 + static int dev_view(register VIEW       *nv);
106 + static int dev_input(int        nsecs);
107 + static void render(void);
108 + static int moveview(int dx, int dy, int mov, int        orb);
109 + static void waitabit(void);
110 + static void getmove(XButtonPressedEvent *ebut);
111 + static int getintersect(FVECT   wp, FVECT       org, FVECT      dir, double     md);
112 + static void setglpersp(register VIEW    *vp);
113 + static int getkey(register XKeyPressedEvent  *ekey);
114 + static void zoomview(int        pct, int        dx, int dy);
115 + static void gotoview(int        vwnum);
116 + static void appendview(char     *nm, VIEW       *vp);
117 + static void copylastv(char      *cause);
118 + static void fixwindow(register XExposeEvent  *eexp);
119 + static void resizewindow(register XConfigureEvent  *ersz);
120  
121 < main(argc, argv)
122 < int     argc;
123 < char    *argv[];
121 >
122 > int
123 > main(
124 >        int     argc,
125 >        char    *argv[]
126 > )
127   {
128          char    *viewsel = NULL;
129          long    vwintvl = 0;
# Line 142 | Line 162 | char   *argv[];
162                                          /* run rad and get views */
163          runrad(argc-i, argv+i);
164                                          /* check view */
165 <        if (viewsel != NULL)
165 >        if (viewsel != NULL) {
166                  if (viewsel[0] == '-') {
167                          char    *ve = viewsel;
168                          if (!sscanview(&thisview, viewsel) ||
# Line 157 | Line 177 | char   *argv[];
177                                                  progname, viewsel);
178                          quit(1);
179                  }
180 +        }
181                                          /* open GL */
182          dev_open(radfile = argv[i]);
183                                          /* load octree or scene files */
184          if (octree != NULL) {
185 <                displist = rgl_octlist(octree, NULL, NULL);
185 >                displist = rgl_octlist(octree, NULL, NULL, NULL);
186                  startrtrace(octree);
187          } else
188 <                displist = rgl_filelist(nscenef, scene);
188 >                displist = rgl_filelist(nscenef, scene, NULL);
189                                          /* set initial view */
190          dev_view(currentview < 0 ? &thisview : vwl[currentview].v);
191                                          /* input/render loop */
# Line 173 | Line 194 | char   *argv[];
194                                          /* all done */
195          quit(0);
196   userr:
197 <        fprintf(stderr, "Usage: %s [-w][-b][-v view] rfile [VAR=value]..\n",
197 >        fprintf(stderr,
198 >                "Usage: %s [-w][-s][-b][-S][-v view] rfile [VAR=value]..\n",
199                          argv[0]);
200          quit(1);
201 +        return 1; /* pro forma return */
202   }
203  
204  
205 + void
206   quit(code)                              /* exit gracefully */
207   int     code;
208   {
209          if (ourdisplay != NULL)
210                  dev_close();
211 <        if (rtpd[2] > 0) {
212 <                if (close_process(rtpd) > 0)
211 >        /* if (rtpd.pid > 0) { */
212 >        if (rtpd.running) {
213 >                if (close_process(&rtpd) > 0)
214                          wputs("bad exit status from rtrace\n");
215 <                rtpd[2] = 0;
215 >                /* rtpd.pid = 0; */
216          }
217          exit(code);
218   }
219  
220  
221 < startrtrace(octname)                    /* start rtrace on octname */
222 < char    *octname;
221 > static void
222 > startrtrace(                    /* start rtrace on octname */
223 >        char    *octname
224 > )
225   {
226          static char     *av[12] = {"rtrace", "-h", "-fff", "-ld+",
227                                          "-opL", "-x", "1"};
# Line 203 | Line 230 | char   *octname;
230          if (nowarn) av[ac++] = "-w-";
231          av[ac++] = octname;
232          av[ac] = NULL;
233 <        if (open_process(rtpd, av) <= 0)
233 >        if (open_process(&rtpd, av) <= 0)
234                  error(SYSTEM, "cannot start rtrace process");
235   }
236  
237  
238 < runrad(ac, av)                          /* run rad and load variables */
239 < int     ac;
240 < char    **av;
238 > static void
239 > runrad(                         /* run rad and load variables */
240 >        int     ac,
241 >        char    **av
242 > )
243   {
244          static char     optfile[] = TEMPLATE;
245          int     nvn = 0, nvv = 0;
246          FILE    *fp;
218        int     cval;
247          register char   *cp;
248          char    radcomm[256], buf[128], nam[32];
249                                          /* set rad commmand */
# Line 243 | Line 271 | char   **av;
271                                                  /* get exposure */
272          if ((cp = scan4var(buf, sizeof(buf), "EXPOSURE", fp)) != NULL) {
273                  expval = atof(cp);
274 <                if (*cp == '-' | *cp == '+')
274 >                if ((*cp == '-') | (*cp == '+'))
275                          expval = pow(2., expval);
276                  expval *= 0.5;          /* compensate for local shading */
277          }
# Line 275 | Line 303 | char   **av;
303          do
304                  if (isview(buf)) {
305                          vwl[nvv].v = (VIEW *)bmalloc(sizeof(VIEW));
306 <                        copystruct(vwl[nvv].v, &stdview);
306 >                        *(vwl[nvv].v) = stdview;
307                          sscanview(vwl[nvv].v, buf);
308                          if ((cp = setview(vwl[nvv++].v)) != NULL) {
309                                  fprintf(stderr, "%s: bad view %d - %s\n",
# Line 297 | Line 325 | char   **av;
325                                          atof(sskip2(buf+4,1)),
326                                          atof(sskip2(buf+4,2)));
327                  else if (backvis && !strncmp(buf, "-bv", 3) &&
328 <                                (!buf[3] || strchr(" 0-FfNn", buf[3]) != NULL))
328 >                                (!buf[3] || strchr("0-FfNn \n",buf[3])!=NULL))
329                          backvis = 0;
330          fclose(fp);
331          unlink(optfile);                        /* delete options file */
332   }
333  
334  
335 < int
336 < findvw(nm)                      /* find named view */
337 < register char   *nm;
335 > static int
336 > findvw(                 /* find named view */
337 >        register char   *nm
338 > )
339   {
340          register int    n;
341  
342 <        if (*nm >= '1' & *nm <= '9' &&
342 >        if ((*nm >= '1') & (*nm <= '9') &&
343                          (n = atoi(nm)-1) <= MAXVIEW && vwl[n].v != NULL)
344                  return(n);
345          for (n = 0; vwl[n].v != NULL; n++)
# Line 320 | Line 349 | register char  *nm;
349   }
350  
351  
352 < int
353 < varmatch(s, vn)                         /* match line to variable */
354 < register char   *s, *vn;
352 > static int
353 > varmatch(                               /* match line to variable */
354 >        register char   *s,
355 >        register char   *vn
356 > )
357   {
358          register int    c;
359  
# Line 338 | Line 369 | register char  *s, *vn;
369   }
370  
371  
372 < char *
373 < scan4var(buf, buflen, vname, fp)        /* scan for variable from fp */
374 < char    *buf;
375 < int     buflen;
376 < char    *vname;
377 < FILE    *fp;
372 > static char *
373 > scan4var(       /* scan for variable from fp */
374 >        char    *buf,
375 >        int     buflen,
376 >        char    *vname,
377 >        FILE    *fp
378 > )
379   {
380          int     cval;
381          register char   *cp;
# Line 363 | Line 395 | FILE   *fp;
395   }
396  
397  
398 < dev_open(id)                    /* initialize GLX driver */
399 < char  *id;
398 > static void
399 > dev_open(                       /* initialize GLX driver */
400 >        char  *id
401 > )
402   {
403          static int      atlBest[] = {GLX_RGBA, GLX_RED_SIZE,4,
404                                  GLX_GREEN_SIZE,4, GLX_BLUE_SIZE,4,
# Line 423 | Line 457 | char  *id;
457          glDepthFunc(GL_LESS);
458          glShadeModel(GL_SMOOTH);
459          glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
460 <        glLightModelf(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
460 >        glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
461          glEnable(GL_LIGHTING);
462 +        glFrontFace(GL_CCW);
463 +        glCullFace(GL_BACK);
464          if (backvis)
465                  glDisable(GL_CULL_FACE);
466 <        else {
431 <                glFrontFace(GL_CCW);
432 <                glCullFace(GL_BACK);
466 >        else
467                  glEnable(GL_CULL_FACE);
434        }
468          glDrawBuffer(GL_BACK);
469                                          /* figure out sensible view */
470          pwidth = (double)DisplayWidthMM(ourdisplay, ourscreen) /
# Line 447 | Line 480 | char  *id;
480          no_render++;
481          do
482                  dev_input(0);           /* get resize event */
483 <        while (hres == 0 & vres == 0);
483 >        while ((hres == 0) & (vres == 0));
484          no_render--;
485          rgl_checkerr("initializing GLX");
486   }
487  
488  
489 < dev_close()                     /* close our display and free resources */
489 > static void
490 > dev_close(void)                 /* close our display and free resources */
491   {
492          glXMakeCurrent(ourdisplay, None, NULL);
493          glXDestroyContext(ourdisplay, gctx);
# Line 464 | Line 498 | dev_close()                    /* close our display and free resources
498   }
499  
500  
501 < int
502 < dev_view(nv)                    /* assign new driver view */
503 < register VIEW   *nv;
501 > static int
502 > dev_view(                       /* assign new driver view */
503 >        register VIEW   *nv
504 > )
505   {
506          int     newhres = hres, newvres = vres;
507          double  wa, va;
# Line 475 | Line 510 | register VIEW  *nv;
510                  error(COMMAND, "illegal view type");
511                  nv->type = VT_PER;
512          }
513 <        if (nv->horiz > 160. | nv->vert > 160.) {
513 >        if ((nv->horiz > 160.) | (nv->vert > 160.)) {
514                  error(COMMAND, "illegal view angle");
515                  if (nv->horiz > 160.)
516                          nv->horiz = 160.;
517                  if (nv->vert > 160.)
518                          nv->vert = 160.;
519          }
520 <        if (hres != 0 & vres != 0) {
520 >        if ((hres != 0) & (vres != 0)) {
521                  wa = (vres*pheight)/(hres*pwidth);
522                  va = viewaspect(nv);
523                  if (va > wa+.05) {
# Line 498 | Line 533 | register VIEW  *nv;
533                                  newvres = (pwidth/pheight)*va*newhres + .5;
534                          }
535                  }
536 <                if (newhres != hres | newvres != vres) {
536 >                if ((newhres != hres) | (newvres != vres)) {
537                          no_render++;
538                          XResizeWindow(ourdisplay, gwind, newhres, newvres);
539                          do
540                                  dev_input(0);           /* get resize event */
541 <                        while (newhres != hres | newvres != vres);
541 >                        while ((newhres != hres) | (newvres != vres));
542                          no_render--;
543                  }
544          }
545 <        copystruct(&thisview, nv);
545 >        thisview = *nv;
546          setglpersp(&thisview);
547          render();
548          return(1);
549   }
550  
551  
552 < int
553 < dev_input(nsecs)                /* get next input event */
554 < int     nsecs;
552 > static int
553 > dev_input(              /* get next input event */
554 >        int     nsecs
555 > )
556   {
557   #if 0
558          static time_t   lasttime = 0;
# Line 554 | Line 590 | int    nsecs;
590   }
591  
592  
593 < render()                        /* render our display list and swap buffers */
593 > static void
594 > render(void)                    /* render our display list and swap buffers */
595   {
596          double  d;
597  
# Line 580 | Line 617 | render()                       /* render our display list and swap buffers
617   }
618  
619  
620 < moveview(dx, dy, mov, orb)      /* move our view */
621 < int     dx, dy, mov, orb;
620 > static int
621 > moveview(       /* move our view */
622 >        int     dx,
623 >        int     dy,
624 >        int     mov,
625 >        int     orb
626 > )
627   {
628          VIEW    nv;
629          FVECT   odir, v1, wp;
630          double  d;
589        register int    li;
631                                  /* start with old view */
632 <        copystruct(&nv, &thisview);
632 >        nv = thisview;
633                                  /* change view direction */
634          if ((d = viewray(v1, odir, &thisview,
635                          (dx+.5)/hres, (dy+.5)/vres)) < -FTINY)
# Line 626 | Line 667 | int    dx, dy, mov, orb;
667   }
668  
669  
670 < getmove(ebut)                           /* get view change */
671 < XButtonPressedEvent     *ebut;
670 > static void
671 > waitabit(void)                          /* pause a moment */
672   {
673 +        struct timespec ts;
674 +        ts.tv_sec = 0;
675 +        ts.tv_nsec = 5000000;
676 +        nanosleep(&ts, NULL);
677 + }
678 +
679 +
680 + static void
681 + getmove(                                /* get view change */
682 +        XButtonPressedEvent     *ebut
683 + )
684 + {
685          int     movdir = MOVDIR(ebut->button);
686          int     movorb = MOVORB(ebut->state);
687          int     moved = 0;
# Line 642 | Line 695 | XButtonPressedEvent    *ebut;
695  
696          while (!XCheckMaskEvent(ourdisplay,
697                          ButtonReleaseMask, levptr(XEvent))) {
698 +                                        /* pause so as not to move too fast */
699 +                waitabit();
700  
701                  if (!XQueryPointer(ourdisplay, gwind, &rootw, &childw,
702                                  &rootx, &rooty, &wx, &wy, &statemask))
# Line 662 | Line 717 | XButtonPressedEvent    *ebut;
717   }
718  
719  
720 < getintersect(wp, org, dir, md)          /* intersect ray with scene geometry */
721 < FVECT   wp;             /* returned world intersection point */
722 < FVECT   org, dir;
723 < double  md;
720 > static int
721 > getintersect(           /* intersect ray with scene geometry */
722 >        FVECT   wp,             /* returned world intersection point */
723 >        FVECT   org,
724 >        FVECT   dir,
725 >        double  md
726 > )
727   {
728          float   fbuf[6];
729                                  /* check to see if rtrace is running */
730 <        if (rtpd[2] <= 0)
730 >        /* if (rtpd.pid <= 0) */
731 >        if (!rtpd.running)
732                  return(0);
733                                  /* assign origin */
734          fbuf[0] = org[0]; fbuf[1] = org[1]; fbuf[2] = org[2];
# Line 677 | Line 736 | double md;
736          if (md <= FTINY) md = FHUGE;
737          fbuf[3] = dir[0]*md; fbuf[4] = dir[1]*md; fbuf[5] = dir[2]*md;
738                                  /* trace that ray */
739 <        if (process(rtpd, fbuf, fbuf, 4*sizeof(float), 6*sizeof(float)) !=
740 <                        4*sizeof(float))
739 >        if (process(&rtpd, (char *)fbuf, (char *)fbuf,
740 >                        4*sizeof(float), 6*sizeof(float)) != 4*sizeof(float))
741                  error(INTERNAL, "error getting data back from rtrace process");
742          if (fbuf[3] >= .99*FHUGE)
743                  return(0);      /* missed local objects */
# Line 687 | Line 746 | double md;
746   }
747  
748  
749 < setglpersp(vp)                  /* set perspective view in GL */
750 < register VIEW   *vp;
749 > static void
750 > setglpersp(                     /* set perspective view in GL */
751 >        register VIEW   *vp
752 > )
753   {
754          double  d, xmin, xmax, ymin, ymax, zmin, zmax;
755  
# Line 719 | Line 780 | register VIEW  *vp;
780   }
781  
782  
783 < int
784 < getkey(ekey)                            /* get input key */
785 < register XKeyPressedEvent  *ekey;
783 > static int
784 > getkey(                         /* get input key */
785 >        register XKeyPressedEvent  *ekey
786 > )
787   {
788          int  n;
789          char    buf[8];
# Line 739 | Line 801 | register XKeyPressedEvent  *ekey;
801          case 'l':                       /* retrieve last (premouse) view */
802                  if (lastview.type) {
803                          VIEW    vtmp;
804 <                        copystruct(&vtmp, &thisview);
804 >                        vtmp = thisview;
805                          dev_view(&lastview);
806 <                        copystruct(&lastview, &vtmp);
806 >                        lastview = vtmp;
807                  } else
808                          XBell(ourdisplay, 0);
809                  break;
# Line 775 | Line 837 | register XKeyPressedEvent  *ekey;
837   }
838  
839  
840 < zoomview(pct, dx, dy)                   /* zoom in or out around (dx,dy) */
841 < int     pct;
842 < int     dx, dy;
840 > static void
841 > zoomview(                       /* zoom in or out around (dx,dy) */
842 >        int     pct,
843 >        int     dx,
844 >        int     dy
845 > )
846   {
847          double  h, v;
783        FVECT   direc;
848  
849 <        if (pct == 100 | pct <= 0)
849 >        if ((pct == 100) | (pct <= 0))
850                  return;
851          copylastv("zooming");
852          h = (dx+.5)/hres - 0.5;
# Line 801 | Line 865 | int    dx, dy;
865   }
866  
867  
868 < gotoview(vwnum)                         /* go to specified view number */
869 < int     vwnum;
868 > static void
869 > gotoview(                               /* go to specified view number */
870 >        int     vwnum
871 > )
872   {
873          if (vwnum < 0)
874                  for (vwnum = currentview; vwl[vwnum+1].v != NULL; vwnum++)
# Line 814 | Line 880 | int    vwnum;
880   }
881  
882  
883 < appendview(nm, vp)                      /* append standard view */
884 < char    *nm;
885 < VIEW    *vp;
883 > static void
884 > appendview(                     /* append standard view */
885 >        char    *nm,
886 >        VIEW    *vp
887 > )
888   {
889          FILE    *fp;
890                                          /* check if already in there */
891 <        if (!bcmp(&thisview, vwl[currentview].v, sizeof(VIEW))) {
891 >        if (!memcmp(&thisview, vwl[currentview].v, sizeof(VIEW))) {
892                  error(COMMAND, "view already in standard list");
893                  return;
894          }
# Line 841 | Line 909 | VIEW   *vp;
909          if (currentview >= MAXVIEW)
910                  error(INTERNAL, "too many views in appendview");
911          vwl[currentview].v = (VIEW *)bmalloc(sizeof(VIEW));
912 <        copystruct(vwl[currentview].v, &thisview);
912 >        *(vwl[currentview].v) = thisview;
913          if (nm != NULL)
914                  vwl[currentview].nam = savqstr(nm);
915   }
916  
917  
918 < copylastv(cause)                        /* copy last view position */
919 < char    *cause;
918 > static void
919 > copylastv(                      /* copy last view position */
920 >        char    *cause
921 > )
922   {
923          static char     *lastvc;
924  
925          if (cause == lastvc)
926                  return;                 /* only record one view per cause */
927          lastvc = cause;
928 <        copystruct(&lastview, &thisview);
928 >        lastview = thisview;
929   }
930  
931  
932 < fixwindow(eexp)                         /* repair damage to window */
933 < register XExposeEvent  *eexp;
932 > static void
933 > fixwindow(                              /* repair damage to window */
934 >        register XExposeEvent  *eexp
935 > )
936   {
937 <        if (hres == 0 | vres == 0) {    /* first exposure */
937 >        if ((hres == 0) | (vres == 0)) {        /* first exposure */
938                  resizewindow((XConfigureEvent *)eexp);
939                  return;
940          }
# Line 873 | Line 945 | register XExposeEvent  *eexp;
945   }
946  
947  
948 < resizewindow(ersz)                      /* resize window */
949 < register XConfigureEvent  *ersz;
948 > static void
949 > resizewindow(                   /* resize window */
950 >        register XConfigureEvent  *ersz
951 > )
952   {
953          static char     resizing[] = "resizing window";
954          double  wa, va;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines