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

Comparing ray/src/hd/rhd_ogl.c (file contents):
Revision 3.6 by gwlarson, Mon Dec 21 19:17:28 1998 UTC vs.
Revision 3.7 by gwlarson, Tue Dec 22 09:40:32 1998 UTC

# Line 55 | Line 55 | static char SCCSid[] = "$SunId$ SGI";
55   #define FEQ(a,b)        ((a)-(b) <= FTINY && (a)-(b) >= -FTINY)
56   #endif
57  
58 + #define VWHEADLOCK      01              /* head position is locked flag */
59 + #define VWPERSP         02              /* perspective view is set */
60 + #define VWORTHO         04              /* orthographic view is set */
61 + #define VWCHANGE        010             /* view has changed */
62 + #define VWSTEADY        020             /* view is now steady */
63 + #define VWMAPPED        040             /* window is mapped */
64 +
65   #define GAMMA           1.4             /* default gamma correction */
66  
67   #define FRAMESTATE(s)   (((s)&(ShiftMask|ControlMask))==(ShiftMask|ControlMask))
# Line 97 | Line 104 | static int     rayqleft = 0;           /* rays left to queue before
104  
105   static XEvent  currentevent;            /* current event */
106  
100 static int  mapped = 0;                 /* window is mapped? */
107   static unsigned long  ourblack=0, ourwhite=~0;
108  
109   static Display  *ourdisplay = NULL;     /* our display */
# Line 115 | Line 121 | static double  dev_zrat;               /* (1. - dev_zmin/dev_zmax) *
121  
122   static int      inpresflags;            /* input result flags */
123  
124 < static int      headlocked;             /* lock vertical motion */
124 > static int      viewflags;              /* what's happening with view */
125  
120 static int      isperspective;          /* perspective/ortho view */
121
122 static int      viewsteady;             /* is view steady? */
123
126   static int  resizewindow(), getevent(), getkey(), moveview(), wipeclean(),
127                  xferdepth(), freedepth(), setglortho(),
128                  setglpersp(), getframe(), getmove(), fixwindow(), mytmflags();
# Line 263 | Line 265 | char  *id;
265          checkglerr("setting rendering parameters");
266          copystruct(&odev.v, &stdview);
267          odev.v.type = VT_PER;
268 <        headlocked = 0;                 /* free up head movement */
267 <        viewsteady = 1;                 /* view starts static */
268 <        isperspective = -1;             /* but no view set, yet */
268 >        viewflags = VWSTEADY;           /* view starts static */
269                                          /* map the window */
270          XMapWindow(ourdisplay, gwind);
271          dev_input();                    /* sets size and view angles */
# Line 355 | Line 355 | register VIEW  *nv;
355                  VSUM(vwright.vp, nv->vp, nv->hvec, d);
356                  /* setview(&vwright);   -- Unnecessary */
357   #endif
358 +                viewflags |= VWCHANGE;
359          }
360          wipeclean();
361          return(1);
# Line 451 | Line 452 | dev_flush()                    /* flush output as appropriate */
452   {
453          int     ndrawn;
454  
455 <        if (mapped && isperspective > 0) {
455 >        if ((viewflags&(VWMAPPED|VWPERSP)) == (VWMAPPED|VWPERSP)) {
456   #ifdef STEREO
457                  pushright();                    /* draw right eye */
458                  ndrawn = gmDrawGeom();
# Line 472 | Line 473 | dev_flush()                    /* flush output as appropriate */
473                  glXSwapBuffers(ourdisplay, gwind);
474                  checkglerr("rendering base view");
475          }
476 <        if (mapped && viewsteady)
477 <                if (isperspective > 0) {        /* first time after steady */
478 <                        if (ndrawn)
479 <                                xferdepth();    /* transfer and clear depth */
480 <                        setglortho();           /* set orthographic view */
481 <                } else if (!isperspective) {
476 >        if ((viewflags&(VWMAPPED|VWSTEADY|VWPERSP|VWORTHO)) ==
477 >                        (VWMAPPED|VWSTEADY|VWPERSP)) {
478 >                                        /* first time after steady */
479 >                if (ndrawn)
480 >                        xferdepth();    /* transfer and clear depth */
481 >                setglortho();           /* set orthographic view */
482 >
483 >        }
484 >        if ((viewflags&(VWMAPPED|VWSTEADY|VWPERSP|VWORTHO)) ==
485 >                        (VWMAPPED|VWSTEADY|VWORTHO)) {
486 >                                        /* else update cones */
487   #ifdef STEREO
488 <                        pushright();
489 <                        odUpdate(1);            /* draw right eye */
490 <                        popright();
488 >                pushright();
489 >                odUpdate(1);            /* draw right eye */
490 >                popright();
491   #endif
492 <                        odUpdate(0);            /* draw left eye */
493 <                        glFlush();              /* flush OpenGL */
494 <                }
492 >                odUpdate(0);            /* draw left eye */
493 >                glFlush();              /* flush OpenGL */
494 >        }
495          rayqleft = RAYQLEN;
496                                          /* flush X11 and return # pending */
497          return(odev.inpready = XPending(ourdisplay));
# Line 613 | Line 619 | pushright()                    /* push on right view & buffer */
619          double  d;
620  
621          setstereobuf(STEREO_BUFFER_RIGHT);
622 <        if (isperspective > 0) {
622 >        if (viewflags & VWPERSP) {
623                  glMatrixMode(GL_MODELVIEW);
624                  glPushMatrix();
625                  d = -eyesepdist / sqrt(odev.v.hn2);
# Line 627 | Line 633 | pushright()                    /* push on right view & buffer */
633   static
634   popright()                      /* pop off right view & buffer */
635   {
636 <        if (isperspective > 0) {
636 >        if (viewflags & VWPERSP) {
637                  glMatrixMode(GL_MODELVIEW);
638                  glPopMatrix();
639          }
# Line 670 | Line 676 | getevent()                     /* get next event */
676                  resizewindow(levptr(XConfigureEvent));
677                  break;
678          case UnmapNotify:
679 <                mapped = 0;
679 >                viewflags &= ~VWMAPPED;
680                  break;
681          case MapNotify:
682                  odRemap(0);
683 <                mapped = 1;
683 >                viewflags |= VWMAPPED;
684                  break;
685          case Expose:
686                  fixwindow(levptr(XExposeEvent));
# Line 761 | Line 767 | int    dx, dy, mov, orb;
767                  d = MOVPCT/100. * mov;
768                  VSUM(nv.vp, nv.vp, odir, d);
769          }
770 <        if (!mov ^ !orb && headlocked) {        /* restore head height */
770 >        if (!mov ^ !orb && viewflags&VWHEADLOCK) {      /* restore height */
771                  VSUM(v1, odev.v.vp, nv.vp, -1.);
772                  d = DOT(v1, nv.vup);
773                  VSUM(nv.vp, nv.vp, odev.v.vup, d);
# Line 810 | Line 816 | XButtonPressedEvent    *ebut;
816  
817          XNoOp(ourdisplay);              /* makes sure we're not idle */
818  
819 <        viewsteady = 0;                 /* flag moving view */
819 >        viewflags &= ~VWSTEADY;         /* flag moving view */
820          setglpersp(&odev.v);            /* start us off in perspective */
821          while (!XCheckMaskEvent(ourdisplay,
822                          ButtonReleaseMask, levptr(XEvent))) {
# Line 852 | Line 858 | XButtonPressedEvent    *ebut;
858                  wy = levptr(XButtonReleasedEvent)->y;
859                  moveview(wx, odev.vres-1-wy, movdir, movorb);
860          }
861 <        viewsteady = 1;                 /* done goofing around */
861 >        viewflags |= VWSTEADY;          /* done goofing around */
862   }
863  
864  
# Line 899 | Line 905 | register VIEW  *vp;
905                  odev.v.vp[2] + odev.v.vdir[2],
906                  odev.v.vup[0], odev.v.vup[1], odev.v.vup[2]);
907          checkglerr("setting perspective view");
902        isperspective = 1;
908          vec[0] = vec[1] = vec[2] = 0.; vec[3] = 1.;
909          glLightModelfv(GL_LIGHT_MODEL_AMBIENT, vec);
910          vec[0] = -odev.v.vdir[0];
# Line 915 | Line 920 | register VIEW  *vp;
920          glEnable(GL_LIGHT0);
921          glEnable(GL_LIGHTING);          /* light our GL objects */
922          glShadeModel(GL_SMOOTH);
923 +        viewflags &= ~VWORTHO;
924 +        viewflags |= VWPERSP;
925   }
926  
927  
# Line 928 | Line 935 | setglortho()                   /* set up orthographic view for cone dr
935          glOrtho(0., (double)odev.hres, 0., (double)odev.vres,
936                          0.001*OMAXDEPTH, 1.001*(-OMAXDEPTH));
937          checkglerr("setting orthographic view");
931        isperspective = 0;
938          glDisable(GL_LIGHTING);         /* cones are constant color */
939          glShadeModel(GL_FLAT);
940 +        viewflags &= ~VWPERSP;
941 +        viewflags |= VWORTHO;
942   }
943  
944  
# Line 946 | Line 954 | wipeclean()                    /* prepare for redraw */
954   #endif
955          glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT);
956          freedepth();
957 <        if (viewsteady)                 /* clear samples if steady */
957 >        if ((viewflags&(VWCHANGE|VWSTEADY)) ==
958 >                        (VWCHANGE|VWSTEADY)) {  /* clear samples if new */
959                  odClean();
960 +                viewflags &= ~VWCHANGE;         /* change noted */
961 +        }
962          setglpersp(&odev.v);            /* reset view & clipping planes */
963   }
964  
# Line 967 | Line 978 | register XKeyPressedEvent  *ekey;
978                  return;
979          switch (buf[0]) {
980          case 'h':                       /* turn on height motion lock */
981 <                headlocked = 1;
981 >                viewflags |= VWHEADLOCK;
982                  return;
983          case 'H':                       /* turn off height motion lock */
984 <                headlocked = 0;
984 >                viewflags &= ~VWHEADLOCK;
985                  return;
986          case 'l':                       /* retrieve last view */
987                  inpresflags |= DFL(DC_LASTVIEW);
# Line 1091 | Line 1102 | register XConfigureEvent  *ersz;
1102          odev.v.vert = 2.*180./PI * atan(0.5/VIEWDIST*pheight*odev.vres);
1103  
1104          inpresflags |= DFL(DC_SETVIEW);
1105 +        viewflags |= VWCHANGE;
1106   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines