111 |
|
static int viewsteady; /* is view steady? */ |
112 |
|
|
113 |
|
static int resizewindow(), getevent(), getkey(), moveview(), wipeclean(), |
114 |
< |
xferdepth(), setglortho(), |
114 |
> |
xferdepth(), freedepth(), setglortho(), |
115 |
|
setglpersp(), getframe(), getmove(), fixwindow(), mytmflags(); |
116 |
|
|
117 |
|
static double getdistance(); |
120 |
|
static int pushright(), popright(); |
121 |
|
#endif |
122 |
|
|
123 |
+ |
extern int gmPortals; /* GL portal list id */ |
124 |
+ |
|
125 |
|
extern time_t time(); |
126 |
|
|
127 |
|
|
258 |
|
#ifdef DOBJ |
259 |
|
dobj_cleanup(); |
260 |
|
#endif |
261 |
+ |
freedepth(); |
262 |
+ |
gmEndGeom(); |
263 |
+ |
gmEndPortal(); |
264 |
|
odDone(); |
265 |
|
glXMakeCurrent(ourdisplay, None, NULL); |
266 |
|
glXDestroyContext(ourdisplay, gctx); |
337 |
|
} |
338 |
|
|
339 |
|
|
340 |
< |
dev_section(ofn) /* add octree for geometry rendering */ |
341 |
< |
char *ofn; |
340 |
> |
dev_section(gfn, pfn) /* add octree for geometry rendering */ |
341 |
> |
char *gfn, *pfn; |
342 |
|
{ |
343 |
|
extern char *index(); |
344 |
|
char *cp; |
345 |
|
|
346 |
< |
if (ofn == NULL) |
347 |
< |
otEndOctree(); |
348 |
< |
else if (access(ofn, R_OK) == 0) |
349 |
< |
otNewOctree(ofn); |
346 |
> |
if (gfn == NULL) { |
347 |
> |
gmEndGeom(); |
348 |
> |
gmEndPortal(); |
349 |
> |
return; |
350 |
> |
} |
351 |
> |
if (access(gfn, R_OK) == 0) |
352 |
> |
gmNewGeom(gfn); |
353 |
|
#ifdef DEBUG |
354 |
|
else { |
355 |
< |
sprintf(errmsg, "cannot load octree \"%s\"", ofn); |
355 |
> |
sprintf(errmsg, "cannot load octree \"%s\"", gfn); |
356 |
|
error(WARNING, errmsg); |
357 |
|
} |
358 |
|
#endif |
359 |
+ |
if (pfn != NULL) |
360 |
+ |
gmNewPortal(pfn); |
361 |
|
} |
362 |
|
|
363 |
|
|
429 |
|
if (mapped && isperspective > 0) { |
430 |
|
#ifdef STEREO |
431 |
|
pushright(); /* draw right eye */ |
432 |
< |
otDrawOctrees(); |
432 |
> |
gmDrawGeom(0); |
433 |
|
#ifdef DOBJ |
434 |
|
dobj_render(); |
435 |
|
#endif |
436 |
|
checkglerr("rendering right eye"); |
437 |
|
popright(); /* draw left eye */ |
438 |
|
#endif |
439 |
< |
ndrawn = otDrawOctrees(); |
439 |
> |
ndrawn = gmDrawGeom(1); |
440 |
|
#ifdef DOBJ |
441 |
|
ndrawn += dobj_render(); |
442 |
|
#endif |
484 |
|
xferdepth() /* load and clear depth buffer */ |
485 |
|
{ |
486 |
|
register GLfloat *dbp; |
487 |
+ |
register GLubyte *abuf; |
488 |
|
|
489 |
|
if (depthbuffer == NULL) { |
490 |
|
#ifdef STEREO |
506 |
|
odDepthMap(1, depthright); |
507 |
|
glClear(GL_DEPTH_BUFFER_BIT); |
508 |
|
#endif |
509 |
+ |
/* read back depth buffer */ |
510 |
|
glReadPixels(0, 0, odev.hres, odev.vres, |
511 |
|
GL_DEPTH_COMPONENT, GL_FLOAT, depthbuffer); |
512 |
+ |
/* read alpha buffer for portals */ |
513 |
+ |
if (gmPortals) |
514 |
+ |
abuf = (GLubyte *)malloc(odev.hres*odev.vres*sizeof(GLubyte)); |
515 |
+ |
else |
516 |
+ |
abuf = NULL; |
517 |
+ |
if (abuf != NULL) |
518 |
+ |
glReadPixels(0, 0, odev.hres, odev.vres, |
519 |
+ |
GL_ALPHA, GL_UNSIGNED_BYTE, abuf); |
520 |
|
for (dbp = depthbuffer + odev.hres*odev.vres; dbp-- > depthbuffer; ) |
521 |
< |
*dbp = mapdepth(*dbp); |
521 |
> |
if (abuf != NULL && abuf[dbp-depthbuffer]) |
522 |
> |
*dbp = FHUGE; |
523 |
> |
else |
524 |
> |
*dbp = mapdepth(*dbp); |
525 |
|
odDepthMap(0, depthbuffer); /* transfer depth data */ |
526 |
|
glClear(GL_DEPTH_BUFFER_BIT); /* clear system buffer */ |
527 |
+ |
if (abuf != NULL) |
528 |
+ |
free((char *)abuf); /* free alpha buffer */ |
529 |
|
} |
530 |
|
|
531 |
|
|
532 |
+ |
static |
533 |
+ |
freedepth() /* free recorded depth buffer */ |
534 |
+ |
{ |
535 |
+ |
if (depthbuffer == NULL) |
536 |
+ |
return; |
537 |
+ |
#ifdef STEREO |
538 |
+ |
odDepthMap(1, NULL); |
539 |
+ |
free((char *)depthright); |
540 |
+ |
depthright = NULL; |
541 |
+ |
#endif |
542 |
+ |
odDepthMap(0, NULL); |
543 |
+ |
free((char *)depthbuffer); |
544 |
+ |
depthbuffer = NULL; |
545 |
+ |
} |
546 |
+ |
|
547 |
+ |
|
548 |
|
static double |
549 |
|
getdistance(dx, dy, direc) /* distance from fore plane along view ray */ |
550 |
|
int dx, dy; |
551 |
|
FVECT direc; |
552 |
|
{ |
553 |
|
GLfloat gldepth; |
554 |
+ |
GLubyte glalpha; |
555 |
|
double dist; |
556 |
|
|
557 |
|
if (dx<0 | dx>=odev.hres | dy<0 | dy>=odev.vres) |
561 |
|
else { |
562 |
|
glReadPixels(dx,dy, 1,1, GL_DEPTH_COMPONENT, |
563 |
|
GL_FLOAT, &gldepth); |
564 |
< |
dist = mapdepth(gldepth); |
564 |
> |
if (gmPortals) |
565 |
> |
glReadPixels(dx,dy, 1,1, GL_ALPHA, |
566 |
> |
GL_UNSIGNED_BYTE, &glalpha); |
567 |
> |
else |
568 |
> |
glalpha = 0; |
569 |
> |
dist = glalpha ? FHUGE : mapdepth(gldepth); |
570 |
|
} |
571 |
|
if (dist >= .99*FHUGE) |
572 |
|
return(FHUGE); |
641 |
|
mapped = 0; |
642 |
|
break; |
643 |
|
case MapNotify: |
644 |
+ |
odRemap(0); |
645 |
|
mapped = 1; |
646 |
|
break; |
647 |
|
case Expose: |
737 |
|
if (setview(&nv) != NULL) |
738 |
|
return(0); /* illegal view */ |
739 |
|
dev_view(&nv); |
740 |
< |
inpresflags |= DFL(DC_SETVIEW)|DFL(DC_REDRAW); |
740 |
> |
inpresflags |= DFL(DC_SETVIEW); |
741 |
|
return(1); |
742 |
|
} |
743 |
|
|
771 |
|
{ |
772 |
|
int movdir = MOVDIR(ebut->button); |
773 |
|
int movorb = MOVORB(ebut->state); |
774 |
+ |
int ndrawn; |
775 |
|
Window rootw, childw; |
776 |
|
int rootx, rooty, wx, wy; |
777 |
|
unsigned int statemask; |
795 |
|
#ifdef STEREO |
796 |
|
pushright(); |
797 |
|
draw_grids(1); |
798 |
< |
otDrawOctrees(); |
798 |
> |
gmDrawGeom(0); |
799 |
|
#ifdef DOBJ |
800 |
|
dobj_render(); |
801 |
|
#endif |
802 |
|
popright(); |
803 |
|
#endif |
804 |
|
/* redraw octrees */ |
805 |
< |
otDrawOctrees(); |
805 |
> |
ndrawn = gmDrawGeom(1); |
806 |
|
#ifdef DOBJ |
807 |
< |
dobj_render(); /* redraw objects */ |
807 |
> |
ndrawn += dobj_render(); /* redraw objects */ |
808 |
|
#endif |
809 |
|
glFlush(); |
810 |
+ |
if (!ndrawn) { |
811 |
+ |
sleep(1); /* for reasonable interaction */ |
812 |
+ |
#ifdef STEREO |
813 |
+ |
pushright(); |
814 |
+ |
draw_grids(0); |
815 |
+ |
popright(); |
816 |
+ |
#endif |
817 |
+ |
draw_grids(0); |
818 |
+ |
} |
819 |
|
} |
820 |
|
if (!(inpresflags & DFL(DC_SETVIEW))) { /* do final motion */ |
821 |
|
movdir = MOVDIR(levptr(XButtonReleasedEvent)->button); |
834 |
|
GLfloat vec[4]; |
835 |
|
double depthlim[2]; |
836 |
|
/* set depth limits */ |
837 |
< |
otDepthLimit(depthlim, odev.v.vp, odev.v.vdir); |
837 |
> |
gmDepthLimit(depthlim, odev.v.vp, odev.v.vdir); |
838 |
|
if (depthlim[0] >= depthlim[1]) { |
839 |
|
dev_zmin = 1.; |
840 |
|
dev_zmax = 100.; |
841 |
|
} else { |
842 |
|
dev_zmin = 0.5*depthlim[0]; |
843 |
< |
dev_zmax = 1.5*depthlim[1]; |
843 |
> |
dev_zmax = 1.75*depthlim[1]; |
844 |
|
if (dev_zmin > dev_zmax/5.) |
845 |
|
dev_zmin = dev_zmax/5.; |
846 |
|
} |
915 |
|
glClear(GL_DEPTH_BUFFER_BIT); |
916 |
|
if (viewsteady) /* clear samples if steady */ |
917 |
|
odClean(); |
918 |
< |
if (depthbuffer != NULL) { /* free recorded depth buffer */ |
861 |
< |
#ifdef STEREO |
862 |
< |
odDepthMap(1, NULL); |
863 |
< |
free((char *)depthright); |
864 |
< |
depthright = NULL; |
865 |
< |
#endif |
866 |
< |
odDepthMap(0, NULL); |
867 |
< |
free((char *)depthbuffer); |
868 |
< |
depthbuffer = NULL; |
869 |
< |
} |
918 |
> |
freedepth(); |
919 |
|
setglpersp(&odev.v); /* reset view & clipping planes */ |
920 |
|
} |
921 |
|
|
966 |
|
inpresflags |= DFL(DC_RESUME); |
967 |
|
return; |
968 |
|
case CTRL('R'): /* redraw screen */ |
969 |
< |
odRemap(); |
969 |
> |
odRemap(0); |
970 |
|
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); |
971 |
|
#ifdef STEREO |
972 |
|
setstereobuf(STEREO_BUFFER_RIGHT); |
981 |
|
XFlush(ourdisplay); |
982 |
|
sleep(1); |
983 |
|
wipeclean(); /* fresh display */ |
984 |
< |
odRemap(); /* new tone mapping */ |
984 |
> |
odRemap(1); /* fresh tone mapping */ |
985 |
|
dev_flush(); /* draw octrees */ |
986 |
|
inpresflags |= DFL(DC_REDRAW); /* resend values from server */ |
987 |
|
rayqleft = 0; /* hold off update */ |
1018 |
|
xmin = eexp->x; xmax = eexp->x + eexp->width; |
1019 |
|
ymin = odev.vres - eexp->y - eexp->height; ymax = odev.vres - eexp->y; |
1020 |
|
/* clear portion of depth */ |
1021 |
+ |
glPushAttrib(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT); |
1022 |
|
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); |
1023 |
|
glDepthFunc(GL_ALWAYS); |
1024 |
|
glBegin(GL_POLYGON); |
1038 |
|
odRedraw(1, xmin, ymin, xmax, ymax); |
1039 |
|
setstereobuf(STEREO_BUFFER_LEFT); |
1040 |
|
#endif |
1041 |
< |
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); |
992 |
< |
glDepthFunc(GL_LEQUAL); |
1041 |
> |
glPopAttrib(); |
1042 |
|
odRedraw(0, xmin, ymin, xmax, ymax); |
1043 |
|
} |
1044 |
|
|
1058 |
|
odev.v.horiz = 2.*180./PI * atan(0.5/VIEWDIST*pwidth*odev.hres); |
1059 |
|
odev.v.vert = 2.*180./PI * atan(0.5/VIEWDIST*pheight*odev.vres); |
1060 |
|
|
1061 |
< |
inpresflags |= DFL(DC_SETVIEW)|DFL(DC_REDRAW); |
1061 |
> |
inpresflags |= DFL(DC_SETVIEW); |
1062 |
|
} |