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 |
82 |
|
|
83 |
|
struct driver odev; /* global device driver structure */ |
84 |
|
|
85 |
+ |
TMstruct *tmGlobal; /* global tone-mapping structure */ |
86 |
+ |
|
87 |
|
char odev_args[64]; /* command arguments */ |
88 |
|
|
89 |
|
static GLfloat *depthbuffer = NULL; /* depth buffer */ |
116 |
|
|
117 |
|
static int viewflags; /* what's happening with view */ |
118 |
|
|
119 |
+ |
/* |
120 |
|
static int resizewindow(), getevent(), getkey(), moveview(), wipeclean(), |
121 |
|
xferdepth(), freedepth(), setglortho(), |
122 |
|
setglpersp(), getframe(), getmove(), fixwindow(), mytmflags(); |
123 |
|
|
124 |
|
static double getdistance(); |
125 |
+ |
*/ |
126 |
+ |
static void checkglerr(char *where); |
127 |
+ |
static void xferdepth(void); |
128 |
+ |
static void freedepth(void); |
129 |
+ |
static double getdistance(int dx, int dy, FVECT direc); |
130 |
+ |
static int mytmflags(void); |
131 |
+ |
static void getevent(void); |
132 |
+ |
static void draw3dline(FVECT wp[2]); |
133 |
+ |
static void draw_grids(int fore); |
134 |
+ |
static int moveview(int dx, int dy, int mov, int orb); |
135 |
+ |
static void getframe(XButtonPressedEvent *ebut); |
136 |
+ |
static void getmove(XButtonPressedEvent *ebut); |
137 |
+ |
static void getkey(XKeyPressedEvent *ekey); |
138 |
+ |
static void fixwindow(XExposeEvent *eexp); |
139 |
+ |
static void resizewindow(XConfigureEvent *ersz); |
140 |
+ |
static void waitabit(void); |
141 |
+ |
static void setglpersp(void); |
142 |
+ |
static void setglortho(void); |
143 |
+ |
static void wipeclean(void); |
144 |
|
|
145 |
+ |
|
146 |
|
#ifdef STEREO |
147 |
< |
static int pushright(), popright(); |
147 |
> |
static void pushright(void); |
148 |
> |
static void popright(void); |
149 |
|
#endif |
150 |
|
|
151 |
|
extern int gmPortals; /* GL portal list id */ |
153 |
|
extern time_t time(); |
154 |
|
|
155 |
|
|
156 |
+ |
void |
157 |
|
dev_open(id) /* initialize GLX driver */ |
158 |
|
char *id; |
159 |
|
{ |
211 |
|
&myprims[BLU][CIEX],&myprims[BLU][CIEY], |
212 |
|
&myprims[WHT][CIEX],&myprims[WHT][CIEY]) >= 6) |
213 |
|
dpri = myprims; |
214 |
< |
if (tmInit(mytmflags(), dpri, gamval) == NULL) |
214 |
> |
tmGlobal = tmInit(mytmflags(), dpri, gamval); |
215 |
> |
if (tmGlobal == NULL) |
216 |
|
error(SYSTEM, "not enough memory in dev_open"); |
217 |
|
/* open window */ |
218 |
|
ourwinattr.background_pixel = ourblack; |
235 |
|
/* set window manager hints */ |
236 |
|
ourxwmhints.flags = InputHint|IconPixmapHint; |
237 |
|
ourxwmhints.input = True; |
238 |
< |
ourxwmhints.icon_pixmap = XCreateBitmapFromData(ourdisplay, |
239 |
< |
gwind, x11icon_bits, x11icon_width, x11icon_height); |
238 |
> |
ourxwmhints.icon_pixmap = XCreateBitmapFromData(ourdisplay, gwind, |
239 |
> |
(char *)x11icon_bits, x11icon_width, x11icon_height); |
240 |
|
XSetWMHints(ourdisplay, gwind, &ourxwmhints); |
241 |
|
oursizhints.min_width = MINWIDTH; |
242 |
|
#ifdef STEREO |
286 |
|
} |
287 |
|
|
288 |
|
|
289 |
< |
dev_close() /* close our display and free resources */ |
289 |
> |
void |
290 |
> |
dev_close(void) /* close our display and free resources */ |
291 |
|
{ |
292 |
|
#ifdef DOBJ |
293 |
|
dobj_cleanup(); |
302 |
|
gwind = 0; |
303 |
|
XCloseDisplay(ourdisplay); |
304 |
|
ourdisplay = NULL; |
305 |
< |
tmDone(NULL); |
305 |
> |
tmDone(tmGlobal); |
306 |
|
odev.v.type = 0; |
307 |
|
odev.hres = odev.vres = 0; |
308 |
|
odev.ifd = -1; |
309 |
|
} |
310 |
|
|
311 |
|
|
312 |
< |
dev_clear() /* clear our representation */ |
312 |
> |
void |
313 |
> |
dev_clear(void) /* clear our representation */ |
314 |
|
{ |
315 |
|
viewflags |= VWCHANGE; /* pretend our view has changed */ |
316 |
|
wipeclean(); /* clean off display and samples */ |
320 |
|
|
321 |
|
|
322 |
|
int |
323 |
< |
dev_view(nv) /* assign new driver view */ |
324 |
< |
register VIEW *nv; |
323 |
> |
dev_view( /* assign new driver view */ |
324 |
> |
VIEW *nv |
325 |
> |
) |
326 |
|
{ |
327 |
+ |
#ifdef STEREO |
328 |
|
double d; |
329 |
< |
|
329 |
> |
#endif |
330 |
|
if (nv->type != VT_PER || /* check view legality */ |
331 |
|
nv->horiz > 160. || nv->vert > 160.) { |
332 |
|
error(COMMAND, "illegal view type/angle"); |
376 |
|
} |
377 |
|
|
378 |
|
|
379 |
< |
dev_section(gfn, pfn) /* add octree for geometry rendering */ |
380 |
< |
char *gfn, *pfn; |
379 |
> |
void |
380 |
> |
dev_section( /* add octree for geometry rendering */ |
381 |
> |
char *gfn, |
382 |
> |
char *pfn |
383 |
> |
) |
384 |
|
{ |
350 |
– |
char *cp; |
351 |
– |
|
385 |
|
if (gfn == NULL) { |
386 |
|
gmEndGeom(); |
387 |
|
gmEndPortal(); |
401 |
|
} |
402 |
|
|
403 |
|
|
404 |
< |
dev_auxcom(cmd, args) /* process an auxiliary command */ |
405 |
< |
char *cmd, *args; |
404 |
> |
void |
405 |
> |
dev_auxcom( /* process an auxiliary command */ |
406 |
> |
char *cmd, |
407 |
> |
char *args |
408 |
> |
) |
409 |
|
{ |
410 |
|
#ifdef DOBJ |
411 |
|
int vischange; |
424 |
|
|
425 |
|
|
426 |
|
VIEW * |
427 |
< |
dev_auxview(n, hvres) /* return nth auxiliary view */ |
428 |
< |
int n; |
429 |
< |
int hvres[2]; |
427 |
> |
dev_auxview( /* return nth auxiliary view */ |
428 |
> |
int n, |
429 |
> |
int hvres[2] |
430 |
> |
) |
431 |
|
{ |
432 |
|
hvres[0] = odev.hres; hvres[1] = odev.vres; |
433 |
|
if (n == 0) |
441 |
|
|
442 |
|
|
443 |
|
int |
444 |
< |
dev_input() /* get X11 input */ |
444 |
> |
dev_input(void) /* get X11 input */ |
445 |
|
{ |
446 |
|
inpresflags = 0; |
447 |
|
|
456 |
|
} |
457 |
|
|
458 |
|
|
459 |
< |
dev_value(c, d, p) /* add a pixel value to our texture */ |
460 |
< |
COLR c; |
461 |
< |
FVECT d, p; |
459 |
> |
void |
460 |
> |
dev_value( /* add a pixel value to our texture */ |
461 |
> |
COLR c, |
462 |
> |
FVECT d, |
463 |
> |
FVECT p |
464 |
> |
) |
465 |
|
{ |
466 |
|
#ifdef DOBJ |
467 |
|
if (dobj_lightsamp != NULL) { /* in light source sampling */ |
476 |
|
|
477 |
|
|
478 |
|
int |
479 |
< |
dev_flush() /* flush output as appropriate */ |
479 |
> |
dev_flush(void) /* flush output as appropriate */ |
480 |
|
{ |
481 |
|
int ndrawn; |
482 |
|
|
522 |
|
} |
523 |
|
|
524 |
|
|
525 |
< |
checkglerr(where) /* check for GL or GLU error */ |
526 |
< |
char *where; |
525 |
> |
static void |
526 |
> |
checkglerr( /* check for GL or GLU error */ |
527 |
> |
char *where |
528 |
> |
) |
529 |
|
{ |
530 |
< |
register GLenum errcode; |
530 |
> |
GLenum errcode; |
531 |
|
|
532 |
|
while ((errcode = glGetError()) != GL_NO_ERROR) { |
533 |
|
sprintf(errmsg, "OpenGL error %s: %s", |
537 |
|
} |
538 |
|
|
539 |
|
|
540 |
< |
static |
541 |
< |
xferdepth() /* load and clear depth buffer */ |
540 |
> |
static void |
541 |
> |
xferdepth(void) /* load and clear depth buffer */ |
542 |
|
{ |
543 |
< |
register GLfloat *dbp; |
544 |
< |
register GLubyte *pbuf; |
543 |
> |
GLfloat *dbp; |
544 |
> |
GLubyte *pbuf; |
545 |
|
|
546 |
|
if (depthbuffer == NULL) { /* allocate private depth buffer */ |
547 |
|
#ifdef STEREO |
600 |
|
} |
601 |
|
|
602 |
|
|
603 |
< |
static |
604 |
< |
freedepth() /* free recorded depth buffer */ |
603 |
> |
static void |
604 |
> |
freedepth(void) /* free recorded depth buffer */ |
605 |
|
{ |
606 |
|
if (depthbuffer == NULL) |
607 |
|
return; |
617 |
|
|
618 |
|
|
619 |
|
static double |
620 |
< |
getdistance(dx, dy, direc) /* distance from fore plane along view ray */ |
621 |
< |
int dx, dy; |
622 |
< |
FVECT direc; |
620 |
> |
getdistance( /* distance from fore plane along view ray */ |
621 |
> |
int dx, |
622 |
> |
int dy, |
623 |
> |
FVECT direc |
624 |
> |
) |
625 |
|
{ |
626 |
|
GLfloat gldepth; |
627 |
|
double dist; |
628 |
|
|
629 |
< |
if (dx<0 | dx>=odev.hres | dy<0 | dy>=odev.vres) |
629 |
> |
if ((dx<0) | (dx>=odev.hres) | (dy<0) | (dy>=odev.vres)) |
630 |
|
return(FHUGE); |
631 |
|
if (depthbuffer != NULL) |
632 |
|
dist = depthbuffer[dy*odev.hres + dx]; |
644 |
|
|
645 |
|
|
646 |
|
#ifdef STEREO |
647 |
< |
static |
648 |
< |
pushright() /* push on right view & buffer */ |
647 |
> |
static void |
648 |
> |
pushright(void) /* push on right view & buffer */ |
649 |
|
{ |
650 |
|
double d; |
651 |
|
|
661 |
|
} |
662 |
|
|
663 |
|
|
664 |
< |
static |
665 |
< |
popright() /* pop off right view & buffer */ |
664 |
> |
static void |
665 |
> |
popright(void) /* pop off right view & buffer */ |
666 |
|
{ |
667 |
|
if (viewflags & VWPERSP) { |
668 |
|
glMatrixMode(GL_MODELVIEW); |
674 |
|
|
675 |
|
|
676 |
|
static int |
677 |
< |
mytmflags() /* figure out tone mapping flags */ |
677 |
> |
mytmflags(void) /* figure out tone mapping flags */ |
678 |
|
{ |
679 |
|
extern char *progname; |
680 |
< |
register char *cp, *tail; |
680 |
> |
char *cp, *tail; |
681 |
|
/* find basic name */ |
682 |
|
for (cp = tail = progname; *cp; cp++) |
683 |
|
if (*cp == '/') |
698 |
|
} |
699 |
|
|
700 |
|
|
701 |
< |
static |
702 |
< |
getevent() /* get next event */ |
701 |
> |
static void |
702 |
> |
getevent(void) /* get next event */ |
703 |
|
{ |
704 |
|
XNextEvent(ourdisplay, levptr(XEvent)); |
705 |
|
switch (levptr(XEvent)->type) { |
720 |
|
getkey(levptr(XKeyPressedEvent)); |
721 |
|
break; |
722 |
|
case ButtonPress: |
723 |
< |
if (FRAMESTATE(levptr(XButtonPressedEvent)->state)) |
724 |
< |
getframe(levptr(XButtonPressedEvent)); |
723 |
> |
if (FRAMESTATE(levptr(XButtonPressedEvent)->state)) |
724 |
> |
getframe(levptr(XButtonPressedEvent)); |
725 |
|
else |
726 |
< |
getmove(levptr(XButtonPressedEvent)); |
726 |
> |
switch (levptr(XButtonPressedEvent)->button) { |
727 |
> |
case Button4: /* wheel up */ |
728 |
> |
case Button5: /* wheel down */ |
729 |
> |
break; |
730 |
> |
default: |
731 |
> |
getmove(levptr(XButtonPressedEvent)); |
732 |
> |
break; |
733 |
> |
} |
734 |
|
break; |
735 |
|
} |
736 |
|
} |
737 |
|
|
738 |
|
|
739 |
< |
static |
740 |
< |
draw3dline(wp) /* draw 3d line in world coordinates */ |
741 |
< |
register FVECT wp[2]; |
739 |
> |
static void |
740 |
> |
draw3dline( /* draw 3d line in world coordinates */ |
741 |
> |
FVECT wp[2] |
742 |
> |
) |
743 |
|
{ |
744 |
|
glVertex3d(wp[0][0], wp[0][1], wp[0][2]); |
745 |
|
glVertex3d(wp[1][0], wp[1][1], wp[1][2]); |
746 |
|
} |
747 |
|
|
748 |
|
|
749 |
< |
static |
750 |
< |
draw_grids(fore) /* draw holodeck section grids */ |
751 |
< |
int fore; |
749 |
> |
static void |
750 |
> |
draw_grids( /* draw holodeck section grids */ |
751 |
> |
int fore |
752 |
> |
) |
753 |
|
{ |
754 |
|
glPushAttrib(GL_LIGHTING_BIT|GL_ENABLE_BIT); |
755 |
|
glDisable(GL_LIGHTING); |
765 |
|
} |
766 |
|
|
767 |
|
|
768 |
< |
static |
769 |
< |
moveview(dx, dy, mov, orb) /* move our view */ |
770 |
< |
int dx, dy, mov, orb; |
768 |
> |
static int |
769 |
> |
moveview( /* move our view */ |
770 |
> |
int dx, |
771 |
> |
int dy, |
772 |
> |
int mov, |
773 |
> |
int orb |
774 |
> |
) |
775 |
|
{ |
776 |
|
VIEW nv; |
777 |
|
FVECT odir, v1, wip; |
778 |
< |
double d, d1; |
779 |
< |
register int li; |
778 |
> |
double d; |
779 |
> |
#ifdef DOBJ |
780 |
> |
double d1; |
781 |
> |
#endif |
782 |
|
/* start with old view */ |
783 |
|
nv = odev.v; |
784 |
|
/* orient our motion */ |
803 |
|
VSUM(nv.vp, wip, odir, -1.); |
804 |
|
spinvector(nv.vdir, nv.vdir, nv.vup, d); |
805 |
|
} else if (orb) { /* orbit up/down */ |
806 |
< |
fcross(v1, odir, nv.vup); |
807 |
< |
if (normalize(v1) == 0.) |
806 |
> |
if (geodesic(odir, odir, nv.vup, |
807 |
> |
d=MOVDEG*PI/180.*orb, GEOD_RAD) == 0.0) |
808 |
|
return(0); |
750 |
– |
spinvector(odir, odir, v1, d=MOVDEG*PI/180.*orb); |
809 |
|
VSUM(nv.vp, wip, odir, -1.); |
810 |
< |
spinvector(nv.vdir, nv.vdir, v1, d); |
810 |
> |
geodesic(nv.vdir, nv.vdir, nv.vup, d, GEOD_RAD); |
811 |
|
} else if (mov) { /* move forward/backward */ |
812 |
|
d = MOVPCT/100. * mov; |
813 |
|
VSUM(nv.vp, nv.vp, odir, d); |
825 |
|
} |
826 |
|
|
827 |
|
|
828 |
< |
static |
829 |
< |
getframe(ebut) /* get focus frame */ |
830 |
< |
XButtonPressedEvent *ebut; |
828 |
> |
static void |
829 |
> |
getframe( /* get focus frame */ |
830 |
> |
XButtonPressedEvent *ebut |
831 |
> |
) |
832 |
|
{ |
833 |
|
int startx = ebut->x, starty = ebut->y; |
834 |
< |
int endx, endy; |
835 |
< |
|
834 |
> |
int endx, endy, midx, midy; |
835 |
> |
FVECT odir, v1; |
836 |
> |
double d; |
837 |
> |
#ifdef DOBJ |
838 |
> |
double d1; |
839 |
> |
#endif |
840 |
> |
/* get mouse drag */ |
841 |
|
XMaskEvent(ourdisplay, ButtonReleaseMask, levptr(XEvent)); |
842 |
|
endx = levptr(XButtonReleasedEvent)->x; |
843 |
|
endy = levptr(XButtonReleasedEvent)->y; |
844 |
< |
if (endx == startx | endy == starty) { |
845 |
< |
XBell(ourdisplay, 0); |
844 |
> |
midx = (startx + endx) >> 1; |
845 |
> |
midy = (starty + endy) >> 1; |
846 |
> |
/* set focus distance */ |
847 |
> |
if (viewray(v1, odir, &odev.v, |
848 |
> |
(midx+.5)/odev.hres, (midy+.5)/odev.vres) < -FTINY) |
849 |
|
return; |
850 |
< |
} |
851 |
< |
if (endx < startx) {register int c = endx; endx = startx; startx = c;} |
852 |
< |
if (endy < starty) {register int c = endy; endy = starty; starty = c;} |
850 |
> |
d = getdistance(midx, midy, odir); /* distance from front plane */ |
851 |
> |
#ifdef DOBJ |
852 |
> |
d1 = dobj_trace(NULL, v1, odir); |
853 |
> |
if (d1 < d) |
854 |
> |
d = d1; |
855 |
> |
#endif |
856 |
> |
if (d < .99*FHUGE) |
857 |
> |
odev.v.vdist = d + sqrt(dist2(v1, odev.v.vp)); |
858 |
> |
/* set frame for rendering */ |
859 |
> |
if ((endx == startx) | (endy == starty)) |
860 |
> |
return; |
861 |
> |
if (endx < startx) {int c = endx; endx = startx; startx = c;} |
862 |
> |
if (endy < starty) {int c = endy; endy = starty; starty = c;} |
863 |
|
sprintf(odev_args, "%.3f %.3f %.3f %.3f", |
864 |
|
(startx+.5)/odev.hres, 1.-(endy+.5)/odev.vres, |
865 |
|
(endx+.5)/odev.hres, 1.-(starty+.5)/odev.vres); |
867 |
|
} |
868 |
|
|
869 |
|
|
870 |
< |
static |
871 |
< |
waitabit() /* pause a moment */ |
870 |
> |
static void |
871 |
> |
waitabit(void) /* pause a moment */ |
872 |
|
{ |
873 |
|
struct timespec ts; |
874 |
|
ts.tv_sec = 0; |
877 |
|
} |
878 |
|
|
879 |
|
|
880 |
< |
static |
881 |
< |
getmove(ebut) /* get view change */ |
882 |
< |
XButtonPressedEvent *ebut; |
880 |
> |
static void |
881 |
> |
getmove( /* get view change */ |
882 |
> |
XButtonPressedEvent *ebut |
883 |
> |
) |
884 |
|
{ |
885 |
|
int movdir = MOVDIR(ebut->button); |
886 |
|
int movorb = MOVORB(ebut->state); |
935 |
|
} |
936 |
|
|
937 |
|
|
938 |
< |
static |
939 |
< |
setglpersp() /* set perspective view in GL */ |
938 |
> |
static void |
939 |
> |
setglpersp(void) /* set perspective view in GL */ |
940 |
|
{ |
941 |
|
double d, xmin, xmax, ymin, ymax; |
942 |
|
GLfloat vec[4]; |
997 |
|
} |
998 |
|
|
999 |
|
|
1000 |
< |
static |
1001 |
< |
setglortho() /* set up orthographic view for cone drawing */ |
1000 |
> |
static void |
1001 |
> |
setglortho(void) /* set up orthographic view for cone drawing */ |
1002 |
|
{ |
1003 |
|
glDrawBuffer(GL_FRONT); /* use single-buffer mode */ |
1004 |
|
/* set view matrix */ |
1014 |
|
} |
1015 |
|
|
1016 |
|
|
1017 |
< |
static |
1018 |
< |
wipeclean() /* prepare for redraw */ |
1017 |
> |
static void |
1018 |
> |
wipeclean(void) /* prepare for redraw */ |
1019 |
|
{ |
1020 |
|
glDrawBuffer(GL_BACK); /* use double-buffer mode */ |
1021 |
|
glReadBuffer(GL_BACK); |
1037 |
|
} |
1038 |
|
|
1039 |
|
|
1040 |
< |
static |
1041 |
< |
getkey(ekey) /* get input key */ |
1042 |
< |
register XKeyPressedEvent *ekey; |
1040 |
> |
static void |
1041 |
> |
getkey( /* get input key */ |
1042 |
> |
XKeyPressedEvent *ekey |
1043 |
> |
) |
1044 |
|
{ |
1045 |
|
Window rootw, childw; |
1046 |
|
int rootx, rooty, wx, wy; |
1121 |
|
} |
1122 |
|
|
1123 |
|
|
1124 |
< |
static |
1125 |
< |
fixwindow(eexp) /* repair damage to window */ |
1126 |
< |
register XExposeEvent *eexp; |
1124 |
> |
static void |
1125 |
> |
fixwindow( /* repair damage to window */ |
1126 |
> |
XExposeEvent *eexp |
1127 |
> |
) |
1128 |
|
{ |
1129 |
|
int xmin, ymin, xmax, ymax; |
1130 |
|
|
1131 |
< |
if (odev.hres == 0 | odev.vres == 0) { /* first exposure */ |
1131 |
> |
if ((odev.hres == 0) | (odev.vres == 0)) { /* first exposure */ |
1132 |
|
resizewindow((XConfigureEvent *)eexp); |
1133 |
|
return; |
1134 |
|
} |
1167 |
|
} |
1168 |
|
|
1169 |
|
|
1170 |
< |
static |
1171 |
< |
resizewindow(ersz) /* resize window */ |
1172 |
< |
register XConfigureEvent *ersz; |
1170 |
> |
static void |
1171 |
> |
resizewindow( /* resize window */ |
1172 |
> |
XConfigureEvent *ersz |
1173 |
> |
) |
1174 |
|
{ |
1175 |
|
glViewport(0, 0, ersz->width, ersz->height); |
1176 |
|
|