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 |
|
|
33 |
|
#define MOVDEG (-5) /* degrees to orbit CW/down /frame */ |
34 |
|
#define MOVORB(s) ((s)&ShiftMask ? 1 : (s)&ControlMask ? -1 : 0) |
35 |
|
|
33 |
– |
#define MINWIDTH 480 /* minimum graphics window width */ |
34 |
– |
#define MINHEIGHT 400 /* minimum graphics window height */ |
35 |
– |
|
36 |
|
#define BORWIDTH 5 /* border width */ |
37 |
|
|
38 |
|
#define ourscreen DefaultScreen(ourdisplay) |
65 |
|
|
66 |
|
int currentview = 0; /* current view number */ |
67 |
|
VIEW thisview = STDVIEW; /* displayed view */ |
68 |
+ |
double eyedist = 1; /* interocular distance */ |
69 |
|
VIEW lastview; /* last recorded view */ |
69 |
– |
char *lastvc = NULL; /* cause of last view change */ |
70 |
|
|
71 |
|
char *progname; /* global argv[0] */ |
72 |
|
char *radfile; /* rad input file */ |
76 |
|
|
77 |
|
int rtpd[3]; /* rtrace process descriptors */ |
78 |
|
|
79 |
+ |
int silent = 0; /* run rad silently? */ |
80 |
|
int backvis = 1; /* back faces visible? */ |
81 |
+ |
int stereo = 0; /* do stereo? */ |
82 |
|
|
83 |
+ |
#ifdef NOSTEREO |
84 |
+ |
#define setstereobuf(bid) 0 |
85 |
+ |
#else |
86 |
+ |
#define setstereobuf(bid) (glXWaitGL(), \ |
87 |
+ |
XSGISetStereoBuffer(ourdisplay, gwind, bid), \ |
88 |
+ |
glXWaitX()) |
89 |
+ |
#endif |
90 |
+ |
|
91 |
|
int displist; /* our scene display list */ |
92 |
|
|
93 |
< |
extern char *fgets(), *fgetline(), *atos(), *scan4var(); |
93 |
> |
int no_render = 0; /* don't rerender */ |
94 |
> |
|
95 |
> |
#ifdef BSD |
96 |
> |
#define strchr index |
97 |
> |
#endif |
98 |
> |
|
99 |
> |
extern char *strchr(), *fgets(), *fgetline(), *atos(), *scan4var(); |
100 |
|
extern int nowarn; /* turn warnings off? */ |
101 |
|
extern time_t time(); |
102 |
|
|
118 |
|
case 'w': |
119 |
|
nowarn = !nowarn; |
120 |
|
break; |
121 |
+ |
case 's': |
122 |
+ |
silent = !silent; |
123 |
+ |
break; |
124 |
+ |
case 'S': |
125 |
+ |
stereo = !stereo; |
126 |
+ |
break; |
127 |
|
case 'c': |
128 |
|
vwintvl = atoi(argv[++i]); |
129 |
|
break; |
135 |
|
} |
136 |
|
if (i >= argc) |
137 |
|
goto userr; |
138 |
+ |
#ifdef NOSTEREO |
139 |
+ |
if (stereo) |
140 |
+ |
error(INTERNAL, "stereo not supported in this version"); |
141 |
+ |
#endif |
142 |
|
/* run rad and get views */ |
143 |
|
runrad(argc-i, argv+i); |
144 |
|
/* check view */ |
145 |
< |
if (viewsel != NULL && (currentview = findvw(viewsel)) < 0) { |
146 |
< |
fprintf(stderr, "%s: no such view\n", viewsel); |
147 |
< |
quit(1); |
148 |
< |
} |
145 |
> |
if (viewsel != NULL) |
146 |
> |
if (viewsel[0] == '-') { |
147 |
> |
char *ve = viewsel; |
148 |
> |
if (!sscanview(&thisview, viewsel) || |
149 |
> |
(ve = setview(&thisview)) != NULL) { |
150 |
> |
fprintf(stderr, "%s: bad view: %s\n", |
151 |
> |
progname, ve); |
152 |
> |
quit(1); |
153 |
> |
} |
154 |
> |
currentview = -1; |
155 |
> |
} else if ((currentview = findvw(viewsel)) < 0) { |
156 |
> |
fprintf(stderr, "%s: no such view: %s\n", |
157 |
> |
progname, viewsel); |
158 |
> |
quit(1); |
159 |
> |
} |
160 |
|
/* open GL */ |
161 |
|
dev_open(radfile = argv[i]); |
162 |
|
/* load octree or scene files */ |
166 |
|
} else |
167 |
|
displist = rgl_filelist(nscenef, scene); |
168 |
|
/* set initial view */ |
169 |
< |
dev_view(vwl[currentview].v); |
169 |
> |
dev_view(currentview < 0 ? &thisview : vwl[currentview].v); |
170 |
|
/* input/render loop */ |
171 |
|
while (dev_input(vwintvl)) |
172 |
|
; |
173 |
|
/* all done */ |
174 |
|
quit(0); |
175 |
|
userr: |
176 |
< |
fprintf(stderr, "Usage: %s [-w][-c #secs][-v view] rfile [VAR=value]..\n", |
176 |
> |
fprintf(stderr, "Usage: %s [-w][-b][-v view] rfile [VAR=value]..\n", |
177 |
|
argv[0]); |
178 |
|
quit(1); |
179 |
|
} |
221 |
|
/* set rad commmand */ |
222 |
|
strcpy(radcomm, "rad -w -v 0 "); /* look out below! */ |
223 |
|
cp = radcomm + 19; |
224 |
+ |
if (silent) { |
225 |
+ |
strcpy(cp, "-s "); |
226 |
+ |
cp += 3; |
227 |
+ |
} |
228 |
|
while (ac--) { |
229 |
|
strcpy(cp, *av++); |
230 |
|
while (*cp) cp++; |
245 |
|
expval = atof(cp); |
246 |
|
if (*cp == '-' | *cp == '+') |
247 |
|
expval = pow(2., expval); |
248 |
+ |
expval *= 0.5; /* compensate for local shading */ |
249 |
|
} |
250 |
+ |
/* look for eye separation */ |
251 |
+ |
if ((cp = scan4var(buf, sizeof(buf), "EYESEP", fp)) != NULL) |
252 |
+ |
eyedist = atof(cp); |
253 |
|
/* look for materials */ |
254 |
|
while ((cp = scan4var(buf, sizeof(buf), "materials", fp)) != NULL) { |
255 |
|
nscenef += wordstring(scene+nscenef, cp); |
290 |
|
/* open options file */ |
291 |
|
if ((fp = fopen(optfile, "r")) == NULL) |
292 |
|
error(SYSTEM, "cannot open options file"); |
293 |
< |
/* get ambient value */ |
293 |
> |
/* get relevant options */ |
294 |
|
while (fgets(buf, sizeof(buf), fp) != NULL) |
295 |
< |
if (!strncmp(buf, "-av ", 4)) { |
295 |
> |
if (!strncmp(buf, "-av ", 4)) |
296 |
|
setcolor(ambval, atof(buf+4), |
297 |
|
atof(sskip2(buf+4,1)), |
298 |
|
atof(sskip2(buf+4,2))); |
299 |
< |
break; |
300 |
< |
} |
299 |
> |
else if (backvis && !strncmp(buf, "-bv", 3) && |
300 |
> |
(!buf[3] || strchr(" 0-FfNn", buf[3]) != NULL)) |
301 |
> |
backvis = 0; |
302 |
|
fclose(fp); |
303 |
|
unlink(optfile); /* delete options file */ |
304 |
|
} |
371 |
|
GLX_DOUBLEBUFFER, GLX_DEPTH_SIZE,15, None}; |
372 |
|
XSetWindowAttributes ourwinattr; |
373 |
|
XWMHints ourxwmhints; |
328 |
– |
XSizeHints oursizhints; |
374 |
|
/* open display server */ |
375 |
|
ourdisplay = XOpenDisplay(NULL); |
376 |
|
if (ourdisplay == NULL) |
396 |
|
if (gwind == 0) |
397 |
|
error(SYSTEM, "cannot create window\n"); |
398 |
|
XStoreName(ourdisplay, gwind, id); |
399 |
+ |
#ifndef NOSTEREO |
400 |
+ |
if (stereo) /* check if stereo working */ |
401 |
+ |
switch (XSGIQueryStereoMode(ourdisplay, gwind)) { |
402 |
+ |
case STEREO_TOP: |
403 |
+ |
case STEREO_BOTTOM: |
404 |
+ |
break; |
405 |
+ |
case STEREO_OFF: |
406 |
+ |
error(USER, |
407 |
+ |
"wrong video mode: run \"/usr/gfx/setmon -n STR_TOP\" first"); |
408 |
+ |
case X_STEREO_UNSUPPORTED: |
409 |
+ |
error(USER, "stereo not supported on this screen"); |
410 |
+ |
default: |
411 |
+ |
error(INTERNAL, "unknown stereo mode"); |
412 |
+ |
} |
413 |
+ |
#endif |
414 |
|
/* set window manager hints */ |
415 |
|
ourxwmhints.flags = InputHint|IconPixmapHint; |
416 |
|
ourxwmhints.input = True; |
417 |
|
ourxwmhints.icon_pixmap = XCreateBitmapFromData(ourdisplay, |
418 |
|
gwind, glradicon_bits, glradicon_width, glradicon_height); |
419 |
|
XSetWMHints(ourdisplay, gwind, &ourxwmhints); |
360 |
– |
oursizhints.min_width = MINWIDTH; |
361 |
– |
oursizhints.min_height = MINHEIGHT; |
362 |
– |
oursizhints.flags = PMinSize; |
363 |
– |
XSetNormalHints(ourdisplay, gwind, &oursizhints); |
420 |
|
/* set GLX context */ |
421 |
|
glXMakeCurrent(ourdisplay, gwind, gctx); |
422 |
|
glEnable(GL_DEPTH_TEST); |
438 |
|
DisplayWidth(ourdisplay, ourscreen); |
439 |
|
pheight = (double)DisplayHeightMM(ourdisplay, ourscreen) / |
440 |
|
DisplayHeight(ourdisplay, ourscreen); |
441 |
+ |
if (stereo) { /* set stereo mode */ |
442 |
+ |
setstereobuf(STEREO_BUFFER_LEFT); |
443 |
+ |
pheight *= 2.; |
444 |
+ |
} |
445 |
|
/* map the window */ |
446 |
|
XMapWindow(ourdisplay, gwind); |
447 |
+ |
no_render++; |
448 |
+ |
do |
449 |
+ |
dev_input(0); /* get resize event */ |
450 |
+ |
while (hres == 0 & vres == 0); |
451 |
+ |
no_render--; |
452 |
|
rgl_checkerr("initializing GLX"); |
453 |
|
} |
454 |
|
|
484 |
|
} |
485 |
|
if (hres != 0 & vres != 0) { |
486 |
|
wa = (vres*pheight)/(hres*pwidth); |
487 |
< |
va = viewaspect(&thisview); |
487 |
> |
va = viewaspect(nv); |
488 |
|
if (va > wa+.05) { |
489 |
|
newvres = (pwidth/pheight)*va*newhres + .5; |
490 |
|
if (newvres > maxvres) { |
499 |
|
} |
500 |
|
} |
501 |
|
if (newhres != hres | newvres != vres) { |
502 |
+ |
no_render++; |
503 |
|
XResizeWindow(ourdisplay, gwind, newhres, newvres); |
504 |
|
do |
505 |
|
dev_input(0); /* get resize event */ |
506 |
|
while (newhres != hres | newvres != vres); |
507 |
+ |
no_render--; |
508 |
|
} |
509 |
|
} |
510 |
|
copystruct(&thisview, nv); |
556 |
|
|
557 |
|
render() /* render our display list and swap buffers */ |
558 |
|
{ |
559 |
< |
if (!mapped) |
559 |
> |
double d; |
560 |
> |
|
561 |
> |
if (!mapped | no_render) |
562 |
|
return; |
563 |
|
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); |
564 |
|
glCallList(displist); |
565 |
+ |
if (stereo) { /* do right eye for stereo */ |
566 |
+ |
setstereobuf(STEREO_BUFFER_RIGHT); |
567 |
+ |
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); |
568 |
+ |
glMatrixMode(GL_MODELVIEW); |
569 |
+ |
glPushMatrix(); |
570 |
+ |
d = -eyedist / sqrt(thisview.hn2); |
571 |
+ |
glTranslated(d*thisview.hvec[0], d*thisview.hvec[1], |
572 |
+ |
d*thisview.hvec[2]); |
573 |
+ |
glCallList(displist); |
574 |
+ |
glMatrixMode(GL_MODELVIEW); |
575 |
+ |
glPopMatrix(); |
576 |
+ |
setstereobuf(STEREO_BUFFER_LEFT); |
577 |
+ |
} |
578 |
|
glXSwapBuffers(ourdisplay, gwind); /* calls glFlush() */ |
579 |
|
rgl_checkerr("rendering display list"); |
580 |
|
} |
636 |
|
int rootx, rooty, wx, wy; |
637 |
|
unsigned int statemask; |
638 |
|
|
639 |
< |
copylastv("moving"); |
639 |
> |
copylastv( movorb ? (movdir ? "left/right" : "up/down") : |
640 |
> |
(movdir ? "fore/back" : "rotate") ); |
641 |
|
XNoOp(ourdisplay); |
642 |
|
|
643 |
|
while (!XCheckMaskEvent(ourdisplay, |
692 |
|
{ |
693 |
|
double d, xmin, xmax, ymin, ymax, zmin, zmax; |
694 |
|
|
695 |
< |
zmin = 0.05; |
696 |
< |
zmax = 5000.; |
695 |
> |
zmin = 0.1; |
696 |
> |
zmax = 1000.; |
697 |
|
if (thisview.vfore > FTINY) |
698 |
|
zmin = thisview.vfore; |
699 |
|
if (thisview.vaft > FTINY) |
737 |
|
headlocked = 0; |
738 |
|
break; |
739 |
|
case 'l': /* retrieve last (premouse) view */ |
740 |
< |
if (lastvc != NULL) { |
740 |
> |
if (lastview.type) { |
741 |
|
VIEW vtmp; |
742 |
|
copystruct(&vtmp, &thisview); |
743 |
|
dev_view(&lastview); |
809 |
|
; |
810 |
|
else if (vwnum >= MAXVIEW || vwl[vwnum].v == NULL) |
811 |
|
vwnum = 0; |
812 |
< |
if (vwnum == currentview) |
730 |
< |
return; |
812 |
> |
copylastv("standard view"); |
813 |
|
dev_view(vwl[currentview=vwnum].v); |
814 |
|
} |
815 |
|
|
850 |
|
copylastv(cause) /* copy last view position */ |
851 |
|
char *cause; |
852 |
|
{ |
853 |
+ |
static char *lastvc; |
854 |
+ |
|
855 |
|
if (cause == lastvc) |
856 |
|
return; /* only record one view per cause */ |
857 |
|
lastvc = cause; |
882 |
|
glViewport(0, 0, hres=ersz->width, vres=ersz->height); |
883 |
|
if (hres > maxhres) maxhres = hres; |
884 |
|
if (vres > maxvres) maxvres = vres; |
885 |
+ |
if (no_render) |
886 |
+ |
return; |
887 |
|
wa = (vres*pheight)/(hres*pwidth); |
888 |
|
va = viewaspect(&thisview); |
889 |
|
if (va > wa+.05) { |