1 |
< |
/* Copyright (c) 1998 Silicon Graphics, Inc. */ |
1 |
> |
/* Copyright (c) 1999 Silicon Graphics, Inc. */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ SGI"; |
19 |
|
#endif |
20 |
|
|
21 |
|
int gmPortals = 0; /* current portal GL list id */ |
22 |
+ |
static int Nlists = 0; /* number of lists allocated */ |
23 |
|
static char *curportlist[MAXPORT]; /* current portal list */ |
24 |
|
static char *newportlist[MAXPORT]; /* new portal file list */ |
25 |
|
|
28 |
|
FVECT cent; /* centroid */ |
29 |
|
FLOAT rad; /* radius */ |
30 |
|
int listid; /* display list identifier */ |
31 |
+ |
int nlists; /* number of lists allocated */ |
32 |
|
} gmCurrent[MAXGEO], gmNext[MAXGEO]; /* current and next list */ |
33 |
|
|
34 |
|
#define FORALLGEOM(ot,i) for (i=0;i<MAXGEO&&ot[i].gfile!=NULL;i++) |
35 |
|
|
36 |
|
#define FORALLPORT(pl,i) for (i=0;i<MAXPORT&&pl[i]!=NULL;i++) |
37 |
|
|
38 |
< |
extern char *atos(), *sskip(), *sskip2(); |
38 |
> |
extern char *nextword(); |
39 |
|
|
40 |
|
|
41 |
|
gmNewGeom(file) /* add new geometry to next list */ |
57 |
|
return; |
58 |
|
} |
59 |
|
/* else load new octree */ |
60 |
< |
gmNext[i].gfile = file; |
60 |
> |
gmNext[i].gfile = savestr(file); |
61 |
|
dolights = 0; |
62 |
|
domats = 1; |
63 |
< |
gmNext[i].listid = rgl_octlist(file, gmNext[i].cent, &gmNext[i].rad); |
63 |
> |
gmNext[i].listid = rgl_octlist(file, gmNext[i].cent, &gmNext[i].rad, |
64 |
> |
&gmNext[i].nlists); |
65 |
> |
gmNext[i].rad *= 1.732; /* go to corners */ |
66 |
|
#ifdef DEBUG |
67 |
|
fprintf(stderr, "Loaded octree \"%s\" into listID %d with radius %f\n", |
68 |
|
file, gmNext[i].listid, gmNext[i].rad); |
78 |
|
FORALLGEOM(gmNext, j) |
79 |
|
if (gmNext[j].listid == gmCurrent[i].listid) |
80 |
|
break; |
81 |
< |
if (j >= MAXGEO || gmNext[j].gfile == NULL) |
82 |
< |
glDeleteLists(gmCurrent[i].listid, 1); /* not found */ |
81 |
> |
if (j >= MAXGEO || gmNext[j].gfile == NULL) { |
82 |
> |
glDeleteLists(gmCurrent[i].listid, /* not found */ |
83 |
> |
gmCurrent[i].nlists); |
84 |
> |
freestr(gmCurrent[i].gfile); |
85 |
> |
} |
86 |
|
} |
87 |
|
bcopy((char *)gmNext, (char *)gmCurrent, sizeof(gmNext)); |
88 |
|
bzero((char *)gmNext, sizeof(gmNext)); |
90 |
|
|
91 |
|
|
92 |
|
int |
93 |
< |
gmDrawGeom(clearports) /* draw current list of octrees (and ports) */ |
87 |
< |
int clearports; |
93 |
> |
gmDrawGeom() /* draw current list of octrees */ |
94 |
|
{ |
95 |
|
register int n; |
96 |
|
|
97 |
|
FORALLGEOM(gmCurrent, n) |
98 |
|
glCallList(gmCurrent[n].listid); |
99 |
< |
if (!n | !clearports | !gmPortals) |
100 |
< |
return(n); |
101 |
< |
/* mark alpha channel over the portals */ |
102 |
< |
glPushAttrib(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT); |
99 |
> |
return(n); |
100 |
> |
} |
101 |
> |
|
102 |
> |
|
103 |
> |
gmDrawPortals(r, g, b, a) /* draw portals with specific RGBA value */ |
104 |
> |
int r, g, b, a; |
105 |
> |
{ |
106 |
> |
if (!gmPortals || r<0 & g<0 & b<0 & a<0) |
107 |
> |
return; |
108 |
> |
glPushAttrib(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT| |
109 |
> |
GL_POLYGON_BIT|GL_LIGHTING_BIT); |
110 |
> |
glDisable(GL_LIGHTING); |
111 |
> |
glDisable(GL_DITHER); |
112 |
> |
glShadeModel(GL_FLAT); |
113 |
> |
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); |
114 |
> |
/* don't actually write depth */ |
115 |
|
glDepthMask(GL_FALSE); |
116 |
< |
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_TRUE); |
117 |
< |
glClear(GL_COLOR_BUFFER_BIT); |
118 |
< |
glColor4ub(0, 0, 0, 0xff); /* write alpha buffer as mask */ |
116 |
> |
/* draw only selected channels */ |
117 |
> |
glColorMask(r>=0, g>=0, b>=0, a>=0); |
118 |
> |
glColor4ub(r&0xff, g&0xff, b&0xff, a&0xff); |
119 |
|
glCallList(gmPortals); /* draw them portals */ |
120 |
|
glPopAttrib(); |
103 |
– |
return(n); |
121 |
|
} |
122 |
|
|
123 |
|
|
151 |
|
|
152 |
|
if (pflist == NULL) |
153 |
|
return; |
154 |
< |
while (*pflist) { |
138 |
< |
atos(newfile, sizeof(newfile), pflist); |
139 |
< |
if (!*newfile) |
140 |
< |
break; |
141 |
< |
pflist = sskip(pflist); |
154 |
> |
while ((pflist = nextword(newfile, sizeof(newfile), pflist)) != NULL) { |
155 |
|
FORALLPORT(newportlist,i) |
156 |
|
if (!strcmp(newportlist[i], newfile)) |
157 |
|
goto endloop; /* in list already */ |
181 |
|
FORALLPORT(newportlist, n); |
182 |
|
if (!n) { /* free old GL list */ |
183 |
|
if (gmPortals) |
184 |
< |
glDeleteLists(gmPortals, 1); |
184 |
> |
glDeleteLists(gmPortals, Nlists); |
185 |
|
gmPortals = 0; |
186 |
|
} else |
187 |
|
qsort(newportlist, n, sizeof(char *), sstrcmp); |
194 |
|
FORALLPORT(newportlist, n); |
195 |
|
dolights = 0; |
196 |
|
domats = 0; |
197 |
< |
gmPortals = rgl_filelist(n, newportlist); |
197 |
> |
gmPortals = rgl_filelist(n, newportlist, &Nlists); |
198 |
|
break; |
199 |
|
} |
200 |
|
FORALLPORT(curportlist, n) /* free old file list */ |