~ubuntu-branches/ubuntu/natty/alien-arena/natty

« back to all changes in this revision

Viewing changes to source/ref_gl/r_surf.c

  • Committer: Bazaar Package Importer
  • Author(s): Andres Mejia, Barry deFreese, Ansgar Burchardt, Gonéri Le Bouder, Andres Mejia
  • Date: 2008-04-18 17:43:24 UTC
  • mfrom: (1.1.2 upstream) (3.1.1 hardy)
  • Revision ID: james.westby@ubuntu.com-20080418174324-si1umi8dngglaha4
Tags: 7.0-1
[ Barry deFreese ]
* Escape - in alien-arena-server.6.
* Add myself to uploaders.

[ Ansgar Burchardt ]
* Remove deprecated Encoding key from .desktop file.

[ Gonéri Le Bouder ]
* Remove Homepage from package description.

[ Andres Mejia ]
* New upstream release.
* Removing XS- part for Vcs-* lines.
* Removing +ssh part of Vcs-Svn line.
* Bumped to Standards-Version 3.7.3.
* Test for existence of *-stamp stamps before removing them.
* Removed Encoding field in desktop file.
* Modify patch for upstream Makefile to make Makefile more useful in building
  Debian packages.
  + Also fixes problem not detecting the existence of libcurl.
* Remove debug packages for release. Will support nostrip option instead.
* Add description for fix-CVE-2007-4754-CVE-2007-4755.dpatch, silences
  lintian warning.
* Add new link for watchfile.
  + Closes: #453555
* Moved debian/scripts/alien-arena-tarball.sh to
  debian/alien-arena-get-orig-source.
* Modified alien-arena-data-get-orig-source to make it easier to maintain.
* Switched from dpatch to quilt.
* Cut down package description.
* Closing bug about mouse constantly looking up. The submitter could not
  reproduce the bug after deleting the ~/.alien-arena directory.
  + Closes: #457700
* Updated copyright file for new release.
* Updated README.Debian files.
* Adding new images for icons. Need build dependency on sharutils.

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
 
9
9
This program is distributed in the hope that it will be useful,
10
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
 
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
12
 
13
13
See the GNU General Public License for more details.
14
14
 
27
27
 
28
28
msurface_t      *r_alpha_surfaces;
29
29
msurface_t      *r_special_surfaces;
 
30
msurface_t *r_normalsurfaces;
 
31
msurface_t *r_specularsurfaces;
30
32
 
31
33
#define DYNAMIC_LIGHT_WIDTH  128
32
34
#define DYNAMIC_LIGHT_HEIGHT 128
65
67
 
66
68
extern void R_SetCacheState( msurface_t *surf );
67
69
extern void R_BuildLightMap (msurface_t *surf, byte *dest, int stride);
68
 
 
69
 
// MH - detail textures begin
70
 
// this should most likely properly belong in a state management struct somewhere
71
 
static msurface_t *r_detailsurfaces;
72
 
// MH - detail textures end
73
70
 
74
71
/*
75
72
=============================================================
101
98
        }
102
99
 
103
100
        return tex->image;
104
 
}
105
 
 
 
101
}
 
102
 
106
103
/*
107
104
================
108
105
DrawGLPoly
174
171
*/
175
172
void DrawGLPolyLightmap( glpoly_t *p, float soffset, float toffset )
176
173
{
177
 
        float *v = p->verts[0];
178
 
        int j;
179
 
 
180
 
        qglBegin (GL_POLYGON);
181
 
 
182
 
        for (j=0 ; j<p->numverts ; j++, v+= VERTEXSIZE)
183
 
        {
184
 
                qglTexCoord2f (v[5] - soffset, v[6] - toffset );
185
 
                qglVertex3fv (v);
186
 
        }
 
174
        float *v = p->verts[0];
 
175
        int j;
 
176
 
 
177
        qglBegin (GL_POLYGON);
 
178
 
 
179
        for (j=0 ; j<p->numverts ; j++, v+= VERTEXSIZE)
 
180
        {
 
181
                qglTexCoord2f (v[5] - soffset, v[6] - toffset );
 
182
                qglVertex3fv (v);
 
183
        }
187
184
        qglEnd ();
188
185
}
189
186
 
214
211
        if (!gl_lightmap->value)
215
212
        {
216
213
                qglEnable (GL_BLEND);
217
 
 
218
 
                if ( gl_saturatelighting->value )
219
 
                {
220
 
                        qglBlendFunc( GL_ONE, GL_ONE );
221
 
                }
222
 
                else
223
 
                {
224
 
                        if ( gl_monolightmap->string[0] != '0' )
225
 
                        {
226
 
                                switch ( toupper( gl_monolightmap->string[0] ) )
227
 
                                {
228
 
                                case 'I':
229
 
                                        qglBlendFunc (GL_ZERO, GL_SRC_COLOR );
230
 
                                        break;
231
 
                                case 'L':
232
 
                                        qglBlendFunc (GL_ZERO, GL_SRC_COLOR );
233
 
                                        break;
234
 
                                case 'A':
235
 
                                default:
236
 
                                        qglBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
237
 
                                        break;
238
 
                                }
239
 
                        }
240
 
                        else
241
 
                        {
242
 
                                qglBlendFunc (GL_ZERO, GL_SRC_COLOR );
243
 
                        }
244
 
                }
 
214
                qglBlendFunc (GL_ZERO, GL_SRC_COLOR );
245
215
        }
246
216
 
247
217
        if ( currentmodel == r_worldmodel )
302
272
                                // upload what we have so far
303
273
                                LM_UploadBlock( true );
304
274
 
305
 
                                // draw all surfaces that use this lightmap
306
 
                                for (drawsurf = newdrawsurf; drawsurf != surf; drawsurf = drawsurf->lightmapchain)
307
 
                                {
308
 
                                        if (drawsurf->polys)
309
 
                                                DrawGLPolyLightmap(drawsurf->polys, 
310
 
                                                        (drawsurf->light_s - drawsurf->dlight_s) * 0.0078125, // ( 1.0 / 128.0 ), 
311
 
                                                        (drawsurf->light_t - drawsurf->dlight_t) * 0.0078125); // ( 1.0 / 128.0 ) );
 
275
                                // draw all surfaces that use this lightmap
 
276
                                for (drawsurf = newdrawsurf; drawsurf != surf; drawsurf = drawsurf->lightmapchain)
 
277
                                {
 
278
                                        if (drawsurf->polys)
 
279
                                                DrawGLPolyLightmap(drawsurf->polys,
 
280
                                                        (drawsurf->light_s - drawsurf->dlight_s) * 0.0078125, // ( 1.0 / 128.0 ),
 
281
                                                        (drawsurf->light_t - drawsurf->dlight_t) * 0.0078125); // ( 1.0 / 128.0 ) );
312
282
                                }
313
283
 
314
284
                                newdrawsurf = drawsurf;
335
305
                if ( newdrawsurf )
336
306
                        LM_UploadBlock( true );
337
307
 
338
 
                for (surf = newdrawsurf; surf != 0; surf = surf->lightmapchain)
339
 
                {
340
 
                        if (surf->polys)
341
 
                                DrawGLPolyLightmap(surf->polys, (surf->light_s - surf->dlight_s) * 0.0078125f /*( 1.0 / 128.0 )*/,
342
 
                                        (surf->light_t - surf->dlight_t) * 0.0078125f); // ( 1.0 / 128.0 ) );
 
308
                for (surf = newdrawsurf; surf != 0; surf = surf->lightmapchain)
 
309
                {
 
310
                        if (surf->polys)
 
311
                                DrawGLPolyLightmap(surf->polys, (surf->light_s - surf->dlight_s) * 0.0078125f /*( 1.0 / 128.0 )*/,
 
312
                                        (surf->light_t - surf->dlight_t) * 0.0078125f); // ( 1.0 / 128.0 ) );
343
313
                }
344
314
        }
345
315
 
367
337
        image = R_TextureAnimation (fa->texinfo);
368
338
 
369
339
        if (fa->flags & SURF_DRAWTURB)
370
 
        {       
 
340
        {
371
341
                GL_Bind( image->texnum );
372
342
 
373
343
                // warp texture, no lightmaps
374
344
                GL_TexEnv( GL_MODULATE );
375
 
                qglColor4f( gl_state.inverse_intensity, 
 
345
                qglColor4f( gl_state.inverse_intensity,
376
346
                                gl_state.inverse_intensity,
377
347
                                        gl_state.inverse_intensity,
378
348
                                        1.0F );
391
361
                GL_TexEnv( GL_REPLACE );
392
362
        }
393
363
 
394
 
        // MH - detail textures begin
395
 
        // accumulate the detail chain
396
 
        // wait until we get here so that we don't get any detail texturing on DRAWTURB polys
397
 
        fa->detailchain = r_detailsurfaces;
398
 
        r_detailsurfaces = fa;
399
 
        // MH - detail textures end
 
364
        fa->normalchain = r_normalsurfaces;
 
365
        r_normalsurfaces = fa;
 
366
        fa->specularchain = r_specularsurfaces;
 
367
        r_specularsurfaces = fa;
400
368
 
401
369
        if (SurfaceIsAlphaBlended(fa))
402
370
                qglEnable( GL_ALPHA_TEST );
403
 
        
 
371
 
404
372
        DrawGLPoly (fa->polys, fa->texinfo->flags);
405
373
 
406
374
        if (SurfaceIsAlphaBlended(fa))
447
415
                        GL_Bind( gl_state.lightmap_textures + fa->lightmaptexturenum );
448
416
 
449
417
                        qglTexSubImage2D( GL_TEXTURE_2D, 0,
450
 
                                                          fa->light_s, fa->light_t, 
451
 
                                                          smax, tmax, 
452
 
                                                          GL_LIGHTMAP_FORMAT, 
 
418
                                                          fa->light_s, fa->light_t,
 
419
                                                          smax, tmax,
 
420
                                                          GL_LIGHTMAP_FORMAT,
453
421
                                                          GL_UNSIGNED_BYTE, temp );
454
422
 
455
423
                        fa->lightmapchain = gl_lms.lightmap_surfaces[fa->lightmaptexturenum];
482
450
{
483
451
        msurface_t      *s;
484
452
        float           intens;
485
 
        rscript_t *rs_shader;
 
453
        rscript_t *rs_shader;
486
454
 
487
455
        // the textures are prescaled up for a better lighting range,
488
456
        // so scale it back down
489
457
        intens = gl_state.inverse_intensity;
490
458
 
491
459
        for (s=r_alpha_surfaces ; s ; s=s->texturechain)
492
 
        {
493
 
                qglLoadMatrixf (r_world_matrix); //moving trans brushes
494
 
 
495
 
                qglDepthMask ( GL_FALSE );
496
 
                qglEnable (GL_BLEND);
497
 
                GL_TexEnv( GL_MODULATE );
 
460
        {
 
461
                qglLoadMatrixf (r_world_matrix); //moving trans brushes
 
462
 
 
463
                qglDepthMask ( GL_FALSE );
 
464
                qglEnable (GL_BLEND);
 
465
                GL_TexEnv( GL_MODULATE );
498
466
 
499
467
                GL_Bind(s->texinfo->image->texnum);
500
468
                c_brush_polys++;
504
472
                else if (s->texinfo->flags & SURF_TRANS66)
505
473
                        qglColor4f (intens, intens, intens, 0.66);
506
474
                else
507
 
                        qglColor4f (intens, intens, intens, 1);
508
 
 
509
 
                //moving trans brushes - spaz
510
 
                if (s->entity)
511
 
                {
512
 
                        s->entity->angles[0] = -s->entity->angles[0];   // stupid quake bug
513
 
                        s->entity->angles[2] = -s->entity->angles[2];   // stupid quake bug
514
 
                                R_RotateForEntity (s->entity);
515
 
                        s->entity->angles[0] = -s->entity->angles[0];   // stupid quake bug
516
 
                        s->entity->angles[2] = -s->entity->angles[2];   // stupid quake bug
 
475
                        qglColor4f (intens, intens, intens, 1);
 
476
 
 
477
                //moving trans brushes - spaz
 
478
                if (s->entity)
 
479
                {
 
480
                        s->entity->angles[0] = -s->entity->angles[0];   // stupid quake bug
 
481
                        s->entity->angles[2] = -s->entity->angles[2];   // stupid quake bug
 
482
                                R_RotateForEntity (s->entity);
 
483
                        s->entity->angles[0] = -s->entity->angles[0];   // stupid quake bug
 
484
                        s->entity->angles[2] = -s->entity->angles[2];   // stupid quake bug
517
485
                }
518
486
 
519
 
                if (s->flags & SURF_DRAWTURB) { 
 
487
                if (s->flags & SURF_DRAWTURB) {
520
488
                        if(!gl_reflection->value || (!Q_stricmp(s->texinfo->image->name, "textures/arena2/lava.wal"))) //lava HACK!
521
489
                                EmitWaterPolys_original (s);
522
490
                        else
523
491
                                EmitWaterPolys (s);
524
492
                }
525
 
                else {
526
 
                        if(r_shaders->value) {
527
 
                                rs_shader = (rscript_t *)s->texinfo->image->script;
528
 
                                if(rs_shader) {
529
 
 
530
 
                                        qglDepthMask(false);
531
 
                                        qglShadeModel (GL_SMOOTH);
532
 
                                        qglEnable(GL_POLYGON_OFFSET_FILL); 
533
 
                                        qglPolygonOffset(-3, -2); 
534
 
                                        
535
 
                                        RS_SpecialSurface(s);
536
 
 
537
 
                                        qglDisable(GL_POLYGON_OFFSET_FILL); 
538
 
                                        GLSTATE_DISABLE_BLEND
539
 
                                        GLSTATE_DISABLE_ALPHATEST
540
 
 
541
 
                                        qglDepthMask(true);
542
 
                                }
543
 
                                else
544
 
                                        DrawGLPoly (s->polys, s->texinfo->flags);
 
493
                else {
 
494
                        if(r_shaders->value) {
 
495
                                rs_shader = (rscript_t *)s->texinfo->image->script;
 
496
                                if(rs_shader) {
 
497
 
 
498
                                        qglDepthMask(false);
 
499
                                        qglShadeModel (GL_SMOOTH);
 
500
                                        qglEnable(GL_POLYGON_OFFSET_FILL);
 
501
                                        qglPolygonOffset(-3, -2);
 
502
 
 
503
                                        RS_SpecialSurface(s);
 
504
 
 
505
                                        qglDisable(GL_POLYGON_OFFSET_FILL);
 
506
                                        GLSTATE_DISABLE_BLEND
 
507
                                        GLSTATE_DISABLE_ALPHATEST
 
508
 
 
509
                                        qglDepthMask(true);
 
510
                                }
 
511
                                else
 
512
                                        DrawGLPoly (s->polys, s->texinfo->flags);
545
513
                        }
546
 
                        else
547
 
                                DrawGLPoly (s->polys, s->texinfo->flags);
548
 
                }
 
514
                        else
 
515
                                DrawGLPoly (s->polys, s->texinfo->flags);
 
516
                }
549
517
 
550
518
        }
551
519
 
560
528
void R_DrawSpecialSurfaces (void)
561
529
{
562
530
        msurface_t      *s;
563
 
        
 
531
 
564
532
        if (!r_shaders->value)
565
533
        {
566
534
                r_special_surfaces = NULL;
570
538
        qglDepthMask(false);
571
539
        qglShadeModel (GL_SMOOTH);
572
540
 
573
 
        qglEnable(GL_POLYGON_OFFSET_FILL); 
574
 
        qglPolygonOffset(-3, -2); 
 
541
        qglEnable(GL_POLYGON_OFFSET_FILL);
 
542
        qglPolygonOffset(-3, -2);
575
543
 
576
544
        for (s=r_special_surfaces ; s ; s=s->specialchain)
577
545
                RS_SpecialSurface(s);
578
 
        
579
 
        qglDisable(GL_POLYGON_OFFSET_FILL); 
 
546
 
 
547
        qglDisable(GL_POLYGON_OFFSET_FILL);
580
548
 
581
549
        GLSTATE_DISABLE_BLEND
582
550
        GLSTATE_DISABLE_ALPHATEST
663
631
        float   *v;
664
632
        image_t *image = R_TextureAnimation( surf->texinfo );
665
633
        qboolean is_dynamic = false;
666
 
        unsigned lmtex = surf->lightmaptexturenum;
667
 
 
668
 
        // MH - detail textures begin
669
 
        // accumulate the detail texture chain
670
 
        surf->detailchain = r_detailsurfaces;
671
 
        r_detailsurfaces = surf;
672
 
        // MH - detail textures end
673
 
 
 
634
        unsigned lmtex = surf->lightmaptexturenum;
 
635
        
 
636
        surf->normalchain = r_normalsurfaces;
 
637
        r_normalsurfaces = surf;
 
638
        surf->specularchain = r_specularsurfaces;
 
639
        r_specularsurfaces = surf;
 
640
        
674
641
        for ( map = 0; map < MAXLIGHTMAPS && surf->styles[map] != 255; map++ )
675
642
        {
676
643
                if ( r_newrefdef.lightstyles[surf->styles[map]].white != surf->cached_light[map] )
695
662
 
696
663
                smax = (surf->extents[0]>>4)+1;
697
664
                tmax = (surf->extents[1]>>4)+1;
698
 
                
 
665
 
699
666
                R_BuildLightMap( surf, (void *)temp, smax*4 );
700
 
                
 
667
 
701
668
                if ( ( surf->styles[map] >= 32 || surf->styles[map] == 0 ) && ( surf->dlightframe != r_framecount ) ) {
702
669
                        R_SetCacheState( surf );
703
670
                } else {
706
673
 
707
674
                GL_MBind( GL_TEXTURE1, gl_state.lightmap_textures + lmtex );
708
675
                qglTexSubImage2D( GL_TEXTURE_2D, 0,
709
 
                                                  surf->light_s, surf->light_t, 
710
 
                                                  smax, tmax, 
711
 
                                                  GL_LIGHTMAP_FORMAT, 
 
676
                                                  surf->light_s, surf->light_t,
 
677
                                                  smax, tmax,
 
678
                                                  GL_LIGHTMAP_FORMAT,
712
679
                                                  GL_UNSIGNED_BYTE, temp );
713
680
        }
714
 
        
 
681
 
715
682
        c_brush_polys++;
716
 
        
 
683
 
717
684
        if (SurfaceIsAlphaBlended(surf))
718
685
                qglEnable( GL_ALPHA_TEST );
719
686
 
742
709
                qglDisable( GL_ALPHA_TEST);
743
710
}
744
711
 
745
 
// MH - detail textures begin
746
 
// here we draw the detail textures!
747
 
// we could do this as a multitextured render along with the other stuff, but my own tests
748
 
// have indicated that for something like this there's no real benefit to be had from doing
749
 
// so.  the difference is in the order of 1 or 2 FPS - the real hit from detail texturing
750
 
// comes from scrunching large images into small spaces
751
 
static void R_DrawDetailSurfaces (void)
752
 
{
753
 
        msurface_t *surf = r_detailsurfaces;
754
 
        int             i;
755
 
        float   *v;
756
 
        glpoly_t *p;
757
 
 
758
 
        // nothing to draw!
759
 
        if (!surf)
760
 
                return;
761
 
 
762
 
        // we do this rather than checking for 0 (checking for 0 is always bad with floats)
763
 
        // standard 6 decimal place precision
764
 
        if (gl_detailtextures->value < 0.00001)
765
 
                return;
766
 
 
767
 
        // we *could* use the standard glBindTexture here as we don't need to do any bind checking
768
 
        // but again we'll maintain consistency
769
 
        GL_Bind (r_detailtexture->texnum);
770
 
 
771
 
        // set the correct blending mode
772
 
        qglTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
773
 
        qglBlendFunc (GL_DST_COLOR, GL_SRC_COLOR);
774
 
        qglEnable (GL_BLEND);
775
 
 
776
 
        // here we get clever and do our texture scaling in the texture matrix.  this saves
777
 
        // us from more runtime calculations in software
778
 
        qglMatrixMode (GL_TEXTURE);
779
 
        qglLoadIdentity ();
780
 
 
781
 
        // we only need to scale the X and Y co-ords, correcponding to texture s and t.
782
 
        // everyone will have their own favourite scaling amount, so i did a cvar
783
 
        qglScalef (gl_detailtextures->value, gl_detailtextures->value, 1.0);
784
 
 
785
 
        // we can safely leave the texture matrix as the active mode while we're doing the draw
786
 
        for (; surf; surf = surf->detailchain)
787
 
        {
788
 
                if (SurfaceIsAlphaBlended(surf))
789
 
                        continue;
790
 
                for (p = surf->polys; p; p = p->chain)
791
 
                {
792
 
                        // using GL_TRIANGLE_FAN is theoretically more efficient than GL_POLYGON as
793
 
                        // the GL implementation can know something about what we are going to draw
794
 
                        // in advance, and set things up accordingly.  the visual result is identical.
795
 
                        qglBegin (GL_TRIANGLE_FAN);
796
 
 
797
 
                        for (v = p->verts[0], i = 0 ; i < p->numverts; i++, v += VERTEXSIZE)
798
 
                        {
799
 
                                // take the 128 * 128 version of the s and t co-ords
800
 
                                qglTexCoord2f (v[7], v[8]);
801
 
                                qglVertex3fv (v);
802
 
                        }
803
 
 
804
 
                        qglEnd ();
805
 
                }
806
 
        }
807
 
 
808
 
        // restore original texture matrix
809
 
        qglLoadIdentity ();
810
 
        qglMatrixMode (GL_MODELVIEW);
811
 
 
812
 
        // restore original blend
813
 
        qglTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
814
 
        qglBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
815
 
        qglDisable (GL_BLEND);
816
 
}
817
 
// MH - detail textures end
 
712
//This next section deals with bumpmapped surfaces.  Much of this was gathered from Mike Hiney
 
713
//and "Paul's Projects" tutorials.
 
714
static void R_InitNormalSurfaces (void)
 
715
{
 
716
        dlight_t        *dl;
 
717
        int                     lnum;
 
718
        vec3_t          lightAdd, angle;
 
719
        float           add;
 
720
 
 
721
        qglActiveTextureARB (GL_TEXTURE0);
 
722
        qglDisable (GL_TEXTURE_2D);
 
723
        qglEnable (GL_TEXTURE_CUBE_MAP_ARB);
 
724
 
 
725
        qglBindTexture (GL_TEXTURE_CUBE_MAP_ARB, r_cubemap->texnum);
 
726
        qglMatrixMode (GL_TEXTURE);
 
727
        qglLoadIdentity ();
 
728
 
 
729
        // rotate around Y to bring blue/pink to the front
 
730
        qglRotatef (145, 0, 1, 0);
 
731
 
 
732
        // now reposition so that the bright spot is center screen
 
733
        qglRotatef (-45, 1, 0, 0);
 
734
        qglRotatef (-45, 0, 0, 1);
 
735
 
 
736
        // rotate by viewangles  
 
737
        qglRotatef (-r_newrefdef.viewangles[2], 1, 0, 0);
 
738
        qglRotatef (-r_newrefdef.viewangles[0], 0, 1, 0);
 
739
        qglRotatef (-r_newrefdef.viewangles[1], 0, 0, 1);
 
740
 
 
741
        //now rotate according to dynamic lights
 
742
        VectorClear(lightAdd);
 
743
        dl = r_newrefdef.dlights;
 
744
        for (lnum=0; lnum<r_newrefdef.num_dlights; lnum++, dl++)
 
745
        {
 
746
 
 
747
                VectorSubtract (r_newrefdef.vieworg, dl->origin, angle);
 
748
                add = sqrt(dl->intensity - VectorLength(angle));
 
749
                VectorNormalize(angle);
 
750
                if (add > 0)
 
751
                {
 
752
                        VectorScale(angle, add, angle);
 
753
                        VectorAdd (lightAdd, angle, lightAdd);
 
754
                }
 
755
        }
 
756
        qglRotatef (-lightAdd[2], 1, 0, 0);
 
757
        qglRotatef (-lightAdd[0], 0, 1, 0);
 
758
        qglRotatef (-lightAdd[1], 0, 0, 1);
 
759
 
 
760
        // the next 2 statements will move the cmstr calculations into hardware so that we don;t
 
761
        // have to evaluate them once per vert...
 
762
 
 
763
        // translate after rotation
 
764
        qglTranslatef (r_newrefdef.vieworg[0], r_newrefdef.vieworg[1], r_newrefdef.vieworg[2]);
 
765
 
 
766
        // now flip everything by -1 again to mimic the software calculation
 
767
        // we won't bother batching this part up...
 
768
        qglScalef (-1, -1, -1);
 
769
 
 
770
        qglMatrixMode (GL_MODELVIEW);
 
771
 
 
772
        // basic replace texenv
 
773
        qglTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
 
774
}
 
775
 
 
776
static void R_DrawNormalSurfaces (void)
 
777
{
 
778
        msurface_t *surf = r_normalsurfaces;
 
779
        int             i;
 
780
        float   *v;
 
781
        glpoly_t *p;
 
782
 
 
783
        // nothing to draw!
 
784
        if (!surf)
 
785
                return;
 
786
 
 
787
        if (!gl_normalmaps->value)
 
788
                return;
 
789
 
 
790
        R_InitNormalSurfaces();
 
791
 
 
792
        qglActiveTextureARB (GL_TEXTURE1);
 
793
        qglEnable (GL_TEXTURE_2D);
 
794
 
 
795
        qglTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
 
796
        qglTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_DOT3_RGB);
 
797
        qglTexEnvi (GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PREVIOUS_ARB);
 
798
        qglTexEnvi (GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_TEXTURE);
 
799
        qglTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);
 
800
        qglTexEnvi (GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR);
 
801
 
 
802
        qglEnable (GL_BLEND); 
 
803
 
 
804
        // set the correct blending mode for normal maps 
 
805
        qglBlendFunc (GL_ZERO, GL_SRC_COLOR); 
 
806
        
 
807
        for (; surf; surf = surf->normalchain)
 
808
        {
 
809
                if (SurfaceIsAlphaBlended(surf))
 
810
                        continue;
 
811
                if(strcmp(surf->texinfo->normalMap->name, surf->texinfo->image->name))
 
812
                        qglBindTexture (GL_TEXTURE_2D, surf->texinfo->normalMap->texnum);
 
813
                else
 
814
                        continue;
 
815
 
 
816
                for (p = surf->polys; p; p = p->chain)
 
817
                {
 
818
                        qglBegin (GL_POLYGON);
 
819
 
 
820
                        for (v = p->verts[0], i = 0 ; i < p->numverts; i++, v += VERTEXSIZE)
 
821
                        {               
 
822
                                qglMTexCoord3fSGIS(GL_TEXTURE0, v[0], v[1], v[2]);
 
823
                                qglMTexCoord2fSGIS(GL_TEXTURE1, v[3], v[4]);
 
824
                                qglVertex3fv (v);
 
825
                        }
 
826
 
 
827
                        qglEnd ();
 
828
                }
 
829
        }
 
830
 
 
831
        //kill TMU1
 
832
        qglActiveTextureARB (GL_TEXTURE1);
 
833
        qglTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
 
834
        qglDisable (GL_TEXTURE_2D);
 
835
 
 
836
        //kill TMU0
 
837
        qglActiveTextureARB (GL_TEXTURE0);
 
838
        qglMatrixMode (GL_TEXTURE);
 
839
        qglLoadIdentity ();
 
840
        qglMatrixMode (GL_MODELVIEW);
 
841
        qglDisable (GL_TEXTURE_CUBE_MAP_ARB);
 
842
        qglEnable (GL_TEXTURE_2D);
 
843
 
 
844
        // restore original blend
 
845
        qglTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
 
846
        qglBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
 
847
        qglDisable (GL_BLEND);
 
848
}
 
849
static void R_DrawSpecularSurfaces (void)
 
850
{
 
851
        msurface_t *surf = r_specularsurfaces;
 
852
        int             i;
 
853
        float   *v;
 
854
        glpoly_t *p;
 
855
 
 
856
        // nothing to draw!
 
857
        if (!surf)
 
858
                return;
 
859
 
 
860
        if (!gl_normalmaps->value || !gl_specularmaps->value)
 
861
                return;
 
862
 
 
863
        R_InitNormalSurfaces();
 
864
 
 
865
        qglActiveTextureARB (GL_TEXTURE1);
 
866
        qglEnable (GL_TEXTURE_2D);
 
867
        qglTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
 
868
 
 
869
        qglDepthMask (GL_FALSE); 
 
870
        qglEnable (GL_BLEND); 
 
871
        qglBlendFunc (GL_ONE, GL_ONE);
 
872
        
 
873
        for (; surf; surf = surf->specularchain)
 
874
        {
 
875
                if (SurfaceIsAlphaBlended(surf))
 
876
                        continue;
 
877
                if(strcmp(surf->texinfo->specularMap->name, surf->texinfo->image->name))
 
878
                        qglBindTexture (GL_TEXTURE_2D, surf->texinfo->specularMap->texnum);
 
879
                else
 
880
                        continue;
 
881
 
 
882
                for (p = surf->polys; p; p = p->chain)
 
883
                {
 
884
                        qglBegin (GL_POLYGON);
 
885
 
 
886
                        for (v = p->verts[0], i = 0 ; i < p->numverts; i++, v += VERTEXSIZE)
 
887
                        {                       
 
888
                                qglMTexCoord3fSGIS(GL_TEXTURE0, v[0], v[1], v[2]);
 
889
                                qglMTexCoord2fSGIS(GL_TEXTURE1, v[3], v[4]);
 
890
                                qglVertex3fv (v);
 
891
                        }
 
892
 
 
893
                        qglEnd ();
 
894
                }
 
895
        }
 
896
 
 
897
                //kill TMU1
 
898
        qglActiveTextureARB (GL_TEXTURE1);
 
899
        qglTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
 
900
        qglDisable (GL_TEXTURE_2D);
 
901
 
 
902
        //kill TMU0
 
903
        qglActiveTextureARB (GL_TEXTURE0);
 
904
        qglMatrixMode (GL_TEXTURE);
 
905
        qglLoadIdentity ();
 
906
        qglMatrixMode (GL_MODELVIEW);
 
907
        qglDisable (GL_TEXTURE_CUBE_MAP_ARB);
 
908
        qglEnable (GL_TEXTURE_2D);
 
909
 
 
910
        // restore original blend
 
911
        qglDepthMask (GL_TRUE);
 
912
        qglTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
 
913
        qglBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
 
914
        qglDisable (GL_BLEND);
 
915
}
818
916
/*
819
917
=================
820
918
R_DrawInlineBModel
836
934
                GL_TexEnv( GL_MODULATE );
837
935
        }
838
936
 
839
 
        // MH - detail textures begin
840
 
        // null the detail chain again
841
 
        r_detailsurfaces = NULL;
842
 
        // MH - detail textures end
843
 
 
 
937
        r_normalsurfaces = NULL;
 
938
        r_specularsurfaces = NULL;
 
939
 
844
940
        //
845
941
        // draw texture
846
942
        //
858
954
                        if (SurfaceIsTranslucent(psurf) && !SurfaceIsAlphaBlended(psurf))
859
955
                        {       // add to the translucent chain
860
956
                                psurf->texturechain = r_alpha_surfaces;
861
 
                                r_alpha_surfaces = psurf;
 
957
                                r_alpha_surfaces = psurf;
862
958
                                psurf->entity = e;
863
959
                        }
864
960
                        else if ( qglMTexCoord2fSGIS && !( psurf->flags & SURF_DRAWTURB ) )
878
974
 
879
975
        if ( !(currententity->flags & RF_TRANSLUCENT) )
880
976
        {
881
 
                if ( !qglMTexCoord2fSGIS )
 
977
                if ( !qglMTexCoord2fSGIS ) {
882
978
                        R_BlendLightmaps ();
883
979
 
884
 
                // MH - detail textures begin
885
 
                // shut down multitexturing (we can't do this in R_DrawDetailSurfaces cos then it
886
 
                // messes things up for the world)
887
 
                GL_EnableMultitexture (false);
888
 
 
889
 
                // don't put them on translucent surfs
890
 
                R_DrawDetailSurfaces ();
891
 
 
892
 
                // bring multitexturing back up
893
 
                GL_EnableMultitexture (true);
894
 
                // MH - detail textures end
 
980
                        GL_EnableMultitexture (true);
 
981
                        R_DrawNormalSurfaces ();
 
982
                        R_DrawSpecularSurfaces ();
 
983
                        GL_EnableMultitexture (false);
 
984
                }
 
985
 
895
986
        }
896
987
        else
897
988
        {
989
1080
 
990
1081
        GL_EnableMultitexture( true );
991
1082
        GL_SelectTexture( GL_TEXTURE0);
992
 
 
 
1083
 
993
1084
        // Vic - begin
994
1085
        if ( !gl_config.mtexcombine ) {
995
1086
 
998
1089
 
999
1090
                if ( gl_lightmap->value )
1000
1091
                        GL_TexEnv( GL_REPLACE );
1001
 
                else 
 
1092
                else
1002
1093
                        GL_TexEnv( GL_MODULATE );
1003
1094
 
1004
1095
        } else {
1072
1163
                for (i=0,clipplane=frustum ; i<4 ; i++,clipplane++)
1073
1164
                {
1074
1165
                        clipped = BoxOnPlaneSide (node->minmaxs, node->minmaxs+3, clipplane);
1075
 
                        
 
1166
 
1076
1167
                        if (clipped == 1)
1077
1168
                                clipflags &= ~(1<<i);   // node is entirely on screen
1078
1169
                        else if (clipped == 2)
1079
1170
                                return;                                 // fully clipped
1080
1171
                }
1081
1172
        }
1082
 
        
 
1173
 
1083
1174
// if a leaf node, draw stuff
1084
1175
        if (node->contents != -1)
1085
1176
        {
1154
1245
                else if (SurfaceIsTranslucent(surf) && !SurfaceIsAlphaBlended(surf))
1155
1246
                {       // add to the translucent chain
1156
1247
                        surf->texturechain = r_alpha_surfaces;
1157
 
                        r_alpha_surfaces = surf;
 
1248
                        r_alpha_surfaces = surf;
1158
1249
                        surf->entity = NULL;
1159
1250
                }
1160
1251
                else
1205
1296
 
1206
1297
        VectorCopy (r_newrefdef.vieworg, modelorg);
1207
1298
 
1208
 
        if (g_drawing_refl) // jitwater / MPO
 
1299
        if (g_drawing_refl) // jitwater / MPO
1209
1300
                modelorg[2] = (2.0f * g_refl_Z[g_active_refl]) - modelorg[2]; // flip
1210
1301
 
1211
1302
        // auto cycle the world frame for texture animation
1217
1308
 
1218
1309
        qglColor3f (1,1,1);
1219
1310
        memset (gl_lms.lightmap_surfaces, 0, sizeof(gl_lms.lightmap_surfaces));
1220
 
 
1221
 
        R_ClearSkyBox ();
1222
1311
 
1223
 
        // MH - detail textures begin
1224
 
        r_detailsurfaces = NULL;
1225
 
        // MH - detail textures end
 
1312
        r_normalsurfaces = NULL;
 
1313
        r_specularsurfaces = NULL;
 
1314
 
 
1315
        R_ClearSkyBox ();
1226
1316
 
1227
1317
        if ( qglMTexCoord2fSGIS )
1228
1318
        {
1229
1319
                GL_EnableMultitexture( true );
1230
1320
 
1231
1321
                GL_SelectTexture( GL_TEXTURE0);
1232
 
                
 
1322
 
1233
1323
                // Vic - begin
1234
1324
                if ( !gl_config.mtexcombine ) {
1235
1325
                        GL_TexEnv( GL_REPLACE );
1237
1327
 
1238
1328
                        if ( gl_lightmap->value )
1239
1329
                                GL_TexEnv( GL_REPLACE );
1240
 
                        else 
 
1330
                        else
1241
1331
                                GL_TexEnv( GL_MODULATE );
1242
1332
                } else {
1243
1333
                        GL_TexEnv ( GL_COMBINE_EXT );
1282
1372
        ** if multitexture is enabled
1283
1373
        */
1284
1374
        DrawTextureChains ();
1285
 
        R_BlendLightmaps ();
 
1375
        R_BlendLightmaps ();
1286
1376
 
1287
 
        // MH - detail textures begin
1288
 
        R_DrawDetailSurfaces ();
1289
 
        // MH - detail textures end
1290
 
        
 
1377
        GL_EnableMultitexture( true );
 
1378
        R_DrawNormalSurfaces ();
 
1379
        R_DrawSpecularSurfaces ();
 
1380
        GL_EnableMultitexture( false ); 
 
1381
 
1291
1382
        R_DrawSkyBox ();
1292
1383
 
1293
1384
        R_DrawTriangleOutlines ();
1344
1435
                        ((int *)fatvis)[i] |= ((int *)vis)[i];
1345
1436
                vis = fatvis;
1346
1437
        }
1347
 
        
 
1438
 
1348
1439
        for (i=0,leaf=r_worldmodel->leafs ; i<r_worldmodel->numleafs ; i++, leaf++)
1349
1440
        {
1350
1441
                cluster = leaf->cluster;
1407
1498
                                height = gl_lms.allocated[i];
1408
1499
                }
1409
1500
 
1410
 
                qglTexSubImage2D( GL_TEXTURE_2D, 
 
1501
                qglTexSubImage2D( GL_TEXTURE_2D,
1411
1502
                                                  0,
1412
1503
                                                  0, 0,
1413
1504
                                                  BLOCK_WIDTH, height,
1417
1508
        }
1418
1509
        else
1419
1510
        {
1420
 
                qglTexImage2D( GL_TEXTURE_2D, 
1421
 
                                           0, 
 
1511
                qglTexImage2D( GL_TEXTURE_2D,
 
1512
                                           0,
1422
1513
                                           gl_lms.internal_format,
1423
 
                                           BLOCK_WIDTH, BLOCK_HEIGHT, 
1424
 
                                           0, 
1425
 
                                           GL_LIGHTMAP_FORMAT, 
1426
 
                                           GL_UNSIGNED_BYTE, 
 
1514
                                           BLOCK_WIDTH, BLOCK_HEIGHT,
 
1515
                                           0,
 
1516
                                           GL_LIGHTMAP_FORMAT,
 
1517
                                           GL_UNSIGNED_BYTE,
1427
1518
                                           gl_lms.lightmap_buffer );
1428
1519
                if ( ++gl_lms.current_lightmap_texture == MAX_LIGHTMAPS )
1429
1520
                        Com_Error( ERR_DROP, "LM_UploadBlock() - MAX_LIGHTMAPS exceeded\n" );
1532
1623
                poly->verts[i][5] = s;
1533
1624
                poly->verts[i][6] = t;
1534
1625
 
1535
 
                // MH - detail textures begin
1536
 
                // here we build a set of texture s and t co-ords suitable for a 128 * 128 version
1537
 
                // of the texture.  this is necessary because using the original texture s and t
1538
 
                // will cause the detail texture (and anything else we may ever consider adding)
1539
 
                // to rescale itself to the same aspect ratio as the original texture, which looks
1540
 
                // bad.  NOTE - to enable this we *must* increase the define of VERTEXSIZE to 9.
1541
1626
                s = DotProduct (vec, fa->texinfo->vecs[0]) + fa->texinfo->vecs[0][3];
1542
1627
                s /= 128;
1543
1628
 
1544
1629
                t = DotProduct (vec, fa->texinfo->vecs[1]) + fa->texinfo->vecs[1][3];
1545
1630
                t /= 128;
1546
1631
 
1547
 
                // and load them in
1548
1632
                poly->verts[i][7] = s;
1549
1633
                poly->verts[i][8] = t;
1550
 
                // MH - detail textures end
1551
1634
        }
1552
1635
}
1553
1636
 
1645
1728
 
1646
1729
        gl_lms.current_lightmap_texture = 1;
1647
1730
 
1648
 
        /*
1649
 
        ** if mono lightmaps are enabled and we want to use alpha
1650
 
        ** blending (a,1-a) then we're likely running on a 3DLabs
1651
 
        ** Permedia2.  In a perfect world we'd use a GL_ALPHA lightmap
1652
 
        ** in order to conserve space and maximize bandwidth, however 
1653
 
        ** this isn't a perfect world.
1654
 
        **
1655
 
        ** So we have to use alpha lightmaps, but stored in GL_RGBA format,
1656
 
        ** which means we only get 1/16th the color resolution we should when
1657
 
        ** using alpha lightmaps.  If we find another board that supports
1658
 
        ** only alpha lightmaps but that can at least support the GL_ALPHA
1659
 
        ** format then we should change this code to use real alpha maps.
1660
 
        */
1661
 
        if ( toupper( gl_monolightmap->string[0] ) == 'A' )
1662
 
        {
1663
 
                gl_lms.internal_format = gl_tex_alpha_format;
1664
 
        }
1665
 
        /*
1666
 
        ** try to do hacked colored lighting with a blended texture
1667
 
        */
1668
 
        else if ( toupper( gl_monolightmap->string[0] ) == 'C' )
1669
 
        {
1670
 
                gl_lms.internal_format = gl_tex_alpha_format;
1671
 
        }
1672
 
        else if ( toupper( gl_monolightmap->string[0] ) == 'I' )
1673
 
        {
1674
 
                gl_lms.internal_format = GL_INTENSITY8;
1675
 
        }
1676
 
        else if ( toupper( gl_monolightmap->string[0] ) == 'L' ) 
1677
 
        {
1678
 
                gl_lms.internal_format = GL_LUMINANCE8;
1679
 
        }
1680
 
        else
1681
 
        {
1682
 
                gl_lms.internal_format = gl_tex_solid_format;
1683
 
        }
 
1731
        gl_lms.internal_format = gl_tex_solid_format;
1684
1732
 
1685
1733
        /*
1686
1734
        ** initialize the dynamic lightmap texture
1688
1736
        GL_Bind( gl_state.lightmap_textures + 0 );
1689
1737
        qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1690
1738
        qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1691
 
        qglTexImage2D( GL_TEXTURE_2D, 
1692
 
                                   0, 
 
1739
        qglTexImage2D( GL_TEXTURE_2D,
 
1740
                                   0,
1693
1741
                                   gl_lms.internal_format,
1694
 
                                   BLOCK_WIDTH, BLOCK_HEIGHT, 
1695
 
                                   0, 
1696
 
                                   GL_LIGHTMAP_FORMAT, 
1697
 
                                   GL_UNSIGNED_BYTE, 
 
1742
                                   BLOCK_WIDTH, BLOCK_HEIGHT,
 
1743
                                   0,
 
1744
                                   GL_LIGHTMAP_FORMAT,
 
1745
                                   GL_UNSIGNED_BYTE,
1698
1746
                                   dummy );
1699
1747
}
1700
1748
 
1709
1757
        GL_EnableMultitexture( false );
1710
1758
}
1711
1759
 
1712
 
/*
1713
 
========================
1714
 
GLOOM MINI MAP !!!
1715
 
draw with vertex array 
1716
 
and ower speedup changes
1717
 
========================
1718
 
*/
1719
 
 
1720
 
 
1721
 
//sul's minimap thing
1722
 
void R_RecursiveRadarNode (mnode_t *node)
1723
 
{
1724
 
        int                     c, side, sidebit;
1725
 
        cplane_t        *plane;
1726
 
        msurface_t      *surf, **mark;
1727
 
        mleaf_t         *pleaf;
1728
 
        float           dot,distance;
1729
 
        glpoly_t        *p;
1730
 
        float           *v;
1731
 
        int                     i;
1732
 
 
1733
 
        if (node->contents == CONTENTS_SOLID)   return;         // solid
1734
 
 
1735
 
        if(r_minimap_zoom->value>=0.1) {
1736
 
                distance = 1024.0/r_minimap_zoom->value;
1737
 
        } else {
1738
 
                distance = 1024.0;
1739
 
        }
1740
 
 
1741
 
        if ( r_origin[0]+distance < node->minmaxs[0] ||
1742
 
                 r_origin[0]-distance > node->minmaxs[3] ||
1743
 
                 r_origin[1]+distance < node->minmaxs[1] ||
1744
 
                 r_origin[1]-distance > node->minmaxs[4] ||
1745
 
                 r_origin[2]+256 < node->minmaxs[2] ||
1746
 
                 r_origin[2]-256 > node->minmaxs[5]) return;
1747
 
  
1748
 
        // if a leaf node, draw stuff
1749
 
        if (node->contents != -1) {
1750
 
                pleaf = (mleaf_t *)node;
1751
 
                // check for door connected areas
1752
 
                if (r_newrefdef.areabits) {
1753
 
                        // not visible
1754
 
                        if (! (r_newrefdef.areabits[pleaf->area>>3] & (1<<(pleaf->area&7)) ) ) return;
1755
 
                }
1756
 
                mark = pleaf->firstmarksurface;
1757
 
                c = pleaf->nummarksurfaces;
1758
 
 
1759
 
                if (c) {
1760
 
                        do {
1761
 
                                (*mark)->visframe = r_framecount;
1762
 
                                mark++;
1763
 
                        } while (--c);
1764
 
                }
1765
 
                return;
1766
 
        }
1767
 
 
1768
 
// node is just a decision point, so go down the apropriate sides
1769
 
// find which side of the node we are on
1770
 
        plane = node->plane;  
1771
 
 
1772
 
        switch (plane->type) {
1773
 
        case PLANE_X:
1774
 
                dot = modelorg[0] - plane->dist;
1775
 
                break;
1776
 
        case PLANE_Y:
1777
 
                dot = modelorg[1] - plane->dist;
1778
 
                break;
1779
 
        case PLANE_Z:
1780
 
                dot = modelorg[2] - plane->dist;
1781
 
                break;
1782
 
        default:
1783
 
                dot = DotProduct (modelorg, plane->normal) - plane->dist;
1784
 
                break;
1785
 
        }
1786
 
 
1787
 
        if (dot >= 0) {
1788
 
                side = 0;
1789
 
                sidebit = 0;
1790
 
        } else {
1791
 
                side = 1;
1792
 
                sidebit = SURF_PLANEBACK;
1793
 
        }
1794
 
 
1795
 
// recurse down the children, front side first
1796
 
        R_RecursiveRadarNode (node->children[side]);
1797
 
 
1798
 
  if(plane->normal[2]) {      
1799
 
                // draw stuff    
1800
 
                if(plane->normal[2]>0) for ( c = node->numsurfaces, surf = r_worldmodel->surfaces + node->firstsurface; c ; c--, surf++)
1801
 
                {
1802
 
                        if (surf->texinfo->flags & SURF_SKY){
1803
 
                                continue;
1804
 
                        }
1805
 
                
1806
 
 
1807
 
                }
1808
 
        } else {
1809
 
                        qglDisable(GL_TEXTURE_2D);
1810
 
                for ( c = node->numsurfaces, surf = r_worldmodel->surfaces + node->firstsurface; c ; c--, surf++) {
1811
 
                        float sColor,C[4];
1812
 
                        if (surf->texinfo->flags & SURF_SKY) continue;
1813
 
                        
1814
 
                        if (surf->texinfo->flags & (SURF_WARP|SURF_FLOWING|SURF_TRANS33|SURF_TRANS66)) {
1815
 
                                sColor=0.5;
1816
 
                        } else {
1817
 
                                sColor=0;
1818
 
                        }
1819
 
                      
1820
 
                        for ( p = surf->polys; p; p = p->chain ) {
1821
 
                                v = p->verts[0];      
1822
 
                                qglBegin(GL_LINE_STRIP);
1823
 
                                for (i=0 ; i< p->numverts; i++, v+= VERTEXSIZE) {
1824
 
                                        C[3]= (v[2]-r_origin[2])/512.0;        
1825
 
                                        if (C[3]>0) {     
1826
 
                                                        
1827
 
                                                C[0]=0.5;
1828
 
                                                C[1]=0.5+sColor;
1829
 
                                                C[2]=0.5;
1830
 
                                                C[3]=1-C[3]; 
1831
 
                      
1832
 
                                        }
1833
 
                                           else 
1834
 
                                        {  
1835
 
                                                C[0]=0.5;
1836
 
                                                C[1]=sColor;
1837
 
                                                C[2]=0;
1838
 
                                                C[3]+=1;
1839
 
                                                
1840
 
                                        }
1841
 
 
1842
 
                                        if(C[3]<0) {
1843
 
                                                C[3]=0;  
1844
 
                                                
1845
 
                                        }
1846
 
                                        qglColor4fv(C);
1847
 
                                        qglVertex3fv (v);       
1848
 
                                }
1849
 
                                                                
1850
 
                                qglEnd();
1851
 
                        }             
1852
 
                }
1853
 
                qglEnable(GL_TEXTURE_2D);
1854
 
        
1855
 
  }
1856
 
        // recurse down the back side
1857
 
        R_RecursiveRadarNode (node->children[!side]);
1858
 
 
1859
 
        
1860
 
}
1861
 
 
1862
 
 
1863
 
 
1864
 
int                     numRadarEnts=0;
1865
 
RadarEnt_t      RadarEnts[MAX_RADAR_ENTS];
1866
 
 
1867
 
void GL_DrawRadar(void)
1868
 
{  
1869
 
        int             i;
1870
 
        float   fS[4]={0,0,-1.0/512.0,0};  
1871
 
    
1872
 
        if ( r_newrefdef.rdflags & RDF_NOWORLDMODEL ) return;
1873
 
        if(!r_minimap->value) return;
1874
 
 
1875
 
        qglViewport (vid.width-r_minimap_size->value,0, r_minimap_size->value, r_minimap_size->value);  
1876
 
        
1877
 
        qglDisable(GL_DEPTH_TEST);
1878
 
        qglMatrixMode(GL_PROJECTION);
1879
 
        qglPushMatrix();
1880
 
        qglLoadIdentity ();         
1881
 
 
1882
 
        
1883
 
        if (r_minimap_style->value) {
1884
 
                qglOrtho(-1024,1024,-1024,1024,-256,256);
1885
 
        } else {
1886
 
                qglOrtho(-1024,1024,-512,1536,-256,256);
1887
 
        }
1888
 
 
1889
 
        qglMatrixMode(GL_MODELVIEW);  
1890
 
        qglPushMatrix();  
1891
 
        qglLoadIdentity ();
1892
 
 
1893
 
        
1894
 
                {
1895
 
                qglStencilMask(255);
1896
 
                qglClear(GL_STENCIL_BUFFER_BIT);
1897
 
                qglEnable(GL_STENCIL_TEST);
1898
 
                qglStencilFunc(GL_ALWAYS,4,4);
1899
 
                qglStencilOp(GL_KEEP,GL_KEEP,GL_REPLACE);
1900
 
 
1901
 
          
1902
 
                GLSTATE_ENABLE_ALPHATEST;
1903
 
                qglAlphaFunc(GL_LESS,0.1);
1904
 
                qglColorMask(0,0,0,0);
1905
 
            
1906
 
                qglColor4f(1,1,1,1);
1907
 
                if(r_around)
1908
 
                        GL_Bind(r_around->texnum);
1909
 
                qglBegin(GL_TRIANGLE_FAN);
1910
 
                if (r_minimap_style->value){
1911
 
                        qglTexCoord2f(0,1); qglVertex3f(1024,-1024,1);
1912
 
                        qglTexCoord2f(1,1); qglVertex3f(-1024,-1024,1);
1913
 
                        qglTexCoord2f(1,0); qglVertex3f(-1024,1024,1);
1914
 
                        qglTexCoord2f(0,0); qglVertex3f(1024,1024,1);
1915
 
                } else {
1916
 
                        qglTexCoord2f(0,1); qglVertex3f(1024,-512,1);
1917
 
                        qglTexCoord2f(1,1); qglVertex3f(-1024,-512,1);
1918
 
                        qglTexCoord2f(1,0); qglVertex3f(-1024,1536,1);
1919
 
                        qglTexCoord2f(0,0); qglVertex3f(1024,1536,1);
1920
 
                }
1921
 
                qglEnd();    
1922
 
 
1923
 
                qglColorMask(1,1,1,1);
1924
 
                GLSTATE_DISABLE_ALPHATEST;
1925
 
                qglAlphaFunc(GL_GREATER, 0.5);
1926
 
                qglStencilOp(GL_KEEP,GL_KEEP,GL_REPLACE);
1927
 
                qglStencilFunc(GL_NOTEQUAL,4,4);
1928
 
 
1929
 
        }
1930
 
 
1931
 
        if(r_minimap_zoom->value>=0.1) {
1932
 
                qglScalef(r_minimap_zoom->value,r_minimap_zoom->value,r_minimap_zoom->value); 
1933
 
        }
1934
 
 
1935
 
        if (r_minimap_style->value) {
1936
 
                qglPushMatrix();  
1937
 
                qglRotatef (90-r_newrefdef.viewangles[1],  0, 0, -1);        
1938
 
                
1939
 
                qglDisable(GL_TEXTURE_2D);
1940
 
                qglBegin(GL_TRIANGLES);  
1941
 
                qglColor4f(1,1,1,0.5);
1942
 
                qglVertex3f(0,32,0);
1943
 
                qglColor4f(1,1,0,0.5);
1944
 
                qglVertex3f(24,-32,0);
1945
 
                qglVertex3f(-24,-32,0);
1946
 
                qglEnd();
1947
 
                
1948
 
                qglPopMatrix();  
1949
 
        } else {
1950
 
                qglDisable(GL_TEXTURE_2D);
1951
 
                qglBegin(GL_TRIANGLES);  
1952
 
                qglColor4f(1,1,1,0.5);
1953
 
                qglVertex3f(0,32,0);
1954
 
                qglColor4f(1,1,0,0.5);
1955
 
                qglVertex3f(24,-32,0);
1956
 
                qglVertex3f(-24,-32,0);
1957
 
                qglEnd();
1958
 
 
1959
 
                qglRotatef (90-r_newrefdef.viewangles[1],  0, 0, 1);        
1960
 
        }
1961
 
        qglTranslatef (-r_newrefdef.vieworg[0],  -r_newrefdef.vieworg[1],  -r_newrefdef.vieworg[2]);  
1962
 
 
1963
 
        qglBegin(GL_QUADS);
1964
 
        for(i=0;i<numRadarEnts;i++){
1965
 
                float x=RadarEnts[i].org[0];
1966
 
                float y=RadarEnts[i].org[1];
1967
 
                float z=RadarEnts[i].org[2];
1968
 
                qglColor4fv(RadarEnts[i].color);    
1969
 
                
1970
 
                qglVertex3f(x+9, y+9, z);
1971
 
                qglVertex3f(x+9, y-9, z);
1972
 
                qglVertex3f(x-9, y-9, z);
1973
 
                qglVertex3f(x-9, y+9, z);
1974
 
        }  
1975
 
        qglEnd();
1976
 
 
1977
 
        qglEnable(GL_TEXTURE_2D);
1978
 
          
1979
 
        if(r_radarmap)
1980
 
                GL_Bind(r_radarmap->texnum);
1981
 
        qglBlendFunc(GL_SRC_ALPHA, GL_ONE);
1982
 
        GLSTATE_ENABLE_BLEND;
1983
 
        qglColor3f(1,1,1);
1984
 
          
1985
 
        fS[3]=0.5+ r_newrefdef.vieworg[2]/512.0;
1986
 
        qglTexGenf(GL_S,GL_TEXTURE_GEN_MODE,GL_OBJECT_LINEAR);
1987
 
                
1988
 
        GLSTATE_ENABLE_TEXGEN;
1989
 
        qglTexGenfv(GL_S,GL_OBJECT_PLANE,fS);
1990
 
 
1991
 
        // draw the stuff
1992
 
        R_RecursiveRadarNode (r_worldmodel->nodes);  
1993
 
 
1994
 
        qglBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
1995
 
        GLSTATE_DISABLE_TEXGEN;
1996
 
 
1997
 
        qglPopMatrix();
1998
 
    
1999
 
        qglViewport(0,0,vid.width,vid.height);
2000
 
          
2001
 
        qglMatrixMode(GL_PROJECTION);
2002
 
        qglPopMatrix();
2003
 
        qglMatrixMode(GL_MODELVIEW);
2004
 
        qglDisable(GL_STENCIL_TEST);
2005
 
        GL_TexEnv( GL_REPLACE );
2006
 
        GLSTATE_DISABLE_BLEND;
2007
 
        qglEnable(GL_DEPTH_TEST);
2008
 
    qglColor4f(1,1,1,1);
2009
 
 
2010
 
}
2011
 
 
 
1760
/*
 
1761
========================
 
1762
GLOOM MINI MAP !!!
 
1763
draw with vertex array
 
1764
and ower speedup changes
 
1765
========================
 
1766
*/
 
1767
 
 
1768
 
 
1769
//sul's minimap thing
 
1770
void R_RecursiveRadarNode (mnode_t *node)
 
1771
{
 
1772
        int                     c, side, sidebit;
 
1773
        cplane_t        *plane;
 
1774
        msurface_t      *surf, **mark;
 
1775
        mleaf_t         *pleaf;
 
1776
        float           dot,distance;
 
1777
        glpoly_t        *p;
 
1778
        float           *v;
 
1779
        int                     i;
 
1780
 
 
1781
        if (node->contents == CONTENTS_SOLID)   return;         // solid
 
1782
 
 
1783
        if(r_minimap_zoom->value>=0.1) {
 
1784
                distance = 1024.0/r_minimap_zoom->value;
 
1785
        } else {
 
1786
                distance = 1024.0;
 
1787
        }
 
1788
 
 
1789
        if ( r_origin[0]+distance < node->minmaxs[0] ||
 
1790
                 r_origin[0]-distance > node->minmaxs[3] ||
 
1791
                 r_origin[1]+distance < node->minmaxs[1] ||
 
1792
                 r_origin[1]-distance > node->minmaxs[4] ||
 
1793
                 r_origin[2]+256 < node->minmaxs[2] ||
 
1794
                 r_origin[2]-256 > node->minmaxs[5]) return;
 
1795
 
 
1796
        // if a leaf node, draw stuff
 
1797
        if (node->contents != -1) {
 
1798
                pleaf = (mleaf_t *)node;
 
1799
                // check for door connected areas
 
1800
                if (r_newrefdef.areabits) {
 
1801
                        // not visible
 
1802
                        if (! (r_newrefdef.areabits[pleaf->area>>3] & (1<<(pleaf->area&7)) ) ) return;
 
1803
                }
 
1804
                mark = pleaf->firstmarksurface;
 
1805
                c = pleaf->nummarksurfaces;
 
1806
 
 
1807
                if (c) {
 
1808
                        do {
 
1809
                                (*mark)->visframe = r_framecount;
 
1810
                                mark++;
 
1811
                        } while (--c);
 
1812
                }
 
1813
                return;
 
1814
        }
 
1815
 
 
1816
// node is just a decision point, so go down the apropriate sides
 
1817
// find which side of the node we are on
 
1818
        plane = node->plane;
 
1819
 
 
1820
        switch (plane->type) {
 
1821
        case PLANE_X:
 
1822
                dot = modelorg[0] - plane->dist;
 
1823
                break;
 
1824
        case PLANE_Y:
 
1825
                dot = modelorg[1] - plane->dist;
 
1826
                break;
 
1827
        case PLANE_Z:
 
1828
                dot = modelorg[2] - plane->dist;
 
1829
                break;
 
1830
        default:
 
1831
                dot = DotProduct (modelorg, plane->normal) - plane->dist;
 
1832
                break;
 
1833
        }
 
1834
 
 
1835
        if (dot >= 0) {
 
1836
                side = 0;
 
1837
                sidebit = 0;
 
1838
        } else {
 
1839
                side = 1;
 
1840
                sidebit = SURF_PLANEBACK;
 
1841
        }
 
1842
 
 
1843
// recurse down the children, front side first
 
1844
        R_RecursiveRadarNode (node->children[side]);
 
1845
 
 
1846
  if(plane->normal[2]) {
 
1847
                // draw stuff
 
1848
                if(plane->normal[2]>0) for ( c = node->numsurfaces, surf = r_worldmodel->surfaces + node->firstsurface; c ; c--, surf++)
 
1849
                {
 
1850
                        if (surf->texinfo->flags & SURF_SKY){
 
1851
                                continue;
 
1852
                        }
 
1853
 
 
1854
 
 
1855
                }
 
1856
        } else {
 
1857
                        qglDisable(GL_TEXTURE_2D);
 
1858
                for ( c = node->numsurfaces, surf = r_worldmodel->surfaces + node->firstsurface; c ; c--, surf++) {
 
1859
                        float sColor,C[4];
 
1860
                        if (surf->texinfo->flags & SURF_SKY) continue;
 
1861
 
 
1862
                        if (surf->texinfo->flags & (SURF_WARP|SURF_FLOWING|SURF_TRANS33|SURF_TRANS66)) {
 
1863
                                sColor=0.5;
 
1864
                        } else {
 
1865
                                sColor=0;
 
1866
                        }
 
1867
 
 
1868
                        for ( p = surf->polys; p; p = p->chain ) {
 
1869
                                v = p->verts[0];
 
1870
                                qglBegin(GL_LINE_STRIP);
 
1871
                                for (i=0 ; i< p->numverts; i++, v+= VERTEXSIZE) {
 
1872
                                        C[3]= (v[2]-r_origin[2])/512.0;
 
1873
                                        if (C[3]>0) {
 
1874
 
 
1875
                                                C[0]=0.5;
 
1876
                                                C[1]=0.5+sColor;
 
1877
                                                C[2]=0.5;
 
1878
                                                C[3]=1-C[3];
 
1879
 
 
1880
                                        }
 
1881
                                           else
 
1882
                                        {
 
1883
                                                C[0]=0.5;
 
1884
                                                C[1]=sColor;
 
1885
                                                C[2]=0;
 
1886
                                                C[3]+=1;
 
1887
 
 
1888
                                        }
 
1889
 
 
1890
                                        if(C[3]<0) {
 
1891
                                                C[3]=0;
 
1892
 
 
1893
                                        }
 
1894
                                        qglColor4fv(C);
 
1895
                                        qglVertex3fv (v);
 
1896
                                }
 
1897
 
 
1898
                                qglEnd();
 
1899
                        }
 
1900
                }
 
1901
                qglEnable(GL_TEXTURE_2D);
 
1902
 
 
1903
  }
 
1904
        // recurse down the back side
 
1905
        R_RecursiveRadarNode (node->children[!side]);
 
1906
 
 
1907
 
 
1908
}
 
1909
 
 
1910
 
 
1911
 
 
1912
int                     numRadarEnts=0;
 
1913
RadarEnt_t      RadarEnts[MAX_RADAR_ENTS];
 
1914
 
 
1915
void GL_DrawRadar(void)
 
1916
{
 
1917
        int             i;
 
1918
        float   fS[4]={0,0,-1.0/512.0,0};
 
1919
 
 
1920
        if ( r_newrefdef.rdflags & RDF_NOWORLDMODEL ) return;
 
1921
        if(!r_minimap->value) return;
 
1922
 
 
1923
        qglViewport (vid.width-r_minimap_size->value,0, r_minimap_size->value, r_minimap_size->value);
 
1924
 
 
1925
        qglDisable(GL_DEPTH_TEST);
 
1926
        qglMatrixMode(GL_PROJECTION);
 
1927
        qglPushMatrix();
 
1928
        qglLoadIdentity ();
 
1929
 
 
1930
 
 
1931
        if (r_minimap_style->value) {
 
1932
                qglOrtho(-1024,1024,-1024,1024,-256,256);
 
1933
        } else {
 
1934
                qglOrtho(-1024,1024,-512,1536,-256,256);
 
1935
        }
 
1936
 
 
1937
        qglMatrixMode(GL_MODELVIEW);
 
1938
        qglPushMatrix();
 
1939
        qglLoadIdentity ();
 
1940
 
 
1941
 
 
1942
                {
 
1943
                qglStencilMask(255);
 
1944
                qglClear(GL_STENCIL_BUFFER_BIT);
 
1945
                qglEnable(GL_STENCIL_TEST);
 
1946
                qglStencilFunc(GL_ALWAYS,4,4);
 
1947
                qglStencilOp(GL_KEEP,GL_KEEP,GL_REPLACE);
 
1948
 
 
1949
 
 
1950
                GLSTATE_ENABLE_ALPHATEST;
 
1951
                qglAlphaFunc(GL_LESS,0.1);
 
1952
                qglColorMask(0,0,0,0);
 
1953
 
 
1954
                qglColor4f(1,1,1,1);
 
1955
                if(r_around)
 
1956
                        GL_Bind(r_around->texnum);
 
1957
                qglBegin(GL_TRIANGLE_FAN);
 
1958
                if (r_minimap_style->value){
 
1959
                        qglTexCoord2f(0,1); qglVertex3f(1024,-1024,1);
 
1960
                        qglTexCoord2f(1,1); qglVertex3f(-1024,-1024,1);
 
1961
                        qglTexCoord2f(1,0); qglVertex3f(-1024,1024,1);
 
1962
                        qglTexCoord2f(0,0); qglVertex3f(1024,1024,1);
 
1963
                } else {
 
1964
                        qglTexCoord2f(0,1); qglVertex3f(1024,-512,1);
 
1965
                        qglTexCoord2f(1,1); qglVertex3f(-1024,-512,1);
 
1966
                        qglTexCoord2f(1,0); qglVertex3f(-1024,1536,1);
 
1967
                        qglTexCoord2f(0,0); qglVertex3f(1024,1536,1);
 
1968
                }
 
1969
                qglEnd();
 
1970
 
 
1971
                qglColorMask(1,1,1,1);
 
1972
                GLSTATE_DISABLE_ALPHATEST;
 
1973
                qglAlphaFunc(GL_GREATER, 0.5);
 
1974
                qglStencilOp(GL_KEEP,GL_KEEP,GL_REPLACE);
 
1975
                qglStencilFunc(GL_NOTEQUAL,4,4);
 
1976
 
 
1977
        }
 
1978
 
 
1979
        if(r_minimap_zoom->value>=0.1) {
 
1980
                qglScalef(r_minimap_zoom->value,r_minimap_zoom->value,r_minimap_zoom->value);
 
1981
        }
 
1982
 
 
1983
        if (r_minimap_style->value) {
 
1984
                qglPushMatrix();
 
1985
                qglRotatef (90-r_newrefdef.viewangles[1],  0, 0, -1);
 
1986
 
 
1987
                qglDisable(GL_TEXTURE_2D);
 
1988
                qglBegin(GL_TRIANGLES);
 
1989
                qglColor4f(1,1,1,0.5);
 
1990
                qglVertex3f(0,32,0);
 
1991
                qglColor4f(1,1,0,0.5);
 
1992
                qglVertex3f(24,-32,0);
 
1993
                qglVertex3f(-24,-32,0);
 
1994
                qglEnd();
 
1995
 
 
1996
                qglPopMatrix();
 
1997
        } else {
 
1998
                qglDisable(GL_TEXTURE_2D);
 
1999
                qglBegin(GL_TRIANGLES);
 
2000
                qglColor4f(1,1,1,0.5);
 
2001
                qglVertex3f(0,32,0);
 
2002
                qglColor4f(1,1,0,0.5);
 
2003
                qglVertex3f(24,-32,0);
 
2004
                qglVertex3f(-24,-32,0);
 
2005
                qglEnd();
 
2006
 
 
2007
                qglRotatef (90-r_newrefdef.viewangles[1],  0, 0, 1);
 
2008
        }
 
2009
        qglTranslatef (-r_newrefdef.vieworg[0],  -r_newrefdef.vieworg[1],  -r_newrefdef.vieworg[2]);
 
2010
 
 
2011
        qglBegin(GL_QUADS);
 
2012
        for(i=0;i<numRadarEnts;i++){
 
2013
                float x=RadarEnts[i].org[0];
 
2014
                float y=RadarEnts[i].org[1];
 
2015
                float z=RadarEnts[i].org[2];
 
2016
                qglColor4fv(RadarEnts[i].color);
 
2017
 
 
2018
                qglVertex3f(x+9, y+9, z);
 
2019
                qglVertex3f(x+9, y-9, z);
 
2020
                qglVertex3f(x-9, y-9, z);
 
2021
                qglVertex3f(x-9, y+9, z);
 
2022
        }
 
2023
        qglEnd();
 
2024
 
 
2025
        qglEnable(GL_TEXTURE_2D);
 
2026
 
 
2027
        if(r_radarmap)
 
2028
                GL_Bind(r_radarmap->texnum);
 
2029
        qglBlendFunc(GL_SRC_ALPHA, GL_ONE);
 
2030
        GLSTATE_ENABLE_BLEND;
 
2031
        qglColor3f(1,1,1);
 
2032
 
 
2033
        fS[3]=0.5+ r_newrefdef.vieworg[2]/512.0;
 
2034
        qglTexGenf(GL_S,GL_TEXTURE_GEN_MODE,GL_OBJECT_LINEAR);
 
2035
 
 
2036
        GLSTATE_ENABLE_TEXGEN;
 
2037
        qglTexGenfv(GL_S,GL_OBJECT_PLANE,fS);
 
2038
 
 
2039
        // draw the stuff
 
2040
        R_RecursiveRadarNode (r_worldmodel->nodes);
 
2041
 
 
2042
        qglBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
 
2043
        GLSTATE_DISABLE_TEXGEN;
 
2044
 
 
2045
        qglPopMatrix();
 
2046
 
 
2047
        qglViewport(0,0,vid.width,vid.height);
 
2048
 
 
2049
        qglMatrixMode(GL_PROJECTION);
 
2050
        qglPopMatrix();
 
2051
        qglMatrixMode(GL_MODELVIEW);
 
2052
        qglDisable(GL_STENCIL_TEST);
 
2053
        GL_TexEnv( GL_REPLACE );
 
2054
        GLSTATE_DISABLE_BLEND;
 
2055
        qglEnable(GL_DEPTH_TEST);
 
2056
    qglColor4f(1,1,1,1);
 
2057
 
 
2058
}
 
2059