1 |
– |
/* Copyright (c) 1998 Silicon Graphics, Inc. */ |
2 |
– |
|
1 |
|
#ifndef lint |
2 |
< |
static char SCCSid[] = "$SunId$ SGI"; |
2 |
> |
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
6 |
– |
|
4 |
|
/* |
5 |
|
* Program to display Radiance scene using OpenGL. |
6 |
|
*/ |
7 |
|
|
11 |
– |
#include "radogl.h" |
12 |
– |
#include "view.h" |
13 |
– |
#include "paths.h" |
8 |
|
#include <sys/types.h> |
9 |
|
#include <GL/glx.h> |
10 |
|
#ifndef NOSTEREO |
11 |
|
#include <X11/extensions/SGIStereo.h> |
12 |
|
#endif |
13 |
|
#include <ctype.h> |
14 |
+ |
#include <time.h> |
15 |
+ |
|
16 |
+ |
#include "radogl.h" |
17 |
+ |
#include "view.h" |
18 |
+ |
#include "paths.h" |
19 |
|
#include "glradicon.h" |
20 |
+ |
#include "rtprocess.h" |
21 |
|
|
22 |
|
#ifndef MAXVIEW |
23 |
|
#define MAXVIEW 63 /* maximum number of standard views */ |
33 |
|
#define MOVDEG (-5) /* degrees to orbit CW/down /frame */ |
34 |
|
#define MOVORB(s) ((s)&ShiftMask ? 1 : (s)&ControlMask ? -1 : 0) |
35 |
|
|
36 |
– |
#define MINWIDTH 480 /* minimum graphics window width */ |
37 |
– |
#define MINHEIGHT 400 /* minimum graphics window height */ |
38 |
– |
|
36 |
|
#define BORWIDTH 5 /* border width */ |
37 |
|
|
38 |
|
#define ourscreen DefaultScreen(ourdisplay) |
74 |
|
int nscenef = 0; /* number of scene files */ |
75 |
|
char *octree; /* octree name (NULL if unnec.) */ |
76 |
|
|
77 |
< |
int rtpd[3]; /* rtrace process descriptors */ |
77 |
> |
SUBPROC rtpd; /* rtrace process descriptors */ |
78 |
|
|
79 |
|
int silent = 0; /* run rad silently? */ |
80 |
|
int backvis = 1; /* back faces visible? */ |
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 |
< |
#ifdef BSD |
99 |
< |
#define strchr index |
100 |
< |
#endif |
101 |
< |
|
102 |
< |
extern char *strchr(), *fgets(), *fgetline(), *atos(), *scan4var(); |
95 |
> |
extern char *fgetline(), *atos(), *scan4var(); |
96 |
|
extern int nowarn; /* turn warnings off? */ |
104 |
– |
extern time_t time(); |
97 |
|
|
98 |
|
|
99 |
|
main(argc, argv) |
156 |
|
dev_open(radfile = argv[i]); |
157 |
|
/* load octree or scene files */ |
158 |
|
if (octree != NULL) { |
159 |
< |
displist = rgl_octlist(octree, NULL, NULL); |
159 |
> |
displist = rgl_octlist(octree, NULL, NULL, NULL); |
160 |
|
startrtrace(octree); |
161 |
|
} else |
162 |
< |
displist = rgl_filelist(nscenef, scene); |
162 |
> |
displist = rgl_filelist(nscenef, scene, NULL); |
163 |
|
/* set initial view */ |
164 |
|
dev_view(currentview < 0 ? &thisview : vwl[currentview].v); |
165 |
|
/* input/render loop */ |
168 |
|
/* all done */ |
169 |
|
quit(0); |
170 |
|
userr: |
171 |
< |
fprintf(stderr, "Usage: %s [-w][-b][-v view] rfile [VAR=value]..\n", |
171 |
> |
fprintf(stderr, |
172 |
> |
"Usage: %s [-w][-s][-b][-S][-v view] rfile [VAR=value]..\n", |
173 |
|
argv[0]); |
174 |
|
quit(1); |
175 |
|
} |
176 |
|
|
177 |
|
|
178 |
+ |
void |
179 |
|
quit(code) /* exit gracefully */ |
180 |
|
int code; |
181 |
|
{ |
182 |
|
if (ourdisplay != NULL) |
183 |
|
dev_close(); |
184 |
< |
if (rtpd[2] > 0) { |
185 |
< |
if (close_process(rtpd) > 0) |
184 |
> |
/* if (rtpd.pid > 0) { */ |
185 |
> |
if (rtpd.running) { |
186 |
> |
if (close_process(&rtpd) > 0) |
187 |
|
wputs("bad exit status from rtrace\n"); |
188 |
< |
rtpd[2] = 0; |
188 |
> |
/* rtpd.pid = 0; */ |
189 |
|
} |
190 |
|
exit(code); |
191 |
|
} |
201 |
|
if (nowarn) av[ac++] = "-w-"; |
202 |
|
av[ac++] = octname; |
203 |
|
av[ac] = NULL; |
204 |
< |
if (open_process(rtpd, av) <= 0) |
204 |
> |
if (open_process(&rtpd, av) <= 0) |
205 |
|
error(SYSTEM, "cannot start rtrace process"); |
206 |
|
} |
207 |
|
|
295 |
|
atof(sskip2(buf+4,1)), |
296 |
|
atof(sskip2(buf+4,2))); |
297 |
|
else if (backvis && !strncmp(buf, "-bv", 3) && |
298 |
< |
(!buf[3] || strchr(" 0-FfNn", buf[3]) != NULL)) |
298 |
> |
(!buf[3] || strchr("0-FfNn \n",buf[3])!=NULL)) |
299 |
|
backvis = 0; |
300 |
|
fclose(fp); |
301 |
|
unlink(optfile); /* delete options file */ |
369 |
|
GLX_DOUBLEBUFFER, GLX_DEPTH_SIZE,15, None}; |
370 |
|
XSetWindowAttributes ourwinattr; |
371 |
|
XWMHints ourxwmhints; |
377 |
– |
XSizeHints oursizhints; |
372 |
|
/* open display server */ |
373 |
|
ourdisplay = XOpenDisplay(NULL); |
374 |
|
if (ourdisplay == NULL) |
415 |
|
ourxwmhints.icon_pixmap = XCreateBitmapFromData(ourdisplay, |
416 |
|
gwind, glradicon_bits, glradicon_width, glradicon_height); |
417 |
|
XSetWMHints(ourdisplay, gwind, &ourxwmhints); |
424 |
– |
oursizhints.min_width = MINWIDTH; |
425 |
– |
oursizhints.min_height = stereo ? MINHEIGHT/2 : MINHEIGHT; |
426 |
– |
oursizhints.flags = PMinSize; |
427 |
– |
XSetNormalHints(ourdisplay, gwind, &oursizhints); |
418 |
|
/* set GLX context */ |
419 |
|
glXMakeCurrent(ourdisplay, gwind, gctx); |
420 |
|
glEnable(GL_DEPTH_TEST); |
421 |
|
glDepthFunc(GL_LESS); |
422 |
|
glShadeModel(GL_SMOOTH); |
423 |
|
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); |
424 |
< |
glLightModelf(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE); |
424 |
> |
glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE); |
425 |
|
glEnable(GL_LIGHTING); |
426 |
+ |
glFrontFace(GL_CCW); |
427 |
+ |
glCullFace(GL_BACK); |
428 |
|
if (backvis) |
429 |
|
glDisable(GL_CULL_FACE); |
430 |
< |
else { |
439 |
< |
glFrontFace(GL_CCW); |
440 |
< |
glCullFace(GL_BACK); |
430 |
> |
else |
431 |
|
glEnable(GL_CULL_FACE); |
442 |
– |
} |
432 |
|
glDrawBuffer(GL_BACK); |
433 |
|
/* figure out sensible view */ |
434 |
|
pwidth = (double)DisplayWidthMM(ourdisplay, ourscreen) / |
441 |
|
} |
442 |
|
/* map the window */ |
443 |
|
XMapWindow(ourdisplay, gwind); |
444 |
+ |
no_render++; |
445 |
|
do |
446 |
|
dev_input(0); /* get resize event */ |
447 |
|
while (hres == 0 & vres == 0); |
448 |
+ |
no_render--; |
449 |
|
rgl_checkerr("initializing GLX"); |
450 |
|
} |
451 |
|
|
496 |
|
} |
497 |
|
} |
498 |
|
if (newhres != hres | newvres != vres) { |
499 |
< |
in_dev_view++; |
499 |
> |
no_render++; |
500 |
|
XResizeWindow(ourdisplay, gwind, newhres, newvres); |
501 |
|
do |
502 |
|
dev_input(0); /* get resize event */ |
503 |
|
while (newhres != hres | newvres != vres); |
504 |
< |
in_dev_view--; |
504 |
> |
no_render--; |
505 |
|
} |
506 |
|
} |
507 |
|
copystruct(&thisview, nv); |
555 |
|
{ |
556 |
|
double d; |
557 |
|
|
558 |
< |
if (!mapped) |
558 |
> |
if (!mapped | no_render) |
559 |
|
return; |
560 |
|
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); |
561 |
|
glCallList(displist); |
623 |
|
} |
624 |
|
|
625 |
|
|
626 |
+ |
static |
627 |
+ |
waitabit() /* pause a moment */ |
628 |
+ |
{ |
629 |
+ |
struct timespec ts; |
630 |
+ |
ts.tv_sec = 0; |
631 |
+ |
ts.tv_nsec = 5000000; |
632 |
+ |
nanosleep(&ts, NULL); |
633 |
+ |
} |
634 |
+ |
|
635 |
+ |
|
636 |
|
getmove(ebut) /* get view change */ |
637 |
|
XButtonPressedEvent *ebut; |
638 |
|
{ |
649 |
|
|
650 |
|
while (!XCheckMaskEvent(ourdisplay, |
651 |
|
ButtonReleaseMask, levptr(XEvent))) { |
652 |
+ |
/* pause so as not to move too fast */ |
653 |
+ |
waitabit(); |
654 |
|
|
655 |
|
if (!XQueryPointer(ourdisplay, gwind, &rootw, &childw, |
656 |
|
&rootx, &rooty, &wx, &wy, &statemask)) |
678 |
|
{ |
679 |
|
float fbuf[6]; |
680 |
|
/* check to see if rtrace is running */ |
681 |
< |
if (rtpd[2] <= 0) |
681 |
> |
/* if (rtpd.pid <= 0) */ |
682 |
> |
if (!rtpd.running) |
683 |
|
return(0); |
684 |
|
/* assign origin */ |
685 |
|
fbuf[0] = org[0]; fbuf[1] = org[1]; fbuf[2] = org[2]; |
687 |
|
if (md <= FTINY) md = FHUGE; |
688 |
|
fbuf[3] = dir[0]*md; fbuf[4] = dir[1]*md; fbuf[5] = dir[2]*md; |
689 |
|
/* trace that ray */ |
690 |
< |
if (process(rtpd, fbuf, fbuf, 4*sizeof(float), 6*sizeof(float)) != |
691 |
< |
4*sizeof(float)) |
690 |
> |
if (process(&rtpd, (char *)fbuf, (char *)fbuf, |
691 |
> |
4*sizeof(float), 6*sizeof(float)) != 4*sizeof(float)) |
692 |
|
error(INTERNAL, "error getting data back from rtrace process"); |
693 |
|
if (fbuf[3] >= .99*FHUGE) |
694 |
|
return(0); /* missed local objects */ |
819 |
|
; |
820 |
|
else if (vwnum >= MAXVIEW || vwl[vwnum].v == NULL) |
821 |
|
vwnum = 0; |
818 |
– |
if (vwnum == currentview) |
819 |
– |
return; |
822 |
|
copylastv("standard view"); |
823 |
|
dev_view(vwl[currentview=vwnum].v); |
824 |
|
} |
892 |
|
glViewport(0, 0, hres=ersz->width, vres=ersz->height); |
893 |
|
if (hres > maxhres) maxhres = hres; |
894 |
|
if (vres > maxvres) maxvres = vres; |
895 |
< |
if (in_dev_view) |
895 |
> |
if (no_render) |
896 |
|
return; |
897 |
|
wa = (vres*pheight)/(hres*pwidth); |
898 |
|
va = viewaspect(&thisview); |