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 */ |
70 |
|
|
71 |
|
char *progname; /* global argv[0] */ |
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 |
< |
int in_dev_view = 0; /* currently in dev_view() */ |
93 |
> |
int no_render = 0; /* don't rerender */ |
94 |
|
|
95 |
< |
extern char *fgets(), *fgetline(), *atos(), *scan4var(); |
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 */ |
173 |
|
/* all done */ |
174 |
|
quit(0); |
175 |
|
userr: |
176 |
< |
fprintf(stderr, "Usage: %s [-w][-b][-v view] rfile [VAR=value]..\n", |
176 |
> |
fprintf(stderr, |
177 |
> |
"Usage: %s [-w][-s][-b][-S][-v view] rfile [VAR=value]..\n", |
178 |
|
argv[0]); |
179 |
|
quit(1); |
180 |
|
} |
222 |
|
/* set rad commmand */ |
223 |
|
strcpy(radcomm, "rad -w -v 0 "); /* look out below! */ |
224 |
|
cp = radcomm + 19; |
225 |
+ |
if (silent) { |
226 |
+ |
strcpy(cp, "-s "); |
227 |
+ |
cp += 3; |
228 |
+ |
} |
229 |
|
while (ac--) { |
230 |
|
strcpy(cp, *av++); |
231 |
|
while (*cp) cp++; |
248 |
|
expval = pow(2., expval); |
249 |
|
expval *= 0.5; /* compensate for local shading */ |
250 |
|
} |
251 |
+ |
/* look for eye separation */ |
252 |
+ |
if ((cp = scan4var(buf, sizeof(buf), "EYESEP", fp)) != NULL) |
253 |
+ |
eyedist = atof(cp); |
254 |
|
/* look for materials */ |
255 |
|
while ((cp = scan4var(buf, sizeof(buf), "materials", fp)) != NULL) { |
256 |
|
nscenef += wordstring(scene+nscenef, cp); |
291 |
|
/* open options file */ |
292 |
|
if ((fp = fopen(optfile, "r")) == NULL) |
293 |
|
error(SYSTEM, "cannot open options file"); |
294 |
< |
/* get ambient value */ |
294 |
> |
/* get relevant options */ |
295 |
|
while (fgets(buf, sizeof(buf), fp) != NULL) |
296 |
< |
if (!strncmp(buf, "-av ", 4)) { |
296 |
> |
if (!strncmp(buf, "-av ", 4)) |
297 |
|
setcolor(ambval, atof(buf+4), |
298 |
|
atof(sskip2(buf+4,1)), |
299 |
|
atof(sskip2(buf+4,2))); |
300 |
< |
break; |
301 |
< |
} |
300 |
> |
else if (backvis && !strncmp(buf, "-bv", 3) && |
301 |
> |
(!buf[3] || strchr(" 0-FfNn", buf[3]) != NULL)) |
302 |
> |
backvis = 0; |
303 |
|
fclose(fp); |
304 |
|
unlink(optfile); /* delete options file */ |
305 |
|
} |
372 |
|
GLX_DOUBLEBUFFER, GLX_DEPTH_SIZE,15, None}; |
373 |
|
XSetWindowAttributes ourwinattr; |
374 |
|
XWMHints ourxwmhints; |
341 |
– |
XSizeHints oursizhints; |
375 |
|
/* open display server */ |
376 |
|
ourdisplay = XOpenDisplay(NULL); |
377 |
|
if (ourdisplay == NULL) |
397 |
|
if (gwind == 0) |
398 |
|
error(SYSTEM, "cannot create window\n"); |
399 |
|
XStoreName(ourdisplay, gwind, id); |
400 |
+ |
#ifndef NOSTEREO |
401 |
+ |
if (stereo) /* check if stereo working */ |
402 |
+ |
switch (XSGIQueryStereoMode(ourdisplay, gwind)) { |
403 |
+ |
case STEREO_TOP: |
404 |
+ |
case STEREO_BOTTOM: |
405 |
+ |
break; |
406 |
+ |
case STEREO_OFF: |
407 |
+ |
error(USER, |
408 |
+ |
"wrong video mode: run \"/usr/gfx/setmon -n STR_TOP\" first"); |
409 |
+ |
case X_STEREO_UNSUPPORTED: |
410 |
+ |
error(USER, "stereo not supported on this screen"); |
411 |
+ |
default: |
412 |
+ |
error(INTERNAL, "unknown stereo mode"); |
413 |
+ |
} |
414 |
+ |
#endif |
415 |
|
/* set window manager hints */ |
416 |
|
ourxwmhints.flags = InputHint|IconPixmapHint; |
417 |
|
ourxwmhints.input = True; |
418 |
|
ourxwmhints.icon_pixmap = XCreateBitmapFromData(ourdisplay, |
419 |
|
gwind, glradicon_bits, glradicon_width, glradicon_height); |
420 |
|
XSetWMHints(ourdisplay, gwind, &ourxwmhints); |
373 |
– |
oursizhints.min_width = MINWIDTH; |
374 |
– |
oursizhints.min_height = MINHEIGHT; |
375 |
– |
oursizhints.flags = PMinSize; |
376 |
– |
XSetNormalHints(ourdisplay, gwind, &oursizhints); |
421 |
|
/* set GLX context */ |
422 |
|
glXMakeCurrent(ourdisplay, gwind, gctx); |
423 |
|
glEnable(GL_DEPTH_TEST); |
424 |
|
glDepthFunc(GL_LESS); |
425 |
|
glShadeModel(GL_SMOOTH); |
426 |
|
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); |
427 |
< |
glLightModelf(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE); |
427 |
> |
glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE); |
428 |
|
glEnable(GL_LIGHTING); |
429 |
+ |
glFrontFace(GL_CCW); |
430 |
+ |
glCullFace(GL_BACK); |
431 |
|
if (backvis) |
432 |
|
glDisable(GL_CULL_FACE); |
433 |
< |
else { |
388 |
< |
glFrontFace(GL_CCW); |
389 |
< |
glCullFace(GL_BACK); |
433 |
> |
else |
434 |
|
glEnable(GL_CULL_FACE); |
391 |
– |
} |
435 |
|
glDrawBuffer(GL_BACK); |
436 |
|
/* figure out sensible view */ |
437 |
|
pwidth = (double)DisplayWidthMM(ourdisplay, ourscreen) / |
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 |
|
|
499 |
|
} |
500 |
|
} |
501 |
|
if (newhres != hres | newvres != vres) { |
502 |
< |
in_dev_view++; |
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 |
< |
in_dev_view--; |
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 |
|
} |
809 |
|
; |
810 |
|
else if (vwnum >= MAXVIEW || vwl[vwnum].v == NULL) |
811 |
|
vwnum = 0; |
812 |
< |
if (vwnum == currentview) |
749 |
< |
return; |
750 |
< |
/* copylastv("change view"); */ |
812 |
> |
copylastv("standard view"); |
813 |
|
dev_view(vwl[currentview=vwnum].v); |
814 |
|
} |
815 |
|
|
882 |
|
glViewport(0, 0, hres=ersz->width, vres=ersz->height); |
883 |
|
if (hres > maxhres) maxhres = hres; |
884 |
|
if (vres > maxvres) maxvres = vres; |
885 |
< |
if (in_dev_view) |
885 |
> |
if (no_render) |
886 |
|
return; |
887 |
|
wa = (vres*pheight)/(hres*pwidth); |
888 |
|
va = viewaspect(&thisview); |