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;
371 if (currenttranspoly < 1)
373 // transpolyrenderminmax();
374 // if (transpolyindices < 1)
377 // Con_DPrintf("transpolyrender: %i polys %i infront %i vertices\n", currenttranspoly, transpolyindices, currenttransvert);
378 // if (transpolyindices >= 2)
380 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
382 glShadeModel(GL_SMOOTH);
383 glDepthMask(0); // disable zbuffer updates
384 if (isG200) // Matrox G200 cards can't handle per pixel alpha
385 glEnable(GL_ALPHA_TEST);
387 glDisable(GL_ALPHA_TEST);
388 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
389 tpolytype = TPOLYTYPE_ALPHA;
392 if (gl_vertexarrays.value)
394 // set up the vertex array
395 qglInterleavedArrays(GL_T2F_C4UB_V3F, 0, transvert);
396 for (i = 0;i < transpolyindices;i++)
398 p = &transpoly[transpolyindex[i]];
399 if (p->texnum != texnum || p->transpolytype != tpolytype)
401 if (p->texnum != texnum)
404 glBindTexture(GL_TEXTURE_2D, texnum);
406 if (p->transpolytype != tpolytype)
408 tpolytype = p->transpolytype;
409 if (tpolytype == TPOLYTYPE_ADD) // additive
410 glBlendFunc(GL_SRC_ALPHA, GL_ONE);
412 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
415 qglDrawArrays(GL_TRIANGLE_FAN, p->firstvert, p->verts);
418 texnum = p->glowtexnum; // highly unlikely to match next poly, but...
419 glBindTexture(GL_TEXTURE_2D, texnum);
420 tpolytype = TPOLYTYPE_ADD; // might match next poly
421 glBlendFunc(GL_SRC_ALPHA, GL_ONE);
422 qglDrawArrays(GL_TRIANGLE_FAN, p->firstvert, p->verts);
425 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
426 glDisableClientState(GL_COLOR_ARRAY);
427 glDisableClientState(GL_VERTEX_ARRAY);
435 for (i = 4095;i >= 0;i--)
437 item = translisthash[i];
442 if (p->texnum != texnum || p->verts != points || p->transpolytype != tpolytype)
447 if (p->fogtexnum) // alpha
448 glEnable(GL_ALPHA_TEST);
450 glDisable(GL_ALPHA_TEST);
452 if (p->texnum != texnum)
455 glBindTexture(GL_TEXTURE_2D, texnum);
457 if (p->transpolytype != tpolytype)
459 tpolytype = p->transpolytype;
460 if (tpolytype == TPOLYTYPE_ADD) // additive
461 glBlendFunc(GL_SRC_ALPHA, GL_ONE);
463 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
469 glBegin(GL_TRIANGLES);
475 glBegin(GL_TRIANGLE_FAN);
476 points = -1; // to force a reinit on the next poly
480 for (j = 0,vert = &transvert[p->firstvert];j < p->verts;j++, vert++)
482 // would be 2fv, but windoze Matrox G200 and probably G400 drivers don't support that (dumb...)
483 glTexCoord2f(vert->s, vert->t);
484 // again, vector version isn't supported I think
485 glColor4ub(vert->r, vert->g, vert->b, vert->a);
486 glVertex3fv(vert->v);
491 texnum = p->glowtexnum; // highly unlikely to match next poly, but...
492 glBindTexture(GL_TEXTURE_2D, texnum);
493 if (tpolytype != TPOLYTYPE_ADD)
495 tpolytype = TPOLYTYPE_ADD; // might match next poly
496 glBlendFunc(GL_SRC_ALPHA, GL_ONE);
499 glBegin(GL_TRIANGLE_FAN);
500 for (j = 0,vert = &transvert[p->firstvert];j < p->verts;j++, vert++)
502 glColor4ub(255,255,255,vert->a);
503 // would be 2fv, but windoze Matrox G200 and probably G400 drivers don't support that (dumb...)
504 glTexCoord2f(vert->s, vert->t);
505 glVertex3fv(vert->v);
509 if (fogenabled && p->transpolytype == TPOLYTYPE_ALPHA)
513 points = -1; // to force a reinit on the next poly
514 if (tpolytype != TPOLYTYPE_ALPHA)
516 tpolytype = TPOLYTYPE_ALPHA; // probably matchs next poly
517 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
521 if (texnum != p->fogtexnum) // highly unlikely to match next poly, but...
523 texnum = p->fogtexnum;
524 glBindTexture(GL_TEXTURE_2D, texnum);
526 glBegin(GL_TRIANGLE_FAN);
527 for (j = 0,vert = &transvert[p->firstvert];j < p->verts;j++, vert++)
529 VectorSubtract(vert->v, r_refdef.vieworg,diff);
530 glTexCoord2f(vert->s, vert->t);
531 glColor4f(fogcolor[0], fogcolor[1], fogcolor[2], vert->a*(1.0f/255.0f)*exp(fogdensity/DotProduct(diff,diff)));
532 glVertex3fv(vert->v);
538 glDisable(GL_TEXTURE_2D);
539 glBegin(GL_TRIANGLE_FAN);
540 for (j = 0,vert = &transvert[p->firstvert];j < p->verts;j++, vert++)
542 VectorSubtract(vert->v, r_refdef.vieworg,diff);
543 glColor4f(fogcolor[0], fogcolor[1], fogcolor[2], vert->a*(1.0f/255.0f)*exp(fogdensity/DotProduct(diff,diff)));
544 glVertex3fv(vert->v);
547 glEnable(GL_TEXTURE_2D);
555 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
556 glDepthMask(1); // enable zbuffer updates
557 glDisable(GL_ALPHA_TEST);
560 extern qboolean isG200;
564 currentwallpoly = currentwallvert = 0;
567 extern qboolean lighthalf;
568 void wallpolyrender()
570 int i, j, texnum, lighttexnum;
573 if (currentwallpoly < 1)
575 c_brush_polys += currentwallpoly;
577 //Con_DPrintf("wallpolyrender: %i polys %i vertices\n", currentwallpoly, currentwallvert);
579 gl_multitexture.value = 0;
581 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
582 glShadeModel(GL_FLAT);
583 // make sure zbuffer is enabled
584 glEnable(GL_DEPTH_TEST);
585 glDisable(GL_ALPHA_TEST);
588 if (r_fullbright.value) // LordHavoc: easy to do fullbright...
590 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
592 for (i = 0,p = wallpoly;i < currentwallpoly;i++, p++)
594 if (p->texnum != texnum)
597 glBindTexture(GL_TEXTURE_2D, texnum);
599 vert = &wallvert[p->firstvert];
601 for (j=0 ; j<p->numverts ; j++, vert++)
603 glTexCoord2f (vert->s, vert->t);
604 glVertex3fv (vert->vert);
609 else if (gl_multitexture.value)
611 qglSelectTexture(gl_mtex_enum+0);
612 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
613 glEnable(GL_TEXTURE_2D);
614 qglSelectTexture(gl_mtex_enum+1);
615 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
616 glEnable(GL_TEXTURE_2D);
619 for (i = 0,p = wallpoly;i < currentwallpoly;i++, p++)
621 if (p->texnum != texnum || p->lighttexnum != lighttexnum)
624 lighttexnum = p->lighttexnum;
625 qglSelectTexture(gl_mtex_enum+0);
626 glBindTexture(GL_TEXTURE_2D, texnum);
627 qglSelectTexture(gl_mtex_enum+1);
628 glBindTexture(GL_TEXTURE_2D, lighttexnum);
630 vert = &wallvert[p->firstvert];
632 for (j=0 ; j<p->numverts ; j++, vert++)
634 qglMTexCoord2f(gl_mtex_enum, vert->s, vert->t); // texture
635 qglMTexCoord2f((gl_mtex_enum+1), vert->u, vert->v); // lightmap
636 glVertex3fv (vert->vert);
641 qglSelectTexture(gl_mtex_enum+1);
642 glDisable(GL_TEXTURE_2D);
643 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
644 qglSelectTexture(gl_mtex_enum+0);
645 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
649 // first do the textures
650 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
652 for (i = 0,p = wallpoly;i < currentwallpoly;i++, p++)
654 if (p->texnum != texnum)
657 glBindTexture(GL_TEXTURE_2D, texnum);
659 vert = &wallvert[p->firstvert];
661 for (j=0 ; j<p->numverts ; j++, vert++)
663 glTexCoord2f (vert->s, vert->t);
664 glVertex3fv (vert->vert);
668 // then modulate using the lightmaps
669 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
670 glBlendFunc(GL_ZERO, GL_SRC_COLOR);
673 for (i = 0,p = wallpoly;i < currentwallpoly;i++, p++)
675 if (p->lighttexnum != texnum)
677 texnum = p->lighttexnum;
678 glBindTexture(GL_TEXTURE_2D, texnum);
680 vert = &wallvert[p->firstvert];
682 for (j=0 ; j<p->numverts ; j++, vert++)
684 glTexCoord2f (vert->u, vert->v);
685 glVertex3fv (vert->vert);
690 // switch to additive mode settings
692 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
693 glBlendFunc(GL_SRC_ALPHA, GL_ONE);
695 glDisable(GL_ALPHA_TEST);
696 glShadeModel(GL_SMOOTH);
697 // render vertex lit overlays ontop
699 for (i = 0, p = wallpoly;i < currentwallpoly;i++, p++)
703 for (j = 0,vert = &wallvert[p->firstvert];j < p->numverts;j++, vert++)
704 if (vert->r || vert->g || vert->b)
709 if (p->texnum != texnum)
712 glBindTexture(GL_TEXTURE_2D, texnum);
715 for (j = 0,vert = &wallvert[p->firstvert];j < p->numverts;j++, vert++)
717 // would be 2fv, but windoze Matrox G200 and probably G400 drivers don't support that (dumb...)
718 glTexCoord2f(vert->s, vert->t);
719 // again, vector version isn't supported I think
720 glColor3ub(vert->r, vert->g, vert->b);
721 glVertex3fv(vert->vert);
725 // render glow textures
726 glShadeModel(GL_FLAT);
727 glBlendFunc(GL_ONE, GL_ONE);
729 glColor3f(0.5,0.5,0.5);
733 for (i = 0,p = wallpoly;i < currentwallpoly;i++, p++)
737 if (p->glowtexnum != texnum)
739 texnum = p->glowtexnum;
740 glBindTexture(GL_TEXTURE_2D, texnum);
742 vert = &wallvert[p->firstvert];
744 for (j=0 ; j<p->numverts ; j++, vert++)
746 glTexCoord2f (vert->s, vert->t);
747 glVertex3fv (vert->vert);
752 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
753 glShadeModel(GL_SMOOTH);
757 glDisable(GL_TEXTURE_2D);
758 for (i = 0,p = &wallpoly[0];i < currentwallpoly;i++, p++)
760 vert = &wallvert[p->firstvert];
762 for (j=0 ; j<p->numverts ; j++, vert++)
764 VectorSubtract(vert->vert, r_refdef.vieworg,diff);
765 glColor4f(fogcolor[0], fogcolor[1], fogcolor[2], exp(fogdensity/DotProduct(diff,diff)));
766 glVertex3fv (vert->vert);
770 glEnable(GL_TEXTURE_2D);
772 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
773 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
774 glDisable(GL_ALPHA_TEST);
775 glShadeModel(GL_SMOOTH);
782 currentskypoly = currentskyvert = 0;
785 extern qboolean isATI;
787 extern char skyname[];
788 extern int solidskytexture, alphaskytexture;
794 float length, speedscale;
796 if (currentskypoly < 1)
799 // Con_DPrintf("skypolyrender: %i polys %i vertices\n", currentskypoly, currentskyvert);
800 glDisable(GL_ALPHA_TEST);
802 // make sure zbuffer is enabled
803 glEnable(GL_DEPTH_TEST);
805 if (!fogenabled && !skyname[0]) // normal quake sky
807 glColor3f(0.5f, 0.5f, 0.5f);
808 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
809 glEnable(GL_TEXTURE_2D);
811 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
812 glBindTexture(GL_TEXTURE_2D, solidskytexture); // upper clouds
813 speedscale = realtime*8;
814 speedscale -= (int)speedscale & ~127 ;
815 for (i = 0,p = &skypoly[0];i < currentskypoly;i++, p++)
817 vert = &skyvert[p->firstvert];
819 for (j=0 ; j<p->verts ; j++, vert++)
821 VectorSubtract (vert->v, r_origin, dir);
822 dir[2] *= 3; // flatten the sphere
824 length = dir[0]*dir[0] + dir[1]*dir[1] + dir[2]*dir[2];
825 length = sqrt (length);
826 length = 6*63/length;
828 glTexCoord2f ((speedscale + dir[0] * length) * (1.0/128), (speedscale + dir[1] * length) * (1.0/128));
829 glVertex3fv (vert->v);
835 glBindTexture(GL_TEXTURE_2D, alphaskytexture); // lower clouds
836 speedscale = realtime*16;
837 speedscale -= (int)speedscale & ~127 ;
838 for (i = 0,p = &skypoly[0];i < currentskypoly;i++, p++)
840 vert = &skyvert[p->firstvert];
842 for (j=0 ; j<p->verts ; j++, vert++)
844 VectorSubtract (vert->v, r_origin, dir);
845 dir[2] *= 3; // flatten the sphere
847 length = dir[0]*dir[0] + dir[1]*dir[1] + dir[2]*dir[2];
848 length = sqrt (length);
849 length = 6*63/length;
851 glTexCoord2f ((speedscale + dir[0] * length) * (1.0/128), (speedscale + dir[1] * length) * (1.0/128));
852 glVertex3fv (vert->v);
862 glDisable(GL_TEXTURE_2D);
863 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
864 glColor3fv(fogcolor); // note: gets rendered over by skybox if fog is not enabled
865 for (i = 0,p = &skypoly[0];i < currentskypoly;i++, p++)
867 vert = &skyvert[p->firstvert];
869 for (j=0 ; j<p->verts ; j++, vert++)
870 glVertex3fv (vert->v);
874 glEnable(GL_TEXTURE_2D);