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"};
23 Cvar_RegisterVariable (&gl_multitexture);
24 Cvar_RegisterVariable (&gl_vertexarrays);
25 transvert = malloc(MAX_TRANSVERTS * sizeof(transvert_t));
26 transpoly = malloc(MAX_TRANSPOLYS * sizeof(transpoly_t));
27 transpolyindex = malloc(MAX_TRANSPOLYS * sizeof(unsigned short));
28 wallvert = malloc(MAX_WALLVERTS * sizeof(wallvert_t));
29 wallpoly = malloc(MAX_WALLPOLYS * sizeof(wallpoly_t));
30 skyvert = malloc(MAX_SKYVERTS * sizeof(skyvert_t));
31 skypoly = malloc(MAX_SKYPOLYS * sizeof(skypoly_t));
36 currenttranspoly = currenttransvert = 0;
39 void transpolybegin(int texnum, int glowtexnum, int fogtexnum, int transpolytype)
41 if (currenttranspoly >= MAX_TRANSPOLYS || currenttransvert >= MAX_TRANSVERTS)
43 transpoly[currenttranspoly].texnum = (unsigned short) texnum;
44 transpoly[currenttranspoly].glowtexnum = (unsigned short) glowtexnum;
45 transpoly[currenttranspoly].fogtexnum = (unsigned short) fogtexnum;
46 transpoly[currenttranspoly].transpolytype = (unsigned short) transpolytype;
47 transpoly[currenttranspoly].firstvert = currenttransvert;
48 transpoly[currenttranspoly].verts = 0;
49 // transpoly[currenttranspoly].ndist = 0; // clear the normal
52 // turned into a #define
54 void transpolyvert(float x, float y, float z, float s, float t, int r, int g, int b, int a)
57 if (currenttranspoly >= MAX_TRANSPOLYS || currenttransvert >= MAX_TRANSVERTS)
59 transvert[currenttransvert].s = s;
60 transvert[currenttransvert].t = t;
61 transvert[currenttransvert].r = bound(0, r, 255);
62 transvert[currenttransvert].g = bound(0, g, 255);
63 transvert[currenttransvert].b = bound(0, b, 255);
64 transvert[currenttransvert].a = bound(0, a, 255);
65 transvert[currenttransvert].v[0] = x;
66 transvert[currenttransvert].v[1] = y;
67 transvert[currenttransvert].v[2] = z;
69 transpoly[currenttranspoly].verts++;
75 if (currenttranspoly >= MAX_TRANSPOLYS)
77 if (transpoly[currenttranspoly].verts < 3) // skip invalid polygons
79 currenttransvert = transpoly[currenttranspoly].firstvert; // reset vert pointer
82 if (currenttransvert >= MAX_TRANSVERTS)
88 extern qboolean isG200;
91 void transpolyrenderminmax()
93 int i, j, k, lastvert;
94 vec_t d, min, max, viewdist, s, average;
98 viewdist = DotProduct(r_refdef.vieworg, vpn);
99 for (i = 0;i < currenttranspoly;i++)
101 if (transpoly[i].verts < 3) // only process valid polygons
103 min = 1000000;max = -1000000;
104 s = 1.0f / transpoly[i].verts;
105 lastvert = transpoly[i].firstvert + transpoly[i].verts;
107 for (j = transpoly[i].firstvert;j < lastvert;j++)
109 d = DotProduct(transvert[j].v, vpn)-viewdist;
110 if (d < min) min = d;
111 if (d > max) max = d;
114 if (max < 4) // free to check here, so skip polys behind the view
116 transpoly[i].distance = average;
119 transpoly[i].mindistance = min;
120 transpoly[i].maxdistance = max;
121 // calculate normal (eek)
122 VectorSubtract(transvert[transpoly[i].firstvert ].v, transvert[transpoly[i].firstvert+1].v, v1);
123 VectorSubtract(transvert[transpoly[i].firstvert+2].v, transvert[transpoly[i].firstvert+1].v, v2);
126 if (transpoly[i].verts > 3 && fabs(DotProduct(v1, v2)) >= (1.0f - (1.0f / 256.0f))) // colinear edges, find a better triple
128 VectorSubtract(transvert[transpoly[i].firstvert + transpoly[i].verts - 1].v, transvert[transpoly[i].firstvert].v, v1);
129 VectorSubtract(transvert[transpoly[i].firstvert + 1].v, transvert[transpoly[i].firstvert].v, v2);
132 if (fabs(DotProduct(v1, v2)) < (1.0f - (1.0f / 256.0f))) // found a good triple
134 for (k = transpoly[i].firstvert + 2;k < (transpoly[i].firstvert + transpoly[i].verts - 1);k++)
136 VectorSubtract(transvert[k-1].v, transvert[k].v, v1);
137 VectorSubtract(transvert[k+1].v, transvert[k].v, v2);
140 if (fabs(DotProduct(v1, v2)) < (1.0f - (1.0f / 256.0f))) // found a good triple
143 VectorSubtract(transvert[k-1].v, transvert[k].v, v1);
144 VectorSubtract(transvert[transpoly[i].firstvert].v, transvert[k].v, v2);
147 if (fabs(DotProduct(v1, v2)) >= (1.0f - (1.0f / 256.0f))) // no good triples; the polygon is a line, skip it
151 CrossProduct(v1, v2, n);
153 ndist = DotProduct(transvert[transpoly[i].firstvert+1].v, n);
155 for (j = 0;j < transpolyindices;j++)
158 if (transpoly[transpolyindex[j]].mindistance > max)
160 if (transpoly[transpolyindex[j]].maxdistance < min)
162 // hard case, check side
163 for (k = transpoly[transpolyindex[j]].firstvert;k < (transpoly[transpolyindex[j]].firstvert + transpoly[transpolyindex[j]].verts);k++)
164 if (DotProduct(transvert[k].v, n) < ndist)
173 for (j = 0;j < transpolyindices;j++)
174 if (transpoly[transpolyindex[j]].distance < average)
176 for (k = transpolyindices;k > j;k--)
177 transpolyindex[k] = transpolyindex[k-1];
179 transpolyindex[j] = i;
184 // LordHavoc: qsort compare function
185 int transpolyqsort(const void *ia, const void *ib)
189 a = &transpoly[*((unsigned short *)ia)];
190 b = &transpoly[*((unsigned short *)ib)];
192 if (a->mindistance > b->mindistance && a->maxdistance > b->maxdistance)
194 if (a->mindistance < b->mindistance && a->maxdistance < b->maxdistance)
199 // calculate normal (eek)
201 VectorSubtract(transvert[a->firstvert ].v, transvert[a->firstvert+1].v, v1);
202 VectorSubtract(transvert[a->firstvert+2].v, transvert[a->firstvert+1].v, v2);
203 CrossProduct(v1, v2, a->n);
204 VectorNormalize(a->n);
205 a->ndist = DotProduct(transvert[a->firstvert ].v, a->n);
208 for (i = b->firstvert, j = 0;i < (b->firstvert + b->verts);i++)
209 j += DotProduct(transvert[i].v, a->n) < a->ndist; // (1) b is infront of a
211 return -1; // (-1) a is behind b
212 return j == b->verts; // (1) a is infront of b (0) a and b intersect
213 // return (transpoly[*((unsigned short *)ib)].mindistance + transpoly[*((unsigned short *)ib)].maxdistance) - (transpoly[*((unsigned short *)ia)].mindistance + transpoly[*((unsigned short *)ia)].maxdistance);
216 return ((transpoly_t*)ia)->distance - ((transpoly_t*)ib)->distance;
220 int transpolyqsort(const void *ia, const void *ib)
222 return (transpoly[*((unsigned short *)ib)].distance - transpoly[*((unsigned short *)ia)].distance);
225 void transpolyrenderminmax()
228 vec_t d, max, viewdist, average;
229 transpolyindices = 0;
230 viewdist = DotProduct(r_refdef.vieworg, vpn);
231 for (i = 0;i < currenttranspoly;i++)
233 if (transpoly[i].verts < 3) // only process valid polygons
236 lastvert = transpoly[i].firstvert + transpoly[i].verts;
238 for (j = transpoly[i].firstvert;j < lastvert;j++)
240 d = DotProduct(transvert[j].v, vpn)-viewdist;
245 if (max < 4) // free to check here, so skip polys behind the view
247 transpoly[i].distance = average / transpoly[i].verts;
248 transpolyindex[transpolyindices++] = i;
250 qsort(&transpolyindex[0], transpolyindices, sizeof(unsigned short), transpolyqsort);
258 for (i = 1;i < transpolyindices;i++)
261 if (transpoly[transpolyindex[i - 1]].mindistance > transpoly[transpolyindex[i]].mindistance && transpoly[transpolyindex[i - 1]].maxdistance > transpoly[transpolyindex[i]].maxdistance)
262 continue; // previous is behind (no swap)
263 if (transpoly[transpolyindex[i - 1]].mindistance < transpoly[transpolyindex[i]].mindistance && transpoly[transpolyindex[i - 1]].maxdistance < transpoly[transpolyindex[i]].maxdistance)
264 goto swap; // previous is infront (swap)
268 if (!transpoly[transpolyindex[i - 1]].ndist)
270 // calculate normal (eek)
272 VectorSubtract(transvert[transpoly[transpolyindex[i - 1]].firstvert ].v, transvert[transpoly[transpolyindex[i - 1]].firstvert+1].v, v1);
273 VectorSubtract(transvert[transpoly[transpolyindex[i - 1]].firstvert+2].v, transvert[transpoly[transpolyindex[i - 1]].firstvert+1].v, v2);
274 CrossProduct(v1, v2, transpoly[transpolyindex[i - 1]].n);
275 VectorNormalize(transpoly[transpolyindex[i - 1]].n);
276 transpoly[transpolyindex[i - 1]].ndist = DotProduct(transvert[transpoly[transpolyindex[i - 1]].firstvert ].v, transpoly[transpolyindex[i - 1]].n);
278 if (DotProduct(transpoly[transpolyindex[i - 1]].n, vpn) >= 0.0f) // backface
283 for (i = transpoly[transpolyindex[i]].firstvert;i < (transpoly[transpolyindex[i]].firstvert + transpoly[transpolyindex[i]].verts);i++)
284 if (DotProduct(transvert[i].v, transpoly[transpolyindex[i - 1]].n) >= transpoly[transpolyindex[i - 1]].ndist)
285 goto noswap; // previous is behind or they intersect
287 // previous is infront (swap)
288 j = transpolyindex[i];
289 transpolyindex[i] = transpolyindex[i - 1];
290 transpolyindex[i - 1] = j;
299 void transpolyrender()
301 int i, j, tpolytype, texnum;
303 if (currenttranspoly < 1)
305 transpolyrenderminmax();
306 if (transpolyindices < 1)
309 // Con_DPrintf("transpolyrender: %i polys %i infront %i vertices\n", currenttranspoly, transpolyindices, currenttransvert);
310 // if (transpolyindices >= 2)
312 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
314 glShadeModel(GL_SMOOTH);
315 glDepthMask(0); // disable zbuffer updates
316 if (isG200) // Matrox G200 cards can't handle per pixel alpha
317 glEnable(GL_ALPHA_TEST);
319 glDisable(GL_ALPHA_TEST);
320 // later note: wasn't working on my TNT drivers... strangely... used a cheaper hack in transpolyvert
321 //// offset by 16 depth units so decal sprites appear infront of walls
322 //glPolygonOffset(1, -16);
323 //glEnable(GL_POLYGON_OFFSET_FILL);
324 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
325 tpolytype = TPOLYTYPE_ALPHA;
328 if (gl_vertexarrays.value)
330 // set up the vertex array
331 qglInterleavedArrays(GL_T2F_C4UB_V3F, 0, transvert);
332 for (i = 0;i < transpolyindices;i++)
334 p = &transpoly[transpolyindex[i]];
335 if (p->texnum != texnum || p->transpolytype != tpolytype)
337 if (p->texnum != texnum)
340 glBindTexture(GL_TEXTURE_2D, texnum);
342 if (p->transpolytype != tpolytype)
344 tpolytype = p->transpolytype;
345 if (tpolytype == TPOLYTYPE_ADD) // additive
346 glBlendFunc(GL_SRC_ALPHA, GL_ONE);
348 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
351 qglDrawArrays(GL_TRIANGLE_FAN, p->firstvert, p->verts);
354 texnum = p->glowtexnum; // highly unlikely to match next poly, but...
355 glBindTexture(GL_TEXTURE_2D, texnum);
356 tpolytype = TPOLYTYPE_ADD; // might match next poly
357 glBlendFunc(GL_SRC_ALPHA, GL_ONE);
358 qglDrawArrays(GL_TRIANGLE_FAN, p->firstvert, p->verts);
361 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
362 glDisableClientState(GL_COLOR_ARRAY);
363 glDisableClientState(GL_VERTEX_ARRAY);
370 for (i = 0;i < transpolyindices;i++)
372 p = &transpoly[transpolyindex[i]];
373 if (p->texnum != texnum || p->verts != points || p->transpolytype != tpolytype)
378 if (p->fogtexnum) // alpha
379 glEnable(GL_ALPHA_TEST);
381 glDisable(GL_ALPHA_TEST);
383 if (p->texnum != texnum)
386 glBindTexture(GL_TEXTURE_2D, texnum);
388 if (p->transpolytype != tpolytype)
390 tpolytype = p->transpolytype;
391 if (tpolytype == TPOLYTYPE_ADD) // additive
392 glBlendFunc(GL_SRC_ALPHA, GL_ONE);
394 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
400 glBegin(GL_TRIANGLES);
406 glBegin(GL_TRIANGLE_FAN);
407 points = -1; // to force a reinit on the next poly
411 for (j = 0,vert = &transvert[p->firstvert];j < p->verts;j++, vert++)
413 // would be 2fv, but windoze Matrox G200 and probably G400 drivers don't support that (dumb...)
414 glTexCoord2f(vert->s, vert->t);
415 // again, vector version isn't supported I think
416 glColor4ub(vert->r, vert->g, vert->b, vert->a);
417 glVertex3fv(vert->v);
422 texnum = p->glowtexnum; // highly unlikely to match next poly, but...
423 glBindTexture(GL_TEXTURE_2D, texnum);
424 if (tpolytype != TPOLYTYPE_ADD)
426 tpolytype = TPOLYTYPE_ADD; // might match next poly
427 glBlendFunc(GL_SRC_ALPHA, GL_ONE);
430 glBegin(GL_TRIANGLE_FAN);
431 for (j = 0,vert = &transvert[p->firstvert];j < p->verts;j++, vert++)
433 glColor4ub(255,255,255,vert->a);
434 // would be 2fv, but windoze Matrox G200 and probably G400 drivers don't support that (dumb...)
435 glTexCoord2f(vert->s, vert->t);
436 glVertex3fv(vert->v);
440 if (fogenabled && p->transpolytype == TPOLYTYPE_ALPHA)
444 points = -1; // to force a reinit on the next poly
445 if (tpolytype != TPOLYTYPE_ALPHA)
447 tpolytype = TPOLYTYPE_ALPHA; // probably matchs next poly
448 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
452 if (texnum != p->fogtexnum) // highly unlikely to match next poly, but...
454 texnum = p->fogtexnum;
455 glBindTexture(GL_TEXTURE_2D, texnum);
457 glBegin(GL_TRIANGLE_FAN);
458 for (j = 0,vert = &transvert[p->firstvert];j < p->verts;j++, vert++)
460 VectorSubtract(vert->v, r_refdef.vieworg,diff);
461 glTexCoord2f(vert->s, vert->t);
462 glColor4f(fogcolor[0], fogcolor[1], fogcolor[2], vert->a*(1.0f/255.0f)*exp(fogdensity/DotProduct(diff,diff)));
463 glVertex3fv(vert->v);
469 glDisable(GL_TEXTURE_2D);
470 glBegin(GL_TRIANGLE_FAN);
471 for (j = 0,vert = &transvert[p->firstvert];j < p->verts;j++, vert++)
473 VectorSubtract(vert->v, r_refdef.vieworg,diff);
474 glColor4f(fogcolor[0], fogcolor[1], fogcolor[2], vert->a*(1.0f/255.0f)*exp(fogdensity/DotProduct(diff,diff)));
475 glVertex3fv(vert->v);
478 glEnable(GL_TEXTURE_2D);
485 //glDisable(GL_POLYGON_OFFSET_FILL);
486 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
487 glDepthMask(1); // enable zbuffer updates
488 glDisable(GL_ALPHA_TEST);
493 currentwallpoly = currentwallvert = 0;
496 extern qboolean lighthalf;
497 void wallpolyrender()
499 int i, j, texnum, lighttexnum;
502 if (currentwallpoly < 1)
504 c_brush_polys += currentwallpoly;
506 //Con_DPrintf("wallpolyrender: %i polys %i vertices\n", currentwallpoly, currentwallvert);
508 gl_multitexture.value = 0;
510 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
511 glShadeModel(GL_FLAT);
512 // make sure zbuffer is enabled
513 glEnable(GL_DEPTH_TEST);
514 glDisable(GL_ALPHA_TEST);
517 if (r_fullbright.value) // LordHavoc: easy to do fullbright...
519 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
521 for (i = 0,p = &wallpoly[0];i < currentwallpoly;i++, p++)
523 if (p->texnum != texnum)
526 glBindTexture(GL_TEXTURE_2D, texnum);
528 vert = &wallvert[p->firstvert];
530 for (j=0 ; j<p->verts ; j++, vert++)
532 glTexCoord2f (vert->s, vert->t);
533 glVertex3fv (vert->vert);
538 else if (gl_multitexture.value)
540 qglSelectTexture(gl_mtex_enum+0);
541 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
542 glEnable(GL_TEXTURE_2D);
543 qglSelectTexture(gl_mtex_enum+1);
544 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
545 glEnable(GL_TEXTURE_2D);
548 for (i = 0,p = &wallpoly[0];i < currentwallpoly;i++, p++)
550 // if (p->texnum != texnum || p->lighttexnum != lighttexnum)
553 lighttexnum = p->lighttexnum;
554 qglSelectTexture(gl_mtex_enum+0);
555 glBindTexture(GL_TEXTURE_2D, texnum);
556 qglSelectTexture(gl_mtex_enum+1);
557 glBindTexture(GL_TEXTURE_2D, lighttexnum);
559 vert = &wallvert[p->firstvert];
561 for (j=0 ; j<p->verts ; j++, vert++)
563 qglMTexCoord2f(gl_mtex_enum, vert->s, vert->t); // texture
564 qglMTexCoord2f((gl_mtex_enum+1), vert->u, vert->v); // lightmap
565 glVertex3fv (vert->vert);
570 qglSelectTexture(gl_mtex_enum+1);
571 glDisable(GL_TEXTURE_2D);
572 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
573 qglSelectTexture(gl_mtex_enum+0);
574 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
578 // first do the textures
579 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
581 for (i = 0,p = &wallpoly[0];i < currentwallpoly;i++, p++)
583 if (p->texnum != texnum)
586 glBindTexture(GL_TEXTURE_2D, texnum);
588 vert = &wallvert[p->firstvert];
590 for (j=0 ; j<p->verts ; j++, vert++)
592 glTexCoord2f (vert->s, vert->t);
593 glVertex3fv (vert->vert);
597 // then modulate using the lightmaps
598 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
599 glBlendFunc(GL_ZERO, GL_SRC_COLOR);
602 for (i = 0,p = &wallpoly[0];i < currentwallpoly;i++, p++)
604 if (p->lighttexnum != texnum)
606 texnum = p->lighttexnum;
607 glBindTexture(GL_TEXTURE_2D, texnum);
609 vert = &wallvert[p->firstvert];
611 for (j=0 ; j<p->verts ; j++, vert++)
613 glTexCoord2f (vert->u, vert->v);
614 glVertex3fv (vert->vert);
619 // render glow textures
621 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
622 glBlendFunc(GL_ONE, GL_ONE);
625 glColor3f(0.5,0.5,0.5);
629 for (i = 0,p = &wallpoly[0];i < currentwallpoly;i++, p++)
633 if (p->glowtexnum != texnum)
635 texnum = p->glowtexnum;
636 glBindTexture(GL_TEXTURE_2D, texnum);
638 vert = &wallvert[p->firstvert];
640 for (j=0 ; j<p->verts ; j++, vert++)
642 glTexCoord2f (vert->s, vert->t);
643 glVertex3fv (vert->vert);
648 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
649 glShadeModel(GL_SMOOTH);
653 glDisable(GL_TEXTURE_2D);
654 for (i = 0,p = &wallpoly[0];i < currentwallpoly;i++, p++)
656 vert = &wallvert[p->firstvert];
658 for (j=0 ; j<p->verts ; j++, vert++)
660 VectorSubtract(vert->vert, r_refdef.vieworg,diff);
661 glColor4f(fogcolor[0], fogcolor[1], fogcolor[2], exp(fogdensity/DotProduct(diff,diff)));
662 glVertex3fv (vert->vert);
666 glEnable(GL_TEXTURE_2D);
674 currentskypoly = currentskyvert = 0;
677 extern qboolean isATI;
679 extern char skyname[];
680 extern int solidskytexture, alphaskytexture;
686 float length, speedscale;
688 if (currentskypoly < 1)
691 // Con_DPrintf("skypolyrender: %i polys %i vertices\n", currentskypoly, currentskyvert);
692 glDisable(GL_ALPHA_TEST);
694 // make sure zbuffer is enabled
695 glEnable(GL_DEPTH_TEST);
697 if (!fogenabled && !skyname[0]) // normal quake sky
699 glColor3f(0.5f, 0.5f, 0.5f);
700 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
701 glEnable(GL_TEXTURE_2D);
703 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
704 glBindTexture(GL_TEXTURE_2D, solidskytexture); // upper clouds
705 speedscale = realtime*8;
706 speedscale -= (int)speedscale & ~127 ;
707 for (i = 0,p = &skypoly[0];i < currentskypoly;i++, p++)
709 vert = &skyvert[p->firstvert];
711 for (j=0 ; j<p->verts ; j++, vert++)
713 VectorSubtract (vert->v, r_origin, dir);
714 dir[2] *= 3; // flatten the sphere
716 length = dir[0]*dir[0] + dir[1]*dir[1] + dir[2]*dir[2];
717 length = sqrt (length);
718 length = 6*63/length;
720 glTexCoord2f ((speedscale + dir[0] * length) * (1.0/128), (speedscale + dir[1] * length) * (1.0/128));
721 glVertex3fv (vert->v);
727 glBindTexture(GL_TEXTURE_2D, alphaskytexture); // lower clouds
728 speedscale = realtime*16;
729 speedscale -= (int)speedscale & ~127 ;
730 for (i = 0,p = &skypoly[0];i < currentskypoly;i++, p++)
732 vert = &skyvert[p->firstvert];
734 for (j=0 ; j<p->verts ; j++, vert++)
736 VectorSubtract (vert->v, r_origin, dir);
737 dir[2] *= 3; // flatten the sphere
739 length = dir[0]*dir[0] + dir[1]*dir[1] + dir[2]*dir[2];
740 length = sqrt (length);
741 length = 6*63/length;
743 glTexCoord2f ((speedscale + dir[0] * length) * (1.0/128), (speedscale + dir[1] * length) * (1.0/128));
744 glVertex3fv (vert->v);
754 glDisable(GL_TEXTURE_2D);
755 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
756 glColor3fv(fogcolor); // note: gets rendered over by skybox if fog is not enabled
757 for (i = 0,p = &skypoly[0];i < currentskypoly;i++, p++)
759 vert = &skyvert[p->firstvert];
761 for (j=0 ; j<p->verts ; j++, vert++)
762 glVertex3fv (vert->v);
766 glEnable(GL_TEXTURE_2D);