| 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 |
|
|
| 68 |
|
|
| 69 |
|
int currentview = 0; /* current view number */ |
| 70 |
|
VIEW thisview = STDVIEW; /* displayed view */ |
| 71 |
+ |
double eyedist = 1; /* interocular distance */ |
| 72 |
|
VIEW lastview; /* last recorded view */ |
| 73 |
|
|
| 74 |
|
char *progname; /* global argv[0] */ |
| 79 |
|
|
| 80 |
|
int rtpd[3]; /* rtrace process descriptors */ |
| 81 |
|
|
| 82 |
+ |
int silent = 0; /* run rad silently? */ |
| 83 |
|
int backvis = 1; /* back faces visible? */ |
| 84 |
+ |
int stereo = 0; /* do stereo? */ |
| 85 |
|
|
| 86 |
+ |
#ifdef NOSTEREO |
| 87 |
+ |
#define setstereobuf(bid) 0 |
| 88 |
+ |
#else |
| 89 |
+ |
#define setstereobuf(bid) (glXWaitGL(), \ |
| 90 |
+ |
XSGISetStereoBuffer(ourdisplay, gwind, bid), \ |
| 91 |
+ |
glXWaitX()) |
| 92 |
+ |
#endif |
| 93 |
+ |
|
| 94 |
|
int displist; /* our scene display list */ |
| 95 |
|
|
| 96 |
|
int in_dev_view = 0; /* currently in dev_view() */ |
| 97 |
|
|
| 98 |
< |
extern char *fgets(), *fgetline(), *atos(), *scan4var(); |
| 98 |
> |
#ifdef BSD |
| 99 |
> |
#define strchr index |
| 100 |
> |
#endif |
| 101 |
> |
|
| 102 |
> |
extern char *strchr(), *fgets(), *fgetline(), *atos(), *scan4var(); |
| 103 |
|
extern int nowarn; /* turn warnings off? */ |
| 104 |
|
extern time_t time(); |
| 105 |
|
|
| 121 |
|
case 'w': |
| 122 |
|
nowarn = !nowarn; |
| 123 |
|
break; |
| 124 |
+ |
case 's': |
| 125 |
+ |
silent = !silent; |
| 126 |
+ |
break; |
| 127 |
+ |
case 'S': |
| 128 |
+ |
stereo = !stereo; |
| 129 |
+ |
break; |
| 130 |
|
case 'c': |
| 131 |
|
vwintvl = atoi(argv[++i]); |
| 132 |
|
break; |
| 138 |
|
} |
| 139 |
|
if (i >= argc) |
| 140 |
|
goto userr; |
| 141 |
+ |
#ifdef NOSTEREO |
| 142 |
+ |
if (stereo) |
| 143 |
+ |
error(INTERNAL, "stereo not supported in this version"); |
| 144 |
+ |
#endif |
| 145 |
|
/* run rad and get views */ |
| 146 |
|
runrad(argc-i, argv+i); |
| 147 |
|
/* check view */ |
| 148 |
< |
if (viewsel != NULL && (currentview = findvw(viewsel)) < 0) { |
| 149 |
< |
fprintf(stderr, "%s: no such view\n", viewsel); |
| 150 |
< |
quit(1); |
| 151 |
< |
} |
| 148 |
> |
if (viewsel != NULL) |
| 149 |
> |
if (viewsel[0] == '-') { |
| 150 |
> |
char *ve = viewsel; |
| 151 |
> |
if (!sscanview(&thisview, viewsel) || |
| 152 |
> |
(ve = setview(&thisview)) != NULL) { |
| 153 |
> |
fprintf(stderr, "%s: bad view: %s\n", |
| 154 |
> |
progname, ve); |
| 155 |
> |
quit(1); |
| 156 |
> |
} |
| 157 |
> |
currentview = -1; |
| 158 |
> |
} else if ((currentview = findvw(viewsel)) < 0) { |
| 159 |
> |
fprintf(stderr, "%s: no such view: %s\n", |
| 160 |
> |
progname, viewsel); |
| 161 |
> |
quit(1); |
| 162 |
> |
} |
| 163 |
|
/* open GL */ |
| 164 |
|
dev_open(radfile = argv[i]); |
| 165 |
|
/* load octree or scene files */ |
| 169 |
|
} else |
| 170 |
|
displist = rgl_filelist(nscenef, scene); |
| 171 |
|
/* set initial view */ |
| 172 |
< |
dev_view(vwl[currentview].v); |
| 172 |
> |
dev_view(currentview < 0 ? &thisview : vwl[currentview].v); |
| 173 |
|
/* input/render loop */ |
| 174 |
|
while (dev_input(vwintvl)) |
| 175 |
|
; |
| 176 |
|
/* all done */ |
| 177 |
|
quit(0); |
| 178 |
|
userr: |
| 179 |
< |
fprintf(stderr, "Usage: %s [-w][-c #secs][-v view] rfile [VAR=value]..\n", |
| 179 |
> |
fprintf(stderr, "Usage: %s [-w][-b][-v view] rfile [VAR=value]..\n", |
| 180 |
|
argv[0]); |
| 181 |
|
quit(1); |
| 182 |
|
} |
| 224 |
|
/* set rad commmand */ |
| 225 |
|
strcpy(radcomm, "rad -w -v 0 "); /* look out below! */ |
| 226 |
|
cp = radcomm + 19; |
| 227 |
+ |
if (silent) { |
| 228 |
+ |
strcpy(cp, "-s "); |
| 229 |
+ |
cp += 3; |
| 230 |
+ |
} |
| 231 |
|
while (ac--) { |
| 232 |
|
strcpy(cp, *av++); |
| 233 |
|
while (*cp) cp++; |
| 248 |
|
expval = atof(cp); |
| 249 |
|
if (*cp == '-' | *cp == '+') |
| 250 |
|
expval = pow(2., expval); |
| 251 |
+ |
expval *= 0.5; /* compensate for local shading */ |
| 252 |
|
} |
| 253 |
+ |
/* look for eye separation */ |
| 254 |
+ |
if ((cp = scan4var(buf, sizeof(buf), "EYESEP", fp)) != NULL) |
| 255 |
+ |
eyedist = atof(cp); |
| 256 |
|
/* look for materials */ |
| 257 |
|
while ((cp = scan4var(buf, sizeof(buf), "materials", fp)) != NULL) { |
| 258 |
|
nscenef += wordstring(scene+nscenef, cp); |
| 293 |
|
/* open options file */ |
| 294 |
|
if ((fp = fopen(optfile, "r")) == NULL) |
| 295 |
|
error(SYSTEM, "cannot open options file"); |
| 296 |
< |
/* get ambient value */ |
| 296 |
> |
/* get relevant options */ |
| 297 |
|
while (fgets(buf, sizeof(buf), fp) != NULL) |
| 298 |
< |
if (!strncmp(buf, "-av ", 4)) { |
| 298 |
> |
if (!strncmp(buf, "-av ", 4)) |
| 299 |
|
setcolor(ambval, atof(buf+4), |
| 300 |
|
atof(sskip2(buf+4,1)), |
| 301 |
|
atof(sskip2(buf+4,2))); |
| 302 |
< |
break; |
| 303 |
< |
} |
| 302 |
> |
else if (backvis && !strncmp(buf, "-bv", 3) && |
| 303 |
> |
(!buf[3] || strchr(" 0-FfNn", buf[3]) != NULL)) |
| 304 |
> |
backvis = 0; |
| 305 |
|
fclose(fp); |
| 306 |
|
unlink(optfile); /* delete options file */ |
| 307 |
|
} |
| 400 |
|
if (gwind == 0) |
| 401 |
|
error(SYSTEM, "cannot create window\n"); |
| 402 |
|
XStoreName(ourdisplay, gwind, id); |
| 403 |
+ |
#ifndef NOSTEREO |
| 404 |
+ |
if (stereo) /* check if stereo working */ |
| 405 |
+ |
switch (XSGIQueryStereoMode(ourdisplay, gwind)) { |
| 406 |
+ |
case STEREO_TOP: |
| 407 |
+ |
case STEREO_BOTTOM: |
| 408 |
+ |
break; |
| 409 |
+ |
case STEREO_OFF: |
| 410 |
+ |
error(USER, |
| 411 |
+ |
"wrong video mode: run \"/usr/gfx/setmon -n STR_TOP\" first"); |
| 412 |
+ |
case X_STEREO_UNSUPPORTED: |
| 413 |
+ |
error(USER, "stereo not supported on this screen"); |
| 414 |
+ |
default: |
| 415 |
+ |
error(INTERNAL, "unknown stereo mode"); |
| 416 |
+ |
} |
| 417 |
+ |
#endif |
| 418 |
|
/* set window manager hints */ |
| 419 |
|
ourxwmhints.flags = InputHint|IconPixmapHint; |
| 420 |
|
ourxwmhints.input = True; |
| 422 |
|
gwind, glradicon_bits, glradicon_width, glradicon_height); |
| 423 |
|
XSetWMHints(ourdisplay, gwind, &ourxwmhints); |
| 424 |
|
oursizhints.min_width = MINWIDTH; |
| 425 |
< |
oursizhints.min_height = MINHEIGHT; |
| 425 |
> |
oursizhints.min_height = stereo ? MINHEIGHT/2 : MINHEIGHT; |
| 426 |
|
oursizhints.flags = PMinSize; |
| 427 |
|
XSetNormalHints(ourdisplay, gwind, &oursizhints); |
| 428 |
|
/* set GLX context */ |
| 446 |
|
DisplayWidth(ourdisplay, ourscreen); |
| 447 |
|
pheight = (double)DisplayHeightMM(ourdisplay, ourscreen) / |
| 448 |
|
DisplayHeight(ourdisplay, ourscreen); |
| 449 |
+ |
if (stereo) { /* set stereo mode */ |
| 450 |
+ |
setstereobuf(STEREO_BUFFER_LEFT); |
| 451 |
+ |
pheight *= 2.; |
| 452 |
+ |
} |
| 453 |
|
/* map the window */ |
| 454 |
|
XMapWindow(ourdisplay, gwind); |
| 455 |
+ |
do |
| 456 |
+ |
dev_input(0); /* get resize event */ |
| 457 |
+ |
while (hres == 0 & vres == 0); |
| 458 |
|
rgl_checkerr("initializing GLX"); |
| 459 |
|
} |
| 460 |
|
|
| 562 |
|
|
| 563 |
|
render() /* render our display list and swap buffers */ |
| 564 |
|
{ |
| 565 |
+ |
double d; |
| 566 |
+ |
|
| 567 |
|
if (!mapped) |
| 568 |
|
return; |
| 569 |
|
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); |
| 570 |
|
glCallList(displist); |
| 571 |
+ |
if (stereo) { /* do right eye for stereo */ |
| 572 |
+ |
setstereobuf(STEREO_BUFFER_RIGHT); |
| 573 |
+ |
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); |
| 574 |
+ |
glMatrixMode(GL_MODELVIEW); |
| 575 |
+ |
glPushMatrix(); |
| 576 |
+ |
d = -eyedist / sqrt(thisview.hn2); |
| 577 |
+ |
glTranslated(d*thisview.hvec[0], d*thisview.hvec[1], |
| 578 |
+ |
d*thisview.hvec[2]); |
| 579 |
+ |
glCallList(displist); |
| 580 |
+ |
glMatrixMode(GL_MODELVIEW); |
| 581 |
+ |
glPopMatrix(); |
| 582 |
+ |
setstereobuf(STEREO_BUFFER_LEFT); |
| 583 |
+ |
} |
| 584 |
|
glXSwapBuffers(ourdisplay, gwind); /* calls glFlush() */ |
| 585 |
|
rgl_checkerr("rendering display list"); |
| 586 |
|
} |
| 642 |
|
int rootx, rooty, wx, wy; |
| 643 |
|
unsigned int statemask; |
| 644 |
|
|
| 645 |
< |
copylastv("moving"); |
| 645 |
> |
copylastv( movorb ? (movdir ? "left/right" : "up/down") : |
| 646 |
> |
(movdir ? "fore/back" : "rotate") ); |
| 647 |
|
XNoOp(ourdisplay); |
| 648 |
|
|
| 649 |
|
while (!XCheckMaskEvent(ourdisplay, |
| 817 |
|
vwnum = 0; |
| 818 |
|
if (vwnum == currentview) |
| 819 |
|
return; |
| 820 |
< |
/* copylastv("change view"); */ |
| 820 |
> |
copylastv("standard view"); |
| 821 |
|
dev_view(vwl[currentview=vwnum].v); |
| 822 |
|
} |
| 823 |
|
|