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 |
+ |
#include "radogl.h" |
16 |
+ |
#include "view.h" |
17 |
+ |
#include "paths.h" |
18 |
|
#include "glradicon.h" |
19 |
|
|
20 |
|
#ifndef MAXVIEW |
31 |
|
#define MOVDEG (-5) /* degrees to orbit CW/down /frame */ |
32 |
|
#define MOVORB(s) ((s)&ShiftMask ? 1 : (s)&ControlMask ? -1 : 0) |
33 |
|
|
36 |
– |
#define MINWIDTH 480 /* minimum graphics window width */ |
37 |
– |
#define MINHEIGHT 400 /* minimum graphics window height */ |
38 |
– |
|
34 |
|
#define BORWIDTH 5 /* border width */ |
35 |
|
|
36 |
|
#define ourscreen DefaultScreen(ourdisplay) |
88 |
|
|
89 |
|
int displist; /* our scene display list */ |
90 |
|
|
91 |
< |
int in_dev_view = 0; /* currently in dev_view() */ |
91 |
> |
int no_render = 0; /* don't rerender */ |
92 |
|
|
93 |
< |
#ifdef BSD |
99 |
< |
#define strchr index |
100 |
< |
#endif |
101 |
< |
|
102 |
< |
extern char *strchr(), *fgets(), *fgetline(), *atos(), *scan4var(); |
93 |
> |
extern char *fgetline(), *atos(), *scan4var(); |
94 |
|
extern int nowarn; /* turn warnings off? */ |
104 |
– |
extern time_t time(); |
95 |
|
|
96 |
|
|
97 |
|
main(argc, argv) |
154 |
|
dev_open(radfile = argv[i]); |
155 |
|
/* load octree or scene files */ |
156 |
|
if (octree != NULL) { |
157 |
< |
displist = rgl_octlist(octree, NULL, NULL); |
157 |
> |
displist = rgl_octlist(octree, NULL, NULL, NULL); |
158 |
|
startrtrace(octree); |
159 |
|
} else |
160 |
< |
displist = rgl_filelist(nscenef, scene); |
160 |
> |
displist = rgl_filelist(nscenef, scene, NULL); |
161 |
|
/* set initial view */ |
162 |
|
dev_view(currentview < 0 ? &thisview : vwl[currentview].v); |
163 |
|
/* input/render loop */ |
166 |
|
/* all done */ |
167 |
|
quit(0); |
168 |
|
userr: |
169 |
< |
fprintf(stderr, "Usage: %s [-w][-b][-v view] rfile [VAR=value]..\n", |
169 |
> |
fprintf(stderr, |
170 |
> |
"Usage: %s [-w][-s][-b][-S][-v view] rfile [VAR=value]..\n", |
171 |
|
argv[0]); |
172 |
|
quit(1); |
173 |
|
} |
174 |
|
|
175 |
|
|
176 |
+ |
void |
177 |
|
quit(code) /* exit gracefully */ |
178 |
|
int code; |
179 |
|
{ |
292 |
|
atof(sskip2(buf+4,1)), |
293 |
|
atof(sskip2(buf+4,2))); |
294 |
|
else if (backvis && !strncmp(buf, "-bv", 3) && |
295 |
< |
(!buf[3] || strchr(" 0-FfNn", buf[3]) != NULL)) |
295 |
> |
(!buf[3] || strchr("0-FfNn \n",buf[3])!=NULL)) |
296 |
|
backvis = 0; |
297 |
|
fclose(fp); |
298 |
|
unlink(optfile); /* delete options file */ |
366 |
|
GLX_DOUBLEBUFFER, GLX_DEPTH_SIZE,15, None}; |
367 |
|
XSetWindowAttributes ourwinattr; |
368 |
|
XWMHints ourxwmhints; |
377 |
– |
XSizeHints oursizhints; |
369 |
|
/* open display server */ |
370 |
|
ourdisplay = XOpenDisplay(NULL); |
371 |
|
if (ourdisplay == NULL) |
412 |
|
ourxwmhints.icon_pixmap = XCreateBitmapFromData(ourdisplay, |
413 |
|
gwind, glradicon_bits, glradicon_width, glradicon_height); |
414 |
|
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); |
415 |
|
/* set GLX context */ |
416 |
|
glXMakeCurrent(ourdisplay, gwind, gctx); |
417 |
|
glEnable(GL_DEPTH_TEST); |
418 |
|
glDepthFunc(GL_LESS); |
419 |
|
glShadeModel(GL_SMOOTH); |
420 |
|
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); |
421 |
< |
glLightModelf(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE); |
421 |
> |
glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE); |
422 |
|
glEnable(GL_LIGHTING); |
423 |
+ |
glFrontFace(GL_CCW); |
424 |
+ |
glCullFace(GL_BACK); |
425 |
|
if (backvis) |
426 |
|
glDisable(GL_CULL_FACE); |
427 |
< |
else { |
439 |
< |
glFrontFace(GL_CCW); |
440 |
< |
glCullFace(GL_BACK); |
427 |
> |
else |
428 |
|
glEnable(GL_CULL_FACE); |
442 |
– |
} |
429 |
|
glDrawBuffer(GL_BACK); |
430 |
|
/* figure out sensible view */ |
431 |
|
pwidth = (double)DisplayWidthMM(ourdisplay, ourscreen) / |
438 |
|
} |
439 |
|
/* map the window */ |
440 |
|
XMapWindow(ourdisplay, gwind); |
441 |
+ |
no_render++; |
442 |
|
do |
443 |
|
dev_input(0); /* get resize event */ |
444 |
|
while (hres == 0 & vres == 0); |
445 |
+ |
no_render--; |
446 |
|
rgl_checkerr("initializing GLX"); |
447 |
|
} |
448 |
|
|
493 |
|
} |
494 |
|
} |
495 |
|
if (newhres != hres | newvres != vres) { |
496 |
< |
in_dev_view++; |
496 |
> |
no_render++; |
497 |
|
XResizeWindow(ourdisplay, gwind, newhres, newvres); |
498 |
|
do |
499 |
|
dev_input(0); /* get resize event */ |
500 |
|
while (newhres != hres | newvres != vres); |
501 |
< |
in_dev_view--; |
501 |
> |
no_render--; |
502 |
|
} |
503 |
|
} |
504 |
|
copystruct(&thisview, nv); |
552 |
|
{ |
553 |
|
double d; |
554 |
|
|
555 |
< |
if (!mapped) |
555 |
> |
if (!mapped | no_render) |
556 |
|
return; |
557 |
|
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); |
558 |
|
glCallList(displist); |
620 |
|
} |
621 |
|
|
622 |
|
|
623 |
+ |
static |
624 |
+ |
waitabit() /* pause a moment */ |
625 |
+ |
{ |
626 |
+ |
struct timespec ts; |
627 |
+ |
ts.tv_sec = 0; |
628 |
+ |
ts.tv_nsec = 5000000; |
629 |
+ |
nanosleep(&ts, NULL); |
630 |
+ |
} |
631 |
+ |
|
632 |
+ |
|
633 |
|
getmove(ebut) /* get view change */ |
634 |
|
XButtonPressedEvent *ebut; |
635 |
|
{ |
646 |
|
|
647 |
|
while (!XCheckMaskEvent(ourdisplay, |
648 |
|
ButtonReleaseMask, levptr(XEvent))) { |
649 |
+ |
/* pause so as not to move too fast */ |
650 |
+ |
waitabit(); |
651 |
|
|
652 |
|
if (!XQueryPointer(ourdisplay, gwind, &rootw, &childw, |
653 |
|
&rootx, &rooty, &wx, &wy, &statemask)) |
683 |
|
if (md <= FTINY) md = FHUGE; |
684 |
|
fbuf[3] = dir[0]*md; fbuf[4] = dir[1]*md; fbuf[5] = dir[2]*md; |
685 |
|
/* trace that ray */ |
686 |
< |
if (process(rtpd, fbuf, fbuf, 4*sizeof(float), 6*sizeof(float)) != |
687 |
< |
4*sizeof(float)) |
686 |
> |
if (process(rtpd, (char *)fbuf, (char *)fbuf, |
687 |
> |
4*sizeof(float), 6*sizeof(float)) != 4*sizeof(float)) |
688 |
|
error(INTERNAL, "error getting data back from rtrace process"); |
689 |
|
if (fbuf[3] >= .99*FHUGE) |
690 |
|
return(0); /* missed local objects */ |
815 |
|
; |
816 |
|
else if (vwnum >= MAXVIEW || vwl[vwnum].v == NULL) |
817 |
|
vwnum = 0; |
818 |
– |
if (vwnum == currentview) |
819 |
– |
return; |
818 |
|
copylastv("standard view"); |
819 |
|
dev_view(vwl[currentview=vwnum].v); |
820 |
|
} |
888 |
|
glViewport(0, 0, hres=ersz->width, vres=ersz->height); |
889 |
|
if (hres > maxhres) maxhres = hres; |
890 |
|
if (vres > maxvres) maxvres = vres; |
891 |
< |
if (in_dev_view) |
891 |
> |
if (no_render) |
892 |
|
return; |
893 |
|
wa = (vres*pheight)/(hres*pwidth); |
894 |
|
va = viewaspect(&thisview); |