3 transvert_t *transvert;
4 transpoly_t *transpoly;
5 unsigned short *transpolyindex;
11 unsigned short currenttranspoly;
12 unsigned short currenttransvert;
13 unsigned short currentwallpoly;
14 unsigned short currentwallvert;
15 unsigned short currentskypoly;
16 unsigned short currentskyvert;
18 cvar_t gl_multitexture = {"gl_multitexture", "1"};
19 cvar_t gl_vertexarrays = {"gl_vertexarrays", "1"};
21 typedef struct translistitem_s
24 struct translistitem_s *next;
28 translistitem translist[MAX_TRANSPOLYS];
29 translistitem *currenttranslist;
31 translistitem *translisthash[4096];
33 float transviewdist; // distance of view origin along the view normal
35 float transreciptable[256];
40 Cvar_RegisterVariable (&gl_multitexture);
41 Cvar_RegisterVariable (&gl_vertexarrays);
42 transvert = malloc(MAX_TRANSVERTS * sizeof(transvert_t));
43 transpoly = malloc(MAX_TRANSPOLYS * sizeof(transpoly_t));
44 transpolyindex = malloc(MAX_TRANSPOLYS * sizeof(unsigned short));
45 wallvert = malloc(MAX_WALLVERTS * sizeof(wallvert_t));
46 wallpoly = malloc(MAX_WALLPOLYS * sizeof(wallpoly_t));
47 skyvert = malloc(MAX_SKYVERTS * sizeof(skyvert_t));
48 skypoly = malloc(MAX_SKYPOLYS * sizeof(skypoly_t));
49 transreciptable[0] = 0.0f;
50 for (i = 1;i < 256;i++)
51 transreciptable[i] = 1.0f / i;
56 currenttranspoly = currenttransvert = 0;
57 currenttranslist = translist;
58 memset(translisthash, 0, sizeof(translisthash));
59 transviewdist = DotProduct(r_refdef.vieworg, vpn);
62 // turned into a #define
64 void transpolybegin(int texnum, int glowtexnum, int fogtexnum, int transpolytype)
66 if (currenttranspoly >= MAX_TRANSPOLYS || currenttransvert >= MAX_TRANSVERTS)
68 transpoly[currenttranspoly].texnum = (unsigned short) texnum;
69 transpoly[currenttranspoly].glowtexnum = (unsigned short) glowtexnum;
70 transpoly[currenttranspoly].fogtexnum = (unsigned short) fogtexnum;
71 transpoly[currenttranspoly].transpolytype = (unsigned short) transpolytype;
72 transpoly[currenttranspoly].firstvert = currenttransvert;
73 transpoly[currenttranspoly].verts = 0;
74 // transpoly[currenttranspoly].ndist = 0; // clear the normal
78 // turned into a #define
80 void transpolyvert(float x, float y, float z, float s, float t, int r, int g, int b, int a)
83 if (currenttranspoly >= MAX_TRANSPOLYS || currenttransvert >= MAX_TRANSVERTS)
85 transvert[currenttransvert].s = s;
86 transvert[currenttransvert].t = t;
87 transvert[currenttransvert].r = bound(0, r, 255);
88 transvert[currenttransvert].g = bound(0, g, 255);
89 transvert[currenttransvert].b = bound(0, b, 255);
90 transvert[currenttransvert].a = bound(0, a, 255);
91 transvert[currenttransvert].v[0] = x;
92 transvert[currenttransvert].v[1] = y;
93 transvert[currenttransvert].v[2] = z;
95 transpoly[currenttranspoly].verts++;
101 float center, d, maxdist;
104 if (currenttranspoly >= MAX_TRANSPOLYS || currenttransvert >= MAX_TRANSVERTS)
106 if (transpoly[currenttranspoly].verts < 3) // skip invalid polygons
108 currenttransvert = transpoly[currenttranspoly].firstvert; // reset vert pointer
112 maxdist = -1000000000000000.0f; // eh, it's definitely behind it, so...
113 for (i = 0,v = &transvert[transpoly[currenttranspoly].firstvert];i < transpoly[currenttranspoly].verts;i++, v++)
115 d = DotProduct(v->v, vpn);
120 maxdist -= transviewdist;
121 if (maxdist < 4.0f) // behind view
123 currenttransvert = transpoly[currenttranspoly].firstvert; // reset vert pointer
126 center *= transreciptable[transpoly[currenttranspoly].verts];
127 center -= transviewdist;
128 i = bound(0, (int) center, 4095);
129 currenttranslist->next = translisthash[i];
130 currenttranslist->poly = transpoly + currenttranspoly;
131 translisthash[i] = currenttranslist;
136 int transpolyindices;
137 extern qboolean isG200;
140 void transpolyrenderminmax()
142 int i, j, k, lastvert;
143 vec_t d, min, max, viewdist, s, average;
146 transpolyindices = 0;
147 viewdist = DotProduct(r_refdef.vieworg, vpn);
148 for (i = 0;i < currenttranspoly;i++)
150 if (transpoly[i].verts < 3) // only process valid polygons
152 min = 1000000;max = -1000000;
153 s = 1.0f / transpoly[i].verts;
154 lastvert = transpoly[i].firstvert + transpoly[i].verts;
156 for (j = transpoly[i].firstvert;j < lastvert;j++)
158 d = DotProduct(transvert[j].v, vpn)-viewdist;
159 if (d < min) min = d;
160 if (d > max) max = d;
163 if (max < 4) // free to check here, so skip polys behind the view
165 transpoly[i].distance = average;
168 transpoly[i].mindistance = min;
169 transpoly[i].maxdistance = max;
170 // calculate normal (eek)
171 VectorSubtract(transvert[transpoly[i].firstvert ].v, transvert[transpoly[i].firstvert+1].v, v1);
172 VectorSubtract(transvert[transpoly[i].firstvert+2].v, transvert[transpoly[i].firstvert+1].v, v2);
175 if (transpoly[i].verts > 3 && fabs(DotProduct(v1, v2)) >= (1.0f - (1.0f / 256.0f))) // colinear edges, find a better triple
177 VectorSubtract(transvert[transpoly[i].firstvert + transpoly[i].verts - 1].v, transvert[transpoly[i].firstvert].v, v1);
178 VectorSubtract(transvert[transpoly[i].firstvert + 1].v, transvert[transpoly[i].firstvert].v, v2);
181 if (fabs(DotProduct(v1, v2)) < (1.0f - (1.0f / 256.0f))) // found a good triple
183 for (k = transpoly[i].firstvert + 2;k < (transpoly[i].firstvert + transpoly[i].verts - 1);k++)
185 VectorSubtract(transvert[k-1].v, transvert[k].v, v1);
186 VectorSubtract(transvert[k+1].v, transvert[k].v, v2);
189 if (fabs(DotProduct(v1, v2)) < (1.0f - (1.0f / 256.0f))) // found a good triple
192 VectorSubtract(transvert[k-1].v, transvert[k].v, v1);
193 VectorSubtract(transvert[transpoly[i].firstvert].v, transvert[k].v, v2);
196 if (fabs(DotProduct(v1, v2)) >= (1.0f - (1.0f / 256.0f))) // no good triples; the polygon is a line, skip it
200 CrossProduct(v1, v2, n);
202 ndist = DotProduct(transvert[transpoly[i].firstvert+1].v, n);
204 for (j = 0;j < transpolyindices;j++)
207 if (transpoly[transpolyindex[j]].mindistance > max)
209 if (transpoly[transpolyindex[j]].maxdistance < min)
211 // hard case, check side
212 for (k = transpoly[transpolyindex[j]].firstvert;k < (transpoly[transpolyindex[j]].firstvert + transpoly[transpolyindex[j]].verts);k++)
213 if (DotProduct(transvert[k].v, n) < ndist)
222 for (j = 0;j < transpolyindices;j++)
223 if (transpoly[transpolyindex[j]].distance < average)
225 for (k = transpolyindices;k > j;k--)
226 transpolyindex[k] = transpolyindex[k-1];
228 transpolyindex[j] = i;
233 // LordHavoc: qsort compare function
234 int transpolyqsort(const void *ia, const void *ib)
238 a = &transpoly[*((unsigned short *)ia)];
239 b = &transpoly[*((unsigned short *)ib)];
241 if (a->mindistance > b->mindistance && a->maxdistance > b->maxdistance)
243 if (a->mindistance < b->mindistance && a->maxdistance < b->maxdistance)
248 // calculate normal (eek)
250 VectorSubtract(transvert[a->firstvert ].v, transvert[a->firstvert+1].v, v1);
251 VectorSubtract(transvert[a->firstvert+2].v, transvert[a->firstvert+1].v, v2);
252 CrossProduct(v1, v2, a->n);
253 VectorNormalize(a->n);
254 a->ndist = DotProduct(transvert[a->firstvert ].v, a->n);
257 for (i = b->firstvert, j = 0;i < (b->firstvert + b->verts);i++)
258 j += DotProduct(transvert[i].v, a->n) < a->ndist; // (1) b is infront of a
260 return -1; // (-1) a is behind b
261 return j == b->verts; // (1) a is infront of b (0) a and b intersect
262 // return (transpoly[*((unsigned short *)ib)].mindistance + transpoly[*((unsigned short *)ib)].maxdistance) - (transpoly[*((unsigned short *)ia)].mindistance + transpoly[*((unsigned short *)ia)].maxdistance);
265 return ((transpoly_t*)ia)->distance - ((transpoly_t*)ib)->distance;
270 int transpolyqsort(const void *ia, const void *ib)
272 return (transpoly[*((unsigned short *)ib)].distance - transpoly[*((unsigned short *)ia)].distance);
277 void transpolyrenderminmax()
280 vec_t d, max, viewdist, average;
281 transpolyindices = 0;
282 viewdist = DotProduct(r_refdef.vieworg, vpn);
283 for (i = 0;i < currenttranspoly;i++)
285 if (transpoly[i].verts < 3) // only process valid polygons
288 lastvert = transpoly[i].firstvert + transpoly[i].verts;
290 for (j = transpoly[i].firstvert;j < lastvert;j++)
292 d = DotProduct(transvert[j].v, vpn)-viewdist;
297 if (max < 4) // free to check here, so skip polys behind the view
299 transpoly[i].distance = average / transpoly[i].verts;
300 transpolyindex[transpolyindices++] = i;
302 qsort(&transpolyindex[0], transpolyindices, sizeof(unsigned short), transpolyqsort);
311 for (i = 1;i < transpolyindices;i++)
314 if (transpoly[transpolyindex[i - 1]].mindistance > transpoly[transpolyindex[i]].mindistance && transpoly[transpolyindex[i - 1]].maxdistance > transpoly[transpolyindex[i]].maxdistance)
315 continue; // previous is behind (no swap)
316 if (transpoly[transpolyindex[i - 1]].mindistance < transpoly[transpolyindex[i]].mindistance && transpoly[transpolyindex[i - 1]].maxdistance < transpoly[transpolyindex[i]].maxdistance)
317 goto swap; // previous is infront (swap)
321 if (!transpoly[transpolyindex[i - 1]].ndist)
323 // calculate normal (eek)
325 VectorSubtract(transvert[transpoly[transpolyindex[i - 1]].firstvert ].v, transvert[transpoly[transpolyindex[i - 1]].firstvert+1].v, v1);
326 VectorSubtract(transvert[transpoly[transpolyindex[i - 1]].firstvert+2].v, transvert[transpoly[transpolyindex[i - 1]].firstvert+1].v, v2);
327 CrossProduct(v1, v2, transpoly[transpolyindex[i - 1]].n);
328 VectorNormalize(transpoly[transpolyindex[i - 1]].n);
329 transpoly[transpolyindex[i - 1]].ndist = DotProduct(transvert[transpoly[transpolyindex[i - 1]].firstvert ].v, transpoly[transpolyindex[i - 1]].n);
331 if (DotProduct(transpoly[transpolyindex[i - 1]].n, vpn) >= 0.0f) // backface
336 for (i = transpoly[transpolyindex[i]].firstvert;i < (transpoly[transpolyindex[i]].firstvert + transpoly[transpolyindex[i]].verts);i++)
337 if (DotProduct(transvert[i].v, transpoly[transpolyindex[i - 1]].n) >= transpoly[transpolyindex[i - 1]].ndist)
338 goto noswap; // previous is behind or they intersect
340 // previous is infront (swap)
341 j = transpolyindex[i];
342 transpolyindex[i] = transpolyindex[i - 1];
343 transpolyindex[i - 1] = j;
352 void transpolyrender()
354 int i, j, tpolytype, texnum;
356 if (currenttranspoly < 1)
358 // transpolyrenderminmax();
359 // if (transpolyindices < 1)
362 // Con_DPrintf("transpolyrender: %i polys %i infront %i vertices\n", currenttranspoly, transpolyindices, currenttransvert);
363 // if (transpolyindices >= 2)
365 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
367 glShadeModel(GL_SMOOTH);
368 glDepthMask(0); // disable zbuffer updates
369 if (isG200) // Matrox G200 cards can't handle per pixel alpha
370 glEnable(GL_ALPHA_TEST);
372 glDisable(GL_ALPHA_TEST);
373 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
374 tpolytype = TPOLYTYPE_ALPHA;
377 if (gl_vertexarrays.value)
379 // set up the vertex array
380 qglInterleavedArrays(GL_T2F_C4UB_V3F, 0, transvert);
381 for (i = 0;i < transpolyindices;i++)
383 p = &transpoly[transpolyindex[i]];
384 if (p->texnum != texnum || p->transpolytype != tpolytype)
386 if (p->texnum != texnum)
389 glBindTexture(GL_TEXTURE_2D, texnum);
391 if (p->transpolytype != tpolytype)
393 tpolytype = p->transpolytype;
394 if (tpolytype == TPOLYTYPE_ADD) // additive
395 glBlendFunc(GL_SRC_ALPHA, GL_ONE);
397 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
400 qglDrawArrays(GL_TRIANGLE_FAN, p->firstvert, p->verts);
403 texnum = p->glowtexnum; // highly unlikely to match next poly, but...
404 glBindTexture(GL_TEXTURE_2D, texnum);
405 tpolytype = TPOLYTYPE_ADD; // might match next poly
406 glBlendFunc(GL_SRC_ALPHA, GL_ONE);
407 qglDrawArrays(GL_TRIANGLE_FAN, p->firstvert, p->verts);
410 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
411 glDisableClientState(GL_COLOR_ARRAY);
412 glDisableClientState(GL_VERTEX_ARRAY);
420 for (i = 4095;i >= 0;i--)
422 item = translisthash[i];
427 if (p->texnum != texnum || p->verts != points || p->transpolytype != tpolytype)
432 if (p->fogtexnum) // alpha
433 glEnable(GL_ALPHA_TEST);
435 glDisable(GL_ALPHA_TEST);
437 if (p->texnum != texnum)
440 glBindTexture(GL_TEXTURE_2D, texnum);
442 if (p->transpolytype != tpolytype)
444 tpolytype = p->transpolytype;
445 if (tpolytype == TPOLYTYPE_ADD) // additive
446 glBlendFunc(GL_SRC_ALPHA, GL_ONE);
448 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
454 glBegin(GL_TRIANGLES);
460 glBegin(GL_TRIANGLE_FAN);
461 points = -1; // to force a reinit on the next poly
465 for (j = 0,vert = &transvert[p->firstvert];j < p->verts;j++, vert++)
467 // would be 2fv, but windoze Matrox G200 and probably G400 drivers don't support that (dumb...)
468 glTexCoord2f(vert->s, vert->t);
469 // again, vector version isn't supported I think
470 glColor4ub(vert->r, vert->g, vert->b, vert->a);
471 glVertex3fv(vert->v);
476 texnum = p->glowtexnum; // highly unlikely to match next poly, but...
477 glBindTexture(GL_TEXTURE_2D, texnum);
478 if (tpolytype != TPOLYTYPE_ADD)
480 tpolytype = TPOLYTYPE_ADD; // might match next poly
481 glBlendFunc(GL_SRC_ALPHA, GL_ONE);
484 glBegin(GL_TRIANGLE_FAN);
485 for (j = 0,vert = &transvert[p->firstvert];j < p->verts;j++, vert++)
487 glColor4ub(255,255,255,vert->a);
488 // would be 2fv, but windoze Matrox G200 and probably G400 drivers don't support that (dumb...)
489 glTexCoord2f(vert->s, vert->t);
490 glVertex3fv(vert->v);
494 if (fogenabled && p->transpolytype == TPOLYTYPE_ALPHA)
498 points = -1; // to force a reinit on the next poly
499 if (tpolytype != TPOLYTYPE_ALPHA)
501 tpolytype = TPOLYTYPE_ALPHA; // probably matchs next poly
502 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
506 if (texnum != p->fogtexnum) // highly unlikely to match next poly, but...
508 texnum = p->fogtexnum;
509 glBindTexture(GL_TEXTURE_2D, texnum);
511 glBegin(GL_TRIANGLE_FAN);
512 for (j = 0,vert = &transvert[p->firstvert];j < p->verts;j++, vert++)
514 VectorSubtract(vert->v, r_refdef.vieworg,diff);
515 glTexCoord2f(vert->s, vert->t);
516 glColor4f(fogcolor[0], fogcolor[1], fogcolor[2], vert->a*(1.0f/255.0f)*exp(fogdensity/DotProduct(diff,diff)));
517 glVertex3fv(vert->v);
523 glDisable(GL_TEXTURE_2D);
524 glBegin(GL_TRIANGLE_FAN);
525 for (j = 0,vert = &transvert[p->firstvert];j < p->verts;j++, vert++)
527 VectorSubtract(vert->v, r_refdef.vieworg,diff);
528 glColor4f(fogcolor[0], fogcolor[1], fogcolor[2], vert->a*(1.0f/255.0f)*exp(fogdensity/DotProduct(diff,diff)));
529 glVertex3fv(vert->v);
532 glEnable(GL_TEXTURE_2D);
540 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
541 glDepthMask(1); // enable zbuffer updates
542 glDisable(GL_ALPHA_TEST);
545 extern qboolean isG200;
549 currentwallpoly = currentwallvert = 0;
552 extern qboolean lighthalf;
553 void wallpolyrender()
555 int i, j, texnum, lighttexnum;
558 if (currentwallpoly < 1)
560 c_brush_polys += currentwallpoly;
562 //Con_DPrintf("wallpolyrender: %i polys %i vertices\n", currentwallpoly, currentwallvert);
564 gl_multitexture.value = 0;
566 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
567 glShadeModel(GL_FLAT);
568 // make sure zbuffer is enabled
569 glEnable(GL_DEPTH_TEST);
570 glDisable(GL_ALPHA_TEST);
573 if (r_fullbright.value) // LordHavoc: easy to do fullbright...
575 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
577 for (i = 0,p = wallpoly;i < currentwallpoly;i++, p++)
579 if (p->texnum != texnum)
582 glBindTexture(GL_TEXTURE_2D, texnum);
584 vert = &wallvert[p->firstvert];
586 for (j=0 ; j<p->numverts ; j++, vert++)
588 glTexCoord2f (vert->s, vert->t);
589 glVertex3fv (vert->vert);
594 else if (gl_multitexture.value)
596 qglSelectTexture(gl_mtex_enum+0);
597 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
598 glEnable(GL_TEXTURE_2D);
599 qglSelectTexture(gl_mtex_enum+1);
600 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
601 glEnable(GL_TEXTURE_2D);
604 for (i = 0,p = wallpoly;i < currentwallpoly;i++, p++)
606 if (p->texnum != texnum || p->lighttexnum != lighttexnum)
609 lighttexnum = p->lighttexnum;
610 qglSelectTexture(gl_mtex_enum+0);
611 glBindTexture(GL_TEXTURE_2D, texnum);
612 qglSelectTexture(gl_mtex_enum+1);
613 glBindTexture(GL_TEXTURE_2D, lighttexnum);
615 vert = &wallvert[p->firstvert];
617 for (j=0 ; j<p->numverts ; j++, vert++)
619 qglMTexCoord2f(gl_mtex_enum, vert->s, vert->t); // texture
620 qglMTexCoord2f((gl_mtex_enum+1), vert->u, vert->v); // lightmap
621 glVertex3fv (vert->vert);
626 qglSelectTexture(gl_mtex_enum+1);
627 glDisable(GL_TEXTURE_2D);
628 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
629 qglSelectTexture(gl_mtex_enum+0);
630 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
634 // first do the textures
635 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
637 for (i = 0,p = wallpoly;i < currentwallpoly;i++, p++)
639 if (p->texnum != texnum)
642 glBindTexture(GL_TEXTURE_2D, texnum);
644 vert = &wallvert[p->firstvert];
646 for (j=0 ; j<p->numverts ; j++, vert++)
648 glTexCoord2f (vert->s, vert->t);
649 glVertex3fv (vert->vert);
653 // then modulate using the lightmaps
654 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
655 glBlendFunc(GL_ZERO, GL_SRC_COLOR);
658 for (i = 0,p = wallpoly;i < currentwallpoly;i++, p++)
660 if (p->lighttexnum != texnum)
662 texnum = p->lighttexnum;
663 glBindTexture(GL_TEXTURE_2D, texnum);
665 vert = &wallvert[p->firstvert];
667 for (j=0 ; j<p->numverts ; j++, vert++)
669 glTexCoord2f (vert->u, vert->v);
670 glVertex3fv (vert->vert);
675 // switch to additive mode settings
677 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
678 glBlendFunc(GL_SRC_ALPHA, GL_ONE);
680 glDisable(GL_ALPHA_TEST);
681 glShadeModel(GL_SMOOTH);
682 // render vertex lit overlays ontop
684 for (i = 0, p = wallpoly;i < currentwallpoly;i++, p++)
688 for (j = 0,vert = &wallvert[p->firstvert];j < p->numverts;j++, vert++)
689 if (vert->r || vert->g || vert->b)
694 if (p->texnum != texnum)
697 glBindTexture(GL_TEXTURE_2D, texnum);
700 for (j = 0,vert = &wallvert[p->firstvert];j < p->numverts;j++, vert++)
702 // would be 2fv, but windoze Matrox G200 and probably G400 drivers don't support that (dumb...)
703 glTexCoord2f(vert->s, vert->t);
704 // again, vector version isn't supported I think
705 glColor3ub(vert->r, vert->g, vert->b);
706 glVertex3fv(vert->vert);
710 // render glow textures
711 glShadeModel(GL_FLAT);
712 glBlendFunc(GL_ONE, GL_ONE);
714 glColor3f(0.5,0.5,0.5);
718 for (i = 0,p = wallpoly;i < currentwallpoly;i++, p++)
722 if (p->glowtexnum != texnum)
724 texnum = p->glowtexnum;
725 glBindTexture(GL_TEXTURE_2D, texnum);
727 vert = &wallvert[p->firstvert];
729 for (j=0 ; j<p->numverts ; j++, vert++)
731 glTexCoord2f (vert->s, vert->t);
732 glVertex3fv (vert->vert);
737 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
738 glShadeModel(GL_SMOOTH);
742 glDisable(GL_TEXTURE_2D);
743 for (i = 0,p = &wallpoly[0];i < currentwallpoly;i++, p++)
745 vert = &wallvert[p->firstvert];
747 for (j=0 ; j<p->numverts ; j++, vert++)
749 VectorSubtract(vert->vert, r_refdef.vieworg,diff);
750 glColor4f(fogcolor[0], fogcolor[1], fogcolor[2], exp(fogdensity/DotProduct(diff,diff)));
751 glVertex3fv (vert->vert);
755 glEnable(GL_TEXTURE_2D);
757 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
758 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
759 glDisable(GL_ALPHA_TEST);
760 glShadeModel(GL_SMOOTH);
767 currentskypoly = currentskyvert = 0;
770 extern qboolean isATI;
772 extern char skyname[];
773 extern int solidskytexture, alphaskytexture;
779 float length, speedscale;
781 if (currentskypoly < 1)
784 // Con_DPrintf("skypolyrender: %i polys %i vertices\n", currentskypoly, currentskyvert);
785 glDisable(GL_ALPHA_TEST);
787 // make sure zbuffer is enabled
788 glEnable(GL_DEPTH_TEST);
790 if (!fogenabled && !skyname[0]) // normal quake sky
792 glColor3f(0.5f, 0.5f, 0.5f);
793 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
794 glEnable(GL_TEXTURE_2D);
796 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
797 glBindTexture(GL_TEXTURE_2D, solidskytexture); // upper clouds
798 speedscale = realtime*8;
799 speedscale -= (int)speedscale & ~127 ;
800 for (i = 0,p = &skypoly[0];i < currentskypoly;i++, p++)
802 vert = &skyvert[p->firstvert];
804 for (j=0 ; j<p->verts ; j++, vert++)
806 VectorSubtract (vert->v, r_origin, dir);
807 dir[2] *= 3; // flatten the sphere
809 length = dir[0]*dir[0] + dir[1]*dir[1] + dir[2]*dir[2];
810 length = sqrt (length);
811 length = 6*63/length;
813 glTexCoord2f ((speedscale + dir[0] * length) * (1.0/128), (speedscale + dir[1] * length) * (1.0/128));
814 glVertex3fv (vert->v);
820 glBindTexture(GL_TEXTURE_2D, alphaskytexture); // lower clouds
821 speedscale = realtime*16;
822 speedscale -= (int)speedscale & ~127 ;
823 for (i = 0,p = &skypoly[0];i < currentskypoly;i++, p++)
825 vert = &skyvert[p->firstvert];
827 for (j=0 ; j<p->verts ; j++, vert++)
829 VectorSubtract (vert->v, r_origin, dir);
830 dir[2] *= 3; // flatten the sphere
832 length = dir[0]*dir[0] + dir[1]*dir[1] + dir[2]*dir[2];
833 length = sqrt (length);
834 length = 6*63/length;
836 glTexCoord2f ((speedscale + dir[0] * length) * (1.0/128), (speedscale + dir[1] * length) * (1.0/128));
837 glVertex3fv (vert->v);
847 glDisable(GL_TEXTURE_2D);
848 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
849 glColor3fv(fogcolor); // note: gets rendered over by skybox if fog is not enabled
850 for (i = 0,p = &skypoly[0];i < currentskypoly;i++, p++)
852 vert = &skyvert[p->firstvert];
854 for (j=0 ; j<p->verts ; j++, vert++)
855 glVertex3fv (vert->v);
859 glEnable(GL_TEXTURE_2D);