--- ray/src/util/glrad.c 1998/06/09 11:43:18 3.1 +++ ray/src/util/glrad.c 1998/06/10 17:52:18 3.4 @@ -13,6 +13,9 @@ static char SCCSid[] = "$SunId$ SGI"; #include "paths.h" #include #include +#ifndef NOSTEREO +#include +#endif #include #include "glradicon.h" @@ -65,8 +68,8 @@ struct { int currentview = 0; /* current view number */ VIEW thisview = STDVIEW; /* displayed view */ +double eyedist = 1; /* interocular distance */ VIEW lastview; /* last recorded view */ -char *lastvc = NULL; /* cause of last view change */ char *progname; /* global argv[0] */ char *radfile; /* rad input file */ @@ -76,11 +79,27 @@ char *octree; /* octree name (NULL if unnec.) */ int rtpd[3]; /* rtrace process descriptors */ +int silent = 0; /* run rad silently? */ int backvis = 1; /* back faces visible? */ +int stereo = 0; /* do stereo? */ +#ifdef NOSTEREO +#define setstereobuf(bid) 0 +#else +#define setstereobuf(bid) (glXWaitGL(), \ + XSGISetStereoBuffer(ourdisplay, gwind, bid), \ + glXWaitX()) +#endif + int displist; /* our scene display list */ -extern char *fgets(), *fgetline(), *atos(), *scan4var(); +int in_dev_view = 0; /* currently in dev_view() */ + +#ifdef BSD +#define strchr index +#endif + +extern char *strchr(), *fgets(), *fgetline(), *atos(), *scan4var(); extern int nowarn; /* turn warnings off? */ extern time_t time(); @@ -102,6 +121,12 @@ char *argv[]; case 'w': nowarn = !nowarn; break; + case 's': + silent = !silent; + break; + case 'S': + stereo = !stereo; + break; case 'c': vwintvl = atoi(argv[++i]); break; @@ -113,13 +138,28 @@ char *argv[]; } if (i >= argc) goto userr; +#ifdef NOSTEREO + if (stereo) + error(INTERNAL, "stereo not supported in this version"); +#endif /* run rad and get views */ runrad(argc-i, argv+i); /* check view */ - if (viewsel != NULL && (currentview = findvw(viewsel)) < 0) { - fprintf(stderr, "%s: no such view\n", viewsel); - quit(1); - } + if (viewsel != NULL) + if (viewsel[0] == '-') { + char *ve = viewsel; + if (!sscanview(&thisview, viewsel) || + (ve = setview(&thisview)) != NULL) { + fprintf(stderr, "%s: bad view: %s\n", + progname, ve); + quit(1); + } + currentview = -1; + } else if ((currentview = findvw(viewsel)) < 0) { + fprintf(stderr, "%s: no such view: %s\n", + progname, viewsel); + quit(1); + } /* open GL */ dev_open(radfile = argv[i]); /* load octree or scene files */ @@ -129,14 +169,14 @@ char *argv[]; } else displist = rgl_filelist(nscenef, scene); /* set initial view */ - dev_view(vwl[currentview].v); + dev_view(currentview < 0 ? &thisview : vwl[currentview].v); /* input/render loop */ while (dev_input(vwintvl)) ; /* all done */ quit(0); userr: - fprintf(stderr, "Usage: %s [-w][-c #secs][-v view] rfile [VAR=value]..\n", + fprintf(stderr, "Usage: %s [-w][-b][-v view] rfile [VAR=value]..\n", argv[0]); quit(1); } @@ -184,6 +224,10 @@ char **av; /* set rad commmand */ strcpy(radcomm, "rad -w -v 0 "); /* look out below! */ cp = radcomm + 19; + if (silent) { + strcpy(cp, "-s "); + cp += 3; + } while (ac--) { strcpy(cp, *av++); while (*cp) cp++; @@ -204,7 +248,11 @@ char **av; expval = atof(cp); if (*cp == '-' | *cp == '+') expval = pow(2., expval); + expval *= 0.5; /* compensate for local shading */ } + /* look for eye separation */ + if ((cp = scan4var(buf, sizeof(buf), "EYESEP", fp)) != NULL) + eyedist = atof(cp); /* look for materials */ while ((cp = scan4var(buf, sizeof(buf), "materials", fp)) != NULL) { nscenef += wordstring(scene+nscenef, cp); @@ -245,14 +293,15 @@ char **av; /* open options file */ if ((fp = fopen(optfile, "r")) == NULL) error(SYSTEM, "cannot open options file"); - /* get ambient value */ + /* get relevant options */ while (fgets(buf, sizeof(buf), fp) != NULL) - if (!strncmp(buf, "-av ", 4)) { + if (!strncmp(buf, "-av ", 4)) setcolor(ambval, atof(buf+4), atof(sskip2(buf+4,1)), atof(sskip2(buf+4,2))); - break; - } + else if (backvis && !strncmp(buf, "-bv", 3) && + (!buf[3] || strchr(" 0-FfNn", buf[3]) != NULL)) + backvis = 0; fclose(fp); unlink(optfile); /* delete options file */ } @@ -351,6 +400,21 @@ char *id; if (gwind == 0) error(SYSTEM, "cannot create window\n"); XStoreName(ourdisplay, gwind, id); +#ifndef NOSTEREO + if (stereo) /* check if stereo working */ + switch (XSGIQueryStereoMode(ourdisplay, gwind)) { + case STEREO_TOP: + case STEREO_BOTTOM: + break; + case STEREO_OFF: + error(USER, + "wrong video mode: run \"/usr/gfx/setmon -n STR_TOP\" first"); + case X_STEREO_UNSUPPORTED: + error(USER, "stereo not supported on this screen"); + default: + error(INTERNAL, "unknown stereo mode"); + } +#endif /* set window manager hints */ ourxwmhints.flags = InputHint|IconPixmapHint; ourxwmhints.input = True; @@ -358,7 +422,7 @@ char *id; gwind, glradicon_bits, glradicon_width, glradicon_height); XSetWMHints(ourdisplay, gwind, &ourxwmhints); oursizhints.min_width = MINWIDTH; - oursizhints.min_height = MINHEIGHT; + oursizhints.min_height = stereo ? MINHEIGHT/2 : MINHEIGHT; oursizhints.flags = PMinSize; XSetNormalHints(ourdisplay, gwind, &oursizhints); /* set GLX context */ @@ -382,8 +446,15 @@ char *id; DisplayWidth(ourdisplay, ourscreen); pheight = (double)DisplayHeightMM(ourdisplay, ourscreen) / DisplayHeight(ourdisplay, ourscreen); + if (stereo) { /* set stereo mode */ + setstereobuf(STEREO_BUFFER_LEFT); + pheight *= 2.; + } /* map the window */ XMapWindow(ourdisplay, gwind); + do + dev_input(0); /* get resize event */ + while (hres == 0 & vres == 0); rgl_checkerr("initializing GLX"); } @@ -419,7 +490,7 @@ register VIEW *nv; } if (hres != 0 & vres != 0) { wa = (vres*pheight)/(hres*pwidth); - va = viewaspect(&thisview); + va = viewaspect(nv); if (va > wa+.05) { newvres = (pwidth/pheight)*va*newhres + .5; if (newvres > maxvres) { @@ -434,10 +505,12 @@ register VIEW *nv; } } if (newhres != hres | newvres != vres) { + in_dev_view++; XResizeWindow(ourdisplay, gwind, newhres, newvres); do dev_input(0); /* get resize event */ while (newhres != hres | newvres != vres); + in_dev_view--; } } copystruct(&thisview, nv); @@ -489,10 +562,25 @@ int nsecs; render() /* render our display list and swap buffers */ { + double d; + if (!mapped) return; glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glCallList(displist); + if (stereo) { /* do right eye for stereo */ + setstereobuf(STEREO_BUFFER_RIGHT); + glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + d = -eyedist / sqrt(thisview.hn2); + glTranslated(d*thisview.hvec[0], d*thisview.hvec[1], + d*thisview.hvec[2]); + glCallList(displist); + glMatrixMode(GL_MODELVIEW); + glPopMatrix(); + setstereobuf(STEREO_BUFFER_LEFT); + } glXSwapBuffers(ourdisplay, gwind); /* calls glFlush() */ rgl_checkerr("rendering display list"); } @@ -554,7 +642,8 @@ XButtonPressedEvent *ebut; int rootx, rooty, wx, wy; unsigned int statemask; - copylastv("moving"); + copylastv( movorb ? (movdir ? "left/right" : "up/down") : + (movdir ? "fore/back" : "rotate") ); XNoOp(ourdisplay); while (!XCheckMaskEvent(ourdisplay, @@ -609,8 +698,8 @@ register VIEW *vp; { double d, xmin, xmax, ymin, ymax, zmin, zmax; - zmin = 0.05; - zmax = 5000.; + zmin = 0.1; + zmax = 1000.; if (thisview.vfore > FTINY) zmin = thisview.vfore; if (thisview.vaft > FTINY) @@ -654,7 +743,7 @@ register XKeyPressedEvent *ekey; headlocked = 0; break; case 'l': /* retrieve last (premouse) view */ - if (lastvc != NULL) { + if (lastview.type) { VIEW vtmp; copystruct(&vtmp, &thisview); dev_view(&lastview); @@ -728,6 +817,7 @@ int vwnum; vwnum = 0; if (vwnum == currentview) return; + copylastv("standard view"); dev_view(vwl[currentview=vwnum].v); } @@ -768,6 +858,8 @@ VIEW *vp; copylastv(cause) /* copy last view position */ char *cause; { + static char *lastvc; + if (cause == lastvc) return; /* only record one view per cause */ lastvc = cause; @@ -798,6 +890,8 @@ register XConfigureEvent *ersz; glViewport(0, 0, hres=ersz->width, vres=ersz->height); if (hres > maxhres) maxhres = hres; if (vres > maxvres) maxvres = vres; + if (in_dev_view) + return; wa = (vres*pheight)/(hres*pwidth); va = viewaspect(&thisview); if (va > wa+.05) {