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.22 by schorsch, Mon Jul 21 22:30:18 2003 UTC vs.
Revision 3.25 by greg, Thu Feb 12 18:55:50 2004 UTC

# Line 17 | Line 17 | static const char      RCSid[] = "$Id$";
17   #endif
18   #endif
19  
20 #include "standard.h"
20  
21 + #include <time.h>
22   #include <GL/glx.h>
23   #include <GL/glu.h>
24   #ifdef STEREO
25   #include <X11/extensions/SGIStereo.h>
26   #endif
27 #include <time.h>
27  
28 + #include "standard.h"
29   #include "rhd_odraw.h"
30 + #include "rhdisp.h"
31 + #include "paths.h"
32   #ifdef DOBJ
33   #include "rhdobj.h"
34   #endif
# Line 112 | Line 114 | static int     inpresflags;            /* input result flags */
114  
115   static int      viewflags;              /* what's happening with view */
116  
117 + /*
118   static int  resizewindow(), getevent(), getkey(), moveview(), wipeclean(),
119                  xferdepth(), freedepth(), setglortho(),
120                  setglpersp(), getframe(), getmove(), fixwindow(), mytmflags();
121  
122   static double   getdistance();
123 + */
124 + static void checkglerr(char *where);
125 + static void xferdepth(void);
126 + static void freedepth(void);
127 + static double getdistance(int dx, int dy, FVECT direc);
128 + static int mytmflags(void);
129 + static void getevent(void);
130 + static void draw3dline(register FVECT wp[2]);
131 + static void draw_grids(int fore);
132 + static int moveview(int dx, int dy, int mov, int orb);
133 + static void getframe(XButtonPressedEvent *ebut);
134 + static void getmove(XButtonPressedEvent *ebut);
135 + static void getkey(register XKeyPressedEvent *ekey);
136 + static void fixwindow(register XExposeEvent *eexp);
137 + static void resizewindow(register XConfigureEvent *ersz);
138 + static void waitabit(void);
139 + static void setglpersp(void);
140 + static void setglortho(void);
141 + static void wipeclean(void);
142  
143 +
144   #ifdef STEREO
145 < static int  pushright(), popright();
145 > static void pushright(void);
146 > static void popright(void);
147   #endif
148  
149   extern int      gmPortals;      /* GL portal list id */
# Line 127 | Line 151 | extern int     gmPortals;      /* GL portal list id */
151   extern time_t   time();
152  
153  
154 + extern void
155   dev_open(id)                    /* initialize GLX driver */
156   char  *id;
157   {
# Line 258 | Line 283 | char  *id;
283   }
284  
285  
286 < dev_close()                     /* close our display and free resources */
286 > extern void
287 > dev_close(void)                 /* close our display and free resources */
288   {
289   #ifdef DOBJ
290          dobj_cleanup();
# Line 280 | Line 306 | dev_close()                    /* close our display and free resources
306   }
307  
308  
309 < dev_clear()                     /* clear our representation */
309 > extern void
310 > dev_clear(void)                 /* clear our representation */
311   {
312          viewflags |= VWCHANGE;          /* pretend our view has changed */
313          wipeclean();                    /* clean off display and samples */
# Line 289 | Line 316 | dev_clear()                    /* clear our representation */
316   }
317  
318  
319 < int
320 < dev_view(nv)                    /* assign new driver view */
321 < register VIEW   *nv;
319 > extern int
320 > dev_view(                       /* assign new driver view */
321 >        register VIEW   *nv
322 > )
323   {
296        double  d;
297
324          if (nv->type != VT_PER ||               /* check view legality */
325                          nv->horiz > 160. || nv->vert > 160.) {
326                  error(COMMAND, "illegal view type/angle");
# Line 344 | Line 370 | register VIEW  *nv;
370   }
371  
372  
373 < dev_section(gfn, pfn)           /* add octree for geometry rendering */
374 < char    *gfn, *pfn;
373 > extern void
374 > dev_section(            /* add octree for geometry rendering */
375 >        char    *gfn,
376 >        char    *pfn
377 > )
378   {
350        char    *cp;
351
379          if (gfn == NULL) {
380                  gmEndGeom();
381                  gmEndPortal();
# Line 368 | Line 395 | char   *gfn, *pfn;
395   }
396  
397  
398 < dev_auxcom(cmd, args)           /* process an auxiliary command */
399 < char    *cmd, *args;
398 > extern void
399 > dev_auxcom(             /* process an auxiliary command */
400 >        char    *cmd,
401 >        char    *args
402 > )
403   {
404   #ifdef DOBJ
405          int     vischange;
# Line 387 | Line 417 | char   *cmd, *args;
417   }
418  
419  
420 < VIEW *
421 < dev_auxview(n, hvres)           /* return nth auxiliary view */
422 < int     n;
423 < int     hvres[2];
420 > extern VIEW *
421 > dev_auxview(            /* return nth auxiliary view */
422 >        int     n,
423 >        int     hvres[2]
424 > )
425   {
426          hvres[0] = odev.hres; hvres[1] = odev.vres;
427          if (n == 0)
# Line 403 | Line 434 | int    hvres[2];
434   }
435  
436  
437 < int
438 < dev_input()                     /* get X11 input */
437 > extern int
438 > dev_input(void)                 /* get X11 input */
439   {
440          inpresflags = 0;
441  
# Line 419 | Line 450 | dev_input()                    /* get X11 input */
450   }
451  
452  
453 < dev_value(c, d, p)              /* add a pixel value to our texture */
454 < COLR    c;
455 < FVECT   d, p;
453 > extern void
454 > dev_value(              /* add a pixel value to our texture */
455 >        COLR    c,
456 >        FVECT   d,
457 >        FVECT   p
458 > )
459   {
460   #ifdef DOBJ
461          if (dobj_lightsamp != NULL) {   /* in light source sampling */
# Line 435 | Line 469 | FVECT  d, p;
469   }
470  
471  
472 < int
473 < dev_flush()                     /* flush output as appropriate */
472 > extern int
473 > dev_flush(void)                 /* flush output as appropriate */
474   {
475          int     ndrawn;
476  
# Line 482 | Line 516 | dev_flush()                    /* flush output as appropriate */
516   }
517  
518  
519 < checkglerr(where)               /* check for GL or GLU error */
520 < char    *where;
519 > static void
520 > checkglerr(             /* check for GL or GLU error */
521 >        char    *where
522 > )
523   {
524          register GLenum errcode;
525  
# Line 495 | Line 531 | char   *where;
531   }
532  
533  
534 < static
535 < xferdepth()                     /* load and clear depth buffer */
534 > static void
535 > xferdepth(void)                 /* load and clear depth buffer */
536   {
537          register GLfloat        *dbp;
538          register GLubyte        *pbuf;
# Line 558 | Line 594 | xferdepth()                    /* load and clear depth buffer */
594   }
595  
596  
597 < static
598 < freedepth()                             /* free recorded depth buffer */
597 > static void
598 > freedepth(void)                         /* free recorded depth buffer */
599   {
600          if (depthbuffer == NULL)
601                  return;
# Line 575 | Line 611 | freedepth()                            /* free recorded depth buffer */
611  
612  
613   static double
614 < getdistance(dx, dy, direc)      /* distance from fore plane along view ray */
615 < int     dx, dy;
616 < FVECT   direc;
614 > getdistance(    /* distance from fore plane along view ray */
615 >        int     dx,
616 >        int     dy,
617 >        FVECT   direc
618 > )
619   {
620          GLfloat gldepth;
621          double  dist;
622  
623 <        if (dx<0 | dx>=odev.hres | dy<0 | dy>=odev.vres)
623 >        if ((dx<0) | (dx>=odev.hres) | (dy<0) | (dy>=odev.vres))
624                  return(FHUGE);
625          if (depthbuffer != NULL)
626                  dist = depthbuffer[dy*odev.hres + dx];
627          else {
628                  glReadPixels(dx,dy, 1,1, GL_DEPTH_COMPONENT,
629                                  GL_FLOAT, &gldepth);
630 +                if (gldepth <= FTINY)
631 +                        return (FHUGE); /* call failed */
632                  dist = mapdepth(gldepth);
633          }
634          if (dist >= .99*FHUGE)
# Line 598 | Line 638 | FVECT  direc;
638  
639  
640   #ifdef STEREO
641 < static
642 < pushright()                     /* push on right view & buffer */
641 > static void
642 > pushright(void)                 /* push on right view & buffer */
643   {
644          double  d;
645  
# Line 615 | Line 655 | pushright()                    /* push on right view & buffer */
655   }
656  
657  
658 < static
659 < popright()                      /* pop off right view & buffer */
658 > static void
659 > popright(void)                  /* pop off right view & buffer */
660   {
661          if (viewflags & VWPERSP) {
662                  glMatrixMode(GL_MODELVIEW);
# Line 628 | Line 668 | popright()                     /* pop off right view & buffer */
668  
669  
670   static int
671 < mytmflags()                     /* figure out tone mapping flags */
671 > mytmflags(void)                 /* figure out tone mapping flags */
672   {
673          extern char     *progname;
674          register char   *cp, *tail;
# Line 652 | Line 692 | mytmflags()                    /* figure out tone mapping flags */
692   }
693  
694  
695 < static
696 < getevent()                      /* get next event */
695 > static void
696 > getevent(void)                  /* get next event */
697   {
698          XNextEvent(ourdisplay, levptr(XEvent));
699          switch (levptr(XEvent)->type) {
# Line 683 | Line 723 | getevent()                     /* get next event */
723   }
724  
725  
726 < static
727 < draw3dline(wp)                  /* draw 3d line in world coordinates */
728 < register FVECT  wp[2];
726 > static void
727 > draw3dline(                     /* draw 3d line in world coordinates */
728 >        register FVECT  wp[2]
729 > )
730   {
731          glVertex3d(wp[0][0], wp[0][1], wp[0][2]);
732          glVertex3d(wp[1][0], wp[1][1], wp[1][2]);
733   }
734  
735  
736 < static
737 < draw_grids(fore)                /* draw holodeck section grids */
738 < int     fore;
736 > static void
737 > draw_grids(             /* draw holodeck section grids */
738 >        int     fore
739 > )
740   {
741          glPushAttrib(GL_LIGHTING_BIT|GL_ENABLE_BIT);
742          glDisable(GL_LIGHTING);
# Line 710 | Line 752 | int    fore;
752   }
753  
754  
755 < static
756 < moveview(dx, dy, mov, orb)      /* move our view */
757 < int     dx, dy, mov, orb;
755 > static int
756 > moveview(       /* move our view */
757 >        int     dx,
758 >        int     dy,
759 >        int     mov,
760 >        int     orb
761 > )
762   {
763          VIEW    nv;
764          FVECT   odir, v1, wip;
765          double  d, d1;
720        register int    li;
766                                  /* start with old view */
767          nv = odev.v;
768                                  /* orient our motion */
# Line 765 | Line 810 | int    dx, dy, mov, orb;
810   }
811  
812  
813 < static
814 < getframe(ebut)                          /* get focus frame */
815 < XButtonPressedEvent     *ebut;
813 > static void
814 > getframe(                               /* get focus frame */
815 >        XButtonPressedEvent     *ebut
816 > )
817   {
818          int     startx = ebut->x, starty = ebut->y;
819          int     endx, endy;
# Line 775 | Line 821 | XButtonPressedEvent    *ebut;
821          XMaskEvent(ourdisplay, ButtonReleaseMask, levptr(XEvent));
822          endx = levptr(XButtonReleasedEvent)->x;
823          endy = levptr(XButtonReleasedEvent)->y;
824 <        if (endx == startx | endy == starty) {
824 >        if ((endx == startx) | (endy == starty)) {
825                  XBell(ourdisplay, 0);
826                  return;
827          }
# Line 788 | Line 834 | XButtonPressedEvent    *ebut;
834   }
835  
836  
837 < static
838 < waitabit()                              /* pause a moment */
837 > static void
838 > waitabit(void)                          /* pause a moment */
839   {
840          struct timespec ts;
841          ts.tv_sec = 0;
842 <        ts.tv_nsec = 50000000;
842 >        ts.tv_nsec = 100000000L;
843          nanosleep(&ts, NULL);
844   }
845  
846  
847 < static
848 < getmove(ebut)                           /* get view change */
849 < XButtonPressedEvent     *ebut;
847 > static void
848 > getmove(                                /* get view change */
849 >        XButtonPressedEvent     *ebut
850 > )
851   {
852          int     movdir = MOVDIR(ebut->button);
853          int     movorb = MOVORB(ebut->state);
# Line 855 | Line 902 | XButtonPressedEvent    *ebut;
902   }
903  
904  
905 < static
906 < setglpersp()                    /* set perspective view in GL */
905 > static void
906 > setglpersp(void)                        /* set perspective view in GL */
907   {
908          double  d, xmin, xmax, ymin, ymax;
909          GLfloat vec[4];
# Line 917 | Line 964 | setglpersp()                   /* set perspective view in GL */
964   }
965  
966  
967 < static
968 < setglortho()                    /* set up orthographic view for cone drawing */
967 > static void
968 > setglortho(void)                        /* set up orthographic view for cone drawing */
969   {
970          glDrawBuffer(GL_FRONT);         /* use single-buffer mode */
971                                          /* set view matrix */
# Line 934 | Line 981 | setglortho()                   /* set up orthographic view for cone dr
981   }
982  
983  
984 < static
985 < wipeclean()                     /* prepare for redraw */
984 > static void
985 > wipeclean(void)                 /* prepare for redraw */
986   {
987          glDrawBuffer(GL_BACK);          /* use double-buffer mode */
988          glReadBuffer(GL_BACK);
# Line 957 | Line 1004 | wipeclean()                    /* prepare for redraw */
1004   }
1005  
1006  
1007 < static
1008 < getkey(ekey)                            /* get input key */
1009 < register XKeyPressedEvent  *ekey;
1007 > static void
1008 > getkey(                         /* get input key */
1009 >        register XKeyPressedEvent  *ekey
1010 > )
1011   {
1012          Window  rootw, childw;
1013          int     rootx, rooty, wx, wy;
# Line 1040 | Line 1088 | register XKeyPressedEvent  *ekey;
1088   }
1089  
1090  
1091 < static
1092 < fixwindow(eexp)                         /* repair damage to window */
1093 < register XExposeEvent  *eexp;
1091 > static void
1092 > fixwindow(                              /* repair damage to window */
1093 >        register XExposeEvent  *eexp
1094 > )
1095   {
1096          int     xmin, ymin, xmax, ymax;
1097  
1098 <        if (odev.hres == 0 | odev.vres == 0) {  /* first exposure */
1098 >        if ((odev.hres == 0) | (odev.vres == 0)) {      /* first exposure */
1099                  resizewindow((XConfigureEvent *)eexp);
1100                  return;
1101          }
# Line 1085 | Line 1134 | register XExposeEvent  *eexp;
1134   }
1135  
1136  
1137 < static
1138 < resizewindow(ersz)                      /* resize window */
1139 < register XConfigureEvent  *ersz;
1137 > static void
1138 > resizewindow(                   /* resize window */
1139 >        register XConfigureEvent  *ersz
1140 > )
1141   {
1142          glViewport(0, 0, ersz->width, ersz->height);
1143  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines