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 transvert = malloc(MAX_TRANSVERTS * sizeof(transvert_t));
41 transpoly = malloc(MAX_TRANSPOLYS * sizeof(transpoly_t));
42 transpolyindex = malloc(MAX_TRANSPOLYS * sizeof(unsigned short));
43 wallvert = malloc(MAX_WALLVERTS * sizeof(wallvert_t));
44 wallpoly = malloc(MAX_WALLPOLYS * sizeof(wallpoly_t));
45 skyvert = malloc(MAX_SKYVERTS * sizeof(skyvert_t));
46 skypoly = malloc(MAX_SKYPOLYS * sizeof(skypoly_t));
47 transreciptable[0] = 0.0f;
48 for (i = 1;i < 256;i++)
49 transreciptable[i] = 1.0f / i;
51 void gl_poly_shutdown()
64 Cvar_RegisterVariable (&gl_multitexture);
65 Cvar_RegisterVariable (&gl_vertexarrays);
66 R_RegisterModule("GL_Poly", gl_poly_start, gl_poly_shutdown);
71 currenttranspoly = currenttransvert = 0;
72 currenttranslist = translist;
73 memset(translisthash, 0, sizeof(translisthash));
74 transviewdist = DotProduct(r_refdef.vieworg, vpn);
77 // turned into a #define
79 void transpolybegin(int texnum, int glowtexnum, int fogtexnum, int transpolytype)
81 if (currenttranspoly >= MAX_TRANSPOLYS || currenttransvert >= MAX_TRANSVERTS)
83 transpoly[currenttranspoly].texnum = (unsigned short) texnum;
84 transpoly[currenttranspoly].glowtexnum = (unsigned short) glowtexnum;
85 transpoly[currenttranspoly].fogtexnum = (unsigned short) fogtexnum;
86 transpoly[currenttranspoly].transpolytype = (unsigned short) transpolytype;
87 transpoly[currenttranspoly].firstvert = currenttransvert;
88 transpoly[currenttranspoly].verts = 0;
89 // transpoly[currenttranspoly].ndist = 0; // clear the normal
93 // turned into a #define
95 void transpolyvert(float x, float y, float z, float s, float t, int r, int g, int b, int a)
98 if (currenttranspoly >= MAX_TRANSPOLYS || currenttransvert >= MAX_TRANSVERTS)
100 transvert[currenttransvert].s = s;
101 transvert[currenttransvert].t = t;
102 transvert[currenttransvert].r = bound(0, r, 255);
103 transvert[currenttransvert].g = bound(0, g, 255);
104 transvert[currenttransvert].b = bound(0, b, 255);
105 transvert[currenttransvert].a = bound(0, a, 255);
106 transvert[currenttransvert].v[0] = x;
107 transvert[currenttransvert].v[1] = y;
108 transvert[currenttransvert].v[2] = z;
110 transpoly[currenttranspoly].verts++;
116 float center, d, maxdist;
119 if (currenttranspoly >= MAX_TRANSPOLYS || currenttransvert >= MAX_TRANSVERTS)
121 if (transpoly[currenttranspoly].verts < 3) // skip invalid polygons
123 currenttransvert = transpoly[currenttranspoly].firstvert; // reset vert pointer
127 maxdist = -1000000000000000.0f; // eh, it's definitely behind it, so...
128 for (i = 0,v = &transvert[transpoly[currenttranspoly].firstvert];i < transpoly[currenttranspoly].verts;i++, v++)
130 d = DotProduct(v->v, vpn);
135 maxdist -= transviewdist;
136 if (maxdist < 4.0f) // behind view
138 currenttransvert = transpoly[currenttranspoly].firstvert; // reset vert pointer
141 center *= transreciptable[transpoly[currenttranspoly].verts];
142 center -= transviewdist;
143 i = bound(0, (int) center, 4095);
144 currenttranslist->next = translisthash[i];
145 currenttranslist->poly = transpoly + currenttranspoly;
146 translisthash[i] = currenttranslist;
151 int transpolyindices;
152 extern qboolean isG200;
155 void transpolyrenderminmax()
157 int i, j, k, lastvert;
158 vec_t d, min, max, viewdist, s, average;
161 transpolyindices = 0;
162 viewdist = DotProduct(r_refdef.vieworg, vpn);
163 for (i = 0;i < currenttranspoly;i++)
165 if (transpoly[i].verts < 3) // only process valid polygons
167 min = 1000000;max = -1000000;
168 s = 1.0f / transpoly[i].verts;
169 lastvert = transpoly[i].firstvert + transpoly[i].verts;
171 for (j = transpoly[i].firstvert;j < lastvert;j++)
173 d = DotProduct(transvert[j].v, vpn)-viewdist;
174 if (d < min) min = d;
175 if (d > max) max = d;
178 if (max < 4) // free to check here, so skip polys behind the view
180 transpoly[i].distance = average;
183 transpoly[i].mindistance = min;
184 transpoly[i].maxdistance = max;
185 // calculate normal (eek)
186 VectorSubtract(transvert[transpoly[i].firstvert ].v, transvert[transpoly[i].firstvert+1].v, v1);
187 VectorSubtract(transvert[transpoly[i].firstvert+2].v, transvert[transpoly[i].firstvert+1].v, v2);
190 if (transpoly[i].verts > 3 && fabs(DotProduct(v1, v2)) >= (1.0f - (1.0f / 256.0f))) // colinear edges, find a better triple
192 VectorSubtract(transvert[transpoly[i].firstvert + transpoly[i].verts - 1].v, transvert[transpoly[i].firstvert].v, v1);
193 VectorSubtract(transvert[transpoly[i].firstvert + 1].v, transvert[transpoly[i].firstvert].v, v2);
196 if (fabs(DotProduct(v1, v2)) < (1.0f - (1.0f / 256.0f))) // found a good triple
198 for (k = transpoly[i].firstvert + 2;k < (transpoly[i].firstvert + transpoly[i].verts - 1);k++)
200 VectorSubtract(transvert[k-1].v, transvert[k].v, v1);
201 VectorSubtract(transvert[k+1].v, transvert[k].v, v2);
204 if (fabs(DotProduct(v1, v2)) < (1.0f - (1.0f / 256.0f))) // found a good triple
207 VectorSubtract(transvert[k-1].v, transvert[k].v, v1);
208 VectorSubtract(transvert[transpoly[i].firstvert].v, transvert[k].v, v2);
211 if (fabs(DotProduct(v1, v2)) >= (1.0f - (1.0f / 256.0f))) // no good triples; the polygon is a line, skip it
215 CrossProduct(v1, v2, n);
217 ndist = DotProduct(transvert[transpoly[i].firstvert+1].v, n);
219 for (j = 0;j < transpolyindices;j++)
222 if (transpoly[transpolyindex[j]].mindistance > max)
224 if (transpoly[transpolyindex[j]].maxdistance < min)
226 // hard case, check side
227 for (k = transpoly[transpolyindex[j]].firstvert;k < (transpoly[transpolyindex[j]].firstvert + transpoly[transpolyindex[j]].verts);k++)
228 if (DotProduct(transvert[k].v, n) < ndist)
237 for (j = 0;j < transpolyindices;j++)
238 if (transpoly[transpolyindex[j]].distance < average)
240 for (k = transpolyindices;k > j;k--)
241 transpolyindex[k] = transpolyindex[k-1];
243 transpolyindex[j] = i;
248 // LordHavoc: qsort compare function
249 int transpolyqsort(const void *ia, const void *ib)
253 a = &transpoly[*((unsigned short *)ia)];
254 b = &transpoly[*((unsigned short *)ib)];
256 if (a->mindistance > b->mindistance && a->maxdistance > b->maxdistance)
258 if (a->mindistance < b->mindistance && a->maxdistance < b->maxdistance)
263 // calculate normal (eek)
265 VectorSubtract(transvert[a->firstvert ].v, transvert[a->firstvert+1].v, v1);
266 VectorSubtract(transvert[a->firstvert+2].v, transvert[a->firstvert+1].v, v2);
267 CrossProduct(v1, v2, a->n);
268 VectorNormalize(a->n);
269 a->ndist = DotProduct(transvert[a->firstvert ].v, a->n);
272 for (i = b->firstvert, j = 0;i < (b->firstvert + b->verts);i++)
273 j += DotProduct(transvert[i].v, a->n) < a->ndist; // (1) b is infront of a
275 return -1; // (-1) a is behind b
276 return j == b->verts; // (1) a is infront of b (0) a and b intersect
277 // return (transpoly[*((unsigned short *)ib)].mindistance + transpoly[*((unsigned short *)ib)].maxdistance) - (transpoly[*((unsigned short *)ia)].mindistance + transpoly[*((unsigned short *)ia)].maxdistance);
280 return ((transpoly_t*)ia)->distance - ((transpoly_t*)ib)->distance;
285 int transpolyqsort(const void *ia, const void *ib)
287 return (transpoly[*((unsigned short *)ib)].distance - transpoly[*((unsigned short *)ia)].distance);
292 void transpolyrenderminmax()
295 vec_t d, max, viewdist, average;
296 transpolyindices = 0;
297 viewdist = DotProduct(r_refdef.vieworg, vpn);
298 for (i = 0;i < currenttranspoly;i++)
300 if (transpoly[i].verts < 3) // only process valid polygons
303 lastvert = transpoly[i].firstvert + transpoly[i].verts;
305 for (j = transpoly[i].firstvert;j < lastvert;j++)
307 d = DotProduct(transvert[j].v, vpn)-viewdist;
312 if (max < 4) // free to check here, so skip polys behind the view
314 transpoly[i].distance = average / transpoly[i].verts;
315 transpolyindex[transpolyindices++] = i;
317 qsort(&transpolyindex[0], transpolyindices, sizeof(unsigned short), transpolyqsort);
326 for (i = 1;i < transpolyindices;i++)
329 if (transpoly[transpolyindex[i - 1]].mindistance > transpoly[transpolyindex[i]].mindistance && transpoly[transpolyindex[i - 1]].maxdistance > transpoly[transpolyindex[i]].maxdistance)
330 continue; // previous is behind (no swap)
331 if (transpoly[transpolyindex[i - 1]].mindistance < transpoly[transpolyindex[i]].mindistance && transpoly[transpolyindex[i - 1]].maxdistance < transpoly[transpolyindex[i]].maxdistance)
332 goto swap; // previous is infront (swap)
336 if (!transpoly[transpolyindex[i - 1]].ndist)
338 // calculate normal (eek)
340 VectorSubtract(transvert[transpoly[transpolyindex[i - 1]].firstvert ].v, transvert[transpoly[transpolyindex[i - 1]].firstvert+1].v, v1);
341 VectorSubtract(transvert[transpoly[transpolyindex[i - 1]].firstvert+2].v, transvert[transpoly[transpolyindex[i - 1]].firstvert+1].v, v2);
342 CrossProduct(v1, v2, transpoly[transpolyindex[i - 1]].n);
343 VectorNormalize(transpoly[transpolyindex[i - 1]].n);
344 transpoly[transpolyindex[i - 1]].ndist = DotProduct(transvert[transpoly[transpolyindex[i - 1]].firstvert ].v, transpoly[transpolyindex[i - 1]].n);
346 if (DotProduct(transpoly[transpolyindex[i - 1]].n, vpn) >= 0.0f) // backface
351 for (i = transpoly[transpolyindex[i]].firstvert;i < (transpoly[transpolyindex[i]].firstvert + transpoly[transpolyindex[i]].verts);i++)
352 if (DotProduct(transvert[i].v, transpoly[transpolyindex[i - 1]].n) >= transpoly[transpolyindex[i - 1]].ndist)
353 goto noswap; // previous is behind or they intersect
355 // previous is infront (swap)
356 j = transpolyindex[i];
357 transpolyindex[i] = transpolyindex[i - 1];
358 transpolyindex[i - 1] = j;
367 void transpolyrender()
369 int i, j, tpolytype, texnum;
373 if (currenttranspoly < 1)
375 // transpolyrenderminmax();
376 // if (transpolyindices < 1)
379 // Con_DPrintf("transpolyrender: %i polys %i infront %i vertices\n", currenttranspoly, transpolyindices, currenttransvert);
380 // if (transpolyindices >= 2)
382 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
384 glShadeModel(GL_SMOOTH);
385 glDepthMask(0); // disable zbuffer updates
386 if (isG200) // Matrox G200 cards can't handle per pixel alpha
387 glEnable(GL_ALPHA_TEST);
389 glDisable(GL_ALPHA_TEST);
390 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
391 tpolytype = TPOLYTYPE_ALPHA;
394 if (gl_vertexarrays.value)
396 // set up the vertex array
397 qglInterleavedArrays(GL_T2F_C4UB_V3F, 0, transvert);
398 for (i = 0;i < transpolyindices;i++)
400 p = &transpoly[transpolyindex[i]];
401 if (p->texnum != texnum || p->transpolytype != tpolytype)
403 if (p->texnum != texnum)
406 glBindTexture(GL_TEXTURE_2D, texnum);
408 if (p->transpolytype != tpolytype)
410 tpolytype = p->transpolytype;
411 if (tpolytype == TPOLYTYPE_ADD) // additive
412 glBlendFunc(GL_SRC_ALPHA, GL_ONE);
414 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
417 qglDrawArrays(GL_TRIANGLE_FAN, p->firstvert, p->verts);
420 texnum = p->glowtexnum; // highly unlikely to match next poly, but...
421 glBindTexture(GL_TEXTURE_2D, texnum);
422 tpolytype = TPOLYTYPE_ADD; // might match next poly
423 glBlendFunc(GL_SRC_ALPHA, GL_ONE);
424 qglDrawArrays(GL_TRIANGLE_FAN, p->firstvert, p->verts);
427 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
428 glDisableClientState(GL_COLOR_ARRAY);
429 glDisableClientState(GL_VERTEX_ARRAY);
437 for (i = 4095;i >= 0;i--)
439 item = translisthash[i];
444 if (p->texnum != texnum || p->verts != points || p->transpolytype != tpolytype)
449 if (p->fogtexnum) // alpha
450 glEnable(GL_ALPHA_TEST);
452 glDisable(GL_ALPHA_TEST);
454 if (p->texnum != texnum)
457 glBindTexture(GL_TEXTURE_2D, texnum);
459 if (p->transpolytype != tpolytype)
461 tpolytype = p->transpolytype;
462 if (tpolytype == TPOLYTYPE_ADD) // additive
463 glBlendFunc(GL_SRC_ALPHA, GL_ONE);
465 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
471 glBegin(GL_TRIANGLES);
477 glBegin(GL_TRIANGLE_FAN);
478 points = -1; // to force a reinit on the next poly
482 for (j = 0,vert = &transvert[p->firstvert];j < p->verts;j++, vert++)
484 // would be 2fv, but windoze Matrox G200 and probably G400 drivers don't support that (dumb...)
485 glTexCoord2f(vert->s, vert->t);
486 // again, vector version isn't supported I think
487 glColor4ub(vert->r, vert->g, vert->b, vert->a);
488 glVertex3fv(vert->v);
493 texnum = p->glowtexnum; // highly unlikely to match next poly, but...
494 glBindTexture(GL_TEXTURE_2D, texnum);
495 if (tpolytype != TPOLYTYPE_ADD)
497 tpolytype = TPOLYTYPE_ADD; // might match next poly
498 glBlendFunc(GL_SRC_ALPHA, GL_ONE);
501 glBegin(GL_TRIANGLE_FAN);
502 for (j = 0,vert = &transvert[p->firstvert];j < p->verts;j++, vert++)
504 glColor4ub(255,255,255,vert->a);
505 // would be 2fv, but windoze Matrox G200 and probably G400 drivers don't support that (dumb...)
506 glTexCoord2f(vert->s, vert->t);
507 glVertex3fv(vert->v);
511 if (fogenabled && p->transpolytype == TPOLYTYPE_ALPHA)
515 points = -1; // to force a reinit on the next poly
516 if (tpolytype != TPOLYTYPE_ALPHA)
518 tpolytype = TPOLYTYPE_ALPHA; // probably matchs next poly
519 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
523 if (texnum != p->fogtexnum) // highly unlikely to match next poly, but...
525 texnum = p->fogtexnum;
526 glBindTexture(GL_TEXTURE_2D, texnum);
528 glBegin(GL_TRIANGLE_FAN);
529 for (j = 0,vert = &transvert[p->firstvert];j < p->verts;j++, vert++)
531 VectorSubtract(vert->v, r_refdef.vieworg,diff);
532 glTexCoord2f(vert->s, vert->t);
533 glColor4f(fogcolor[0], fogcolor[1], fogcolor[2], vert->a*(1.0f/255.0f)*exp(fogdensity/DotProduct(diff,diff)));
534 glVertex3fv(vert->v);
540 glDisable(GL_TEXTURE_2D);
541 glBegin(GL_TRIANGLE_FAN);
542 for (j = 0,vert = &transvert[p->firstvert];j < p->verts;j++, vert++)
544 VectorSubtract(vert->v, r_refdef.vieworg,diff);
545 glColor4f(fogcolor[0], fogcolor[1], fogcolor[2], vert->a*(1.0f/255.0f)*exp(fogdensity/DotProduct(diff,diff)));
546 glVertex3fv(vert->v);
549 glEnable(GL_TEXTURE_2D);
557 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
558 glDepthMask(1); // enable zbuffer updates
559 glDisable(GL_ALPHA_TEST);
562 extern qboolean isG200;
566 currentwallpoly = currentwallvert = 0;
569 extern qboolean lighthalf;
570 void wallpolyrender()
572 int i, j, texnum, lighttexnum;
577 if (currentwallpoly < 1)
579 c_brush_polys += currentwallpoly;
581 //Con_DPrintf("wallpolyrender: %i polys %i vertices\n", currentwallpoly, currentwallvert);
583 gl_multitexture.value = 0;
585 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
586 glShadeModel(GL_FLAT);
587 // make sure zbuffer is enabled
588 glEnable(GL_DEPTH_TEST);
589 glDisable(GL_ALPHA_TEST);
592 if (r_fullbright.value) // LordHavoc: easy to do fullbright...
594 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
596 for (i = 0,p = wallpoly;i < currentwallpoly;i++, p++)
598 if (p->texnum != texnum)
601 glBindTexture(GL_TEXTURE_2D, texnum);
603 vert = &wallvert[p->firstvert];
605 for (j=0 ; j<p->numverts ; j++, vert++)
607 glTexCoord2f (vert->s, vert->t);
608 glVertex3fv (vert->vert);
613 else if (gl_multitexture.value)
615 qglSelectTexture(gl_mtex_enum+0);
616 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
617 glEnable(GL_TEXTURE_2D);
618 qglSelectTexture(gl_mtex_enum+1);
619 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
620 glEnable(GL_TEXTURE_2D);
623 for (i = 0,p = wallpoly;i < currentwallpoly;i++, p++)
625 if (p->texnum != texnum || p->lighttexnum != lighttexnum)
628 lighttexnum = p->lighttexnum;
629 qglSelectTexture(gl_mtex_enum+0);
630 glBindTexture(GL_TEXTURE_2D, texnum);
631 qglSelectTexture(gl_mtex_enum+1);
632 glBindTexture(GL_TEXTURE_2D, lighttexnum);
634 vert = &wallvert[p->firstvert];
636 for (j=0 ; j<p->numverts ; j++, vert++)
638 qglMTexCoord2f(gl_mtex_enum, vert->s, vert->t); // texture
639 qglMTexCoord2f((gl_mtex_enum+1), vert->u, vert->v); // lightmap
640 glVertex3fv (vert->vert);
645 qglSelectTexture(gl_mtex_enum+1);
646 glDisable(GL_TEXTURE_2D);
647 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
648 qglSelectTexture(gl_mtex_enum+0);
649 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
653 // first do the textures
654 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
656 for (i = 0,p = wallpoly;i < currentwallpoly;i++, p++)
658 if (p->texnum != texnum)
661 glBindTexture(GL_TEXTURE_2D, texnum);
663 vert = &wallvert[p->firstvert];
665 for (j=0 ; j<p->numverts ; j++, vert++)
667 glTexCoord2f (vert->s, vert->t);
668 glVertex3fv (vert->vert);
672 // then modulate using the lightmaps
673 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
674 glBlendFunc(GL_ZERO, GL_SRC_COLOR);
677 for (i = 0,p = wallpoly;i < currentwallpoly;i++, p++)
679 if (p->lighttexnum != texnum)
681 texnum = p->lighttexnum;
682 glBindTexture(GL_TEXTURE_2D, texnum);
684 vert = &wallvert[p->firstvert];
686 for (j=0 ; j<p->numverts ; j++, vert++)
688 glTexCoord2f (vert->u, vert->v);
689 glVertex3fv (vert->vert);
694 // switch to additive mode settings
696 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
697 glBlendFunc(GL_SRC_ALPHA, GL_ONE);
699 glDisable(GL_ALPHA_TEST);
700 glShadeModel(GL_SMOOTH);
701 // render vertex lit overlays ontop
703 for (i = 0, p = wallpoly;i < currentwallpoly;i++, p++)
707 for (j = 0,vert = &wallvert[p->firstvert];j < p->numverts;j++, vert++)
708 if (vert->r || vert->g || vert->b)
713 if (p->texnum != texnum)
716 glBindTexture(GL_TEXTURE_2D, texnum);
719 for (j = 0,vert = &wallvert[p->firstvert];j < p->numverts;j++, vert++)
721 // would be 2fv, but windoze Matrox G200 and probably G400 drivers don't support that (dumb...)
722 glTexCoord2f(vert->s, vert->t);
723 // again, vector version isn't supported I think
724 glColor3ub(vert->r, vert->g, vert->b);
725 glVertex3fv(vert->vert);
729 // render glow textures
730 glShadeModel(GL_FLAT);
731 glBlendFunc(GL_ONE, GL_ONE);
733 glColor3f(0.5,0.5,0.5);
737 for (i = 0,p = wallpoly;i < currentwallpoly;i++, p++)
741 if (p->glowtexnum != texnum)
743 texnum = p->glowtexnum;
744 glBindTexture(GL_TEXTURE_2D, texnum);
746 vert = &wallvert[p->firstvert];
748 for (j=0 ; j<p->numverts ; j++, vert++)
750 glTexCoord2f (vert->s, vert->t);
751 glVertex3fv (vert->vert);
756 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
757 glShadeModel(GL_SMOOTH);
761 glDisable(GL_TEXTURE_2D);
762 for (i = 0,p = &wallpoly[0];i < currentwallpoly;i++, p++)
764 vert = &wallvert[p->firstvert];
766 for (j=0 ; j<p->numverts ; j++, vert++)
768 VectorSubtract(vert->vert, r_refdef.vieworg,diff);
769 glColor4f(fogcolor[0], fogcolor[1], fogcolor[2], exp(fogdensity/DotProduct(diff,diff)));
770 glVertex3fv (vert->vert);
774 glEnable(GL_TEXTURE_2D);
776 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
777 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
778 glDisable(GL_ALPHA_TEST);
779 glShadeModel(GL_SMOOTH);
786 currentskypoly = currentskyvert = 0;
789 extern qboolean isATI;
791 extern char skyname[];
792 extern int solidskytexture, alphaskytexture;
798 float length, speedscale;
802 if (currentskypoly < 1)
805 // Con_DPrintf("skypolyrender: %i polys %i vertices\n", currentskypoly, currentskyvert);
806 glDisable(GL_ALPHA_TEST);
808 // make sure zbuffer is enabled
809 glEnable(GL_DEPTH_TEST);
811 if (!fogenabled && !skyname[0]) // normal quake sky
813 glColor3f(0.5f, 0.5f, 0.5f);
814 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
815 glEnable(GL_TEXTURE_2D);
817 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
818 glBindTexture(GL_TEXTURE_2D, solidskytexture); // upper clouds
819 speedscale = realtime*8;
820 speedscale -= (int)speedscale & ~127 ;
821 for (i = 0,p = &skypoly[0];i < currentskypoly;i++, p++)
823 vert = &skyvert[p->firstvert];
825 for (j=0 ; j<p->verts ; j++, vert++)
827 VectorSubtract (vert->v, r_origin, dir);
828 dir[2] *= 3; // flatten the sphere
830 length = dir[0]*dir[0] + dir[1]*dir[1] + dir[2]*dir[2];
831 length = sqrt (length);
832 length = 6*63/length;
834 glTexCoord2f ((speedscale + dir[0] * length) * (1.0/128), (speedscale + dir[1] * length) * (1.0/128));
835 glVertex3fv (vert->v);
841 glBindTexture(GL_TEXTURE_2D, alphaskytexture); // lower clouds
842 speedscale = realtime*16;
843 speedscale -= (int)speedscale & ~127 ;
844 for (i = 0,p = &skypoly[0];i < currentskypoly;i++, p++)
846 vert = &skyvert[p->firstvert];
848 for (j=0 ; j<p->verts ; j++, vert++)
850 VectorSubtract (vert->v, r_origin, dir);
851 dir[2] *= 3; // flatten the sphere
853 length = dir[0]*dir[0] + dir[1]*dir[1] + dir[2]*dir[2];
854 length = sqrt (length);
855 length = 6*63/length;
857 glTexCoord2f ((speedscale + dir[0] * length) * (1.0/128), (speedscale + dir[1] * length) * (1.0/128));
858 glVertex3fv (vert->v);
868 glDisable(GL_TEXTURE_2D);
869 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
870 glColor3fv(fogcolor); // note: gets rendered over by skybox if fog is not enabled
871 for (i = 0,p = &skypoly[0];i < currentskypoly;i++, p++)
873 vert = &skyvert[p->firstvert];
875 for (j=0 ; j<p->verts ; j++, vert++)
876 glVertex3fv (vert->v);
880 glEnable(GL_TEXTURE_2D);