示例#1
0
文件: 3dfx.c 项目: gameplayer22/d2x-1
int _3dfx_LoadTextureFromDisk( const char *name, int index )
{
   Gu3dfInfo info;
   int       success_or_fail = 0;

   if ( gu3dfGetInfo( name, &info ) )
   {
      _3dfx_texture_info[index].flags = 0;

      if ( info.header.large_lod != GR_LOD_64 )
      {
         goto done;
      }

      if ( info.header.aspect_ratio != GR_ASPECT_1x1 )
      {
         goto done;
      }

      #ifdef malloc
      #  undef malloc
      #endif
      info.data = ( void * ) malloc( info.mem_required );

      if ( info.data == 0 )
      {
         mprintf( ( 0, "info.data == 0\n" ) );
         goto done;
      }

      if ( !gu3dfLoad( name, &info ) )
      {
         mprintf( ( 0, "couldn't gu3dfLoad() '%s'\n", name ) );
         free( info.data );
         goto done;
      }

      _3dfx_texture_info[index].data         = info.data;
      _3dfx_texture_info[index].flags        = _3DFX_TF_IN_MEMORY;
      _3dfx_texture_info[index].mem_required = info.mem_required;

      if ( info.header.format == GR_TEXFMT_ARGB_1555 )
         _3dfx_texture_info[index].flags |= _3DFX_TF_TRANSPARENT;
      else if ( info.header.format == GR_TEXFMT_ARGB_4444 )
         _3dfx_texture_info[index].flags |= ( _3DFX_TF_SUPERX | _3DFX_TF_TRANSPARENT );
   }

   success_or_fail = 1;
done:
   return success_or_fail;
}
示例#2
0
GrMipMapId_t
doTexture(char *fileName) {
  GrMipMapId_t
    ret = GR_NULL_MIPMAP_HANDLE; /* What we're giving back */
  Gu3dfInfo
    info;                       /* infomation about the 3df file*/

  if (gu3dfGetInfo(fileName, &info)) {
    if ((info.data = malloc(info.mem_required)) == NULL) {
      fprintf( stderr, "Couldn't allocate memory for %s.\n", fileName );
      grGlideShutdown();
      exit( -1 );
    }
    if (!gu3dfLoad(fileName, &info)) {
      fprintf( stderr, "Couldn't load texture file %s.\n", fileName);
      grGlideShutdown();
      exit( -1 );
    }
    ret =
      guTexAllocateMemory(
                          0, GR_MIPMAPLEVELMASK_BOTH,
                          info.header.width, info.header.height,
                          info.header.format,
                          GR_MIPMAP_NEAREST_DITHER,
                          info.header.small_lod, info.header.large_lod,
                          info.header.aspect_ratio,
                          GR_TEXTURECLAMP_WRAP, GR_TEXTURECLAMP_WRAP,
                          GR_TEXTUREFILTER_BILINEAR, GR_TEXTUREFILTER_BILINEAR,
                          0.0F,
                          FXFALSE );
    
    if (ret == GR_NULL_MIPMAP_HANDLE) {
      fprintf(stderr, "Couldn't allocate mmid for texture file %s.\n", fileName);
      grGlideShutdown();
      exit( -1 );
    }

    guTexDownloadMipMap(ret, info.data, &info.table.nccTable);

    free(info.data);
  } 
  
  return ret;

}/* doTexture */
示例#3
0
void main( int argc, char **argv )
{
  GrMipMapId_t      decal0;
  Gu3dfInfo         info;
  float
    wWidth, wHeight;
  int automate = 0;
  int i;
  char *fileName;
  GrScreenResolution_t
    screenRes = GR_RESOLUTION_800x600;

  GrVertex vtx1, vtx2, vtx3, vtx4;
  float    near_z = 2.0F;
  float    far_z  = 16.0F;

  if (argc < 2 || strstr(argv[1], "-n")) {
    fprintf(stderr, "usage:  test20 filename.3df [-n]\n");
    exit(-1);
  }
  fileName = argv[1];
  if(argc > 2)
    if(strstr(argv[2], "-n"))
      automate = 1;
    else
    {
      fprintf(stderr, "usage:  test20 filename.3df [-n]\n");
      exit(-1);
    }

  wWidth = 800.f;
  wHeight = 600.f;

  puts( "TEST20: " );
  puts( "tests loading of 3df files");
  if(!automate)
  {
    puts("Press a key to continue");
    getch();
  }

  /*
  ** set up Glide and the hardware
  */
  grGlideInit();

  if ( !grSstQueryHardware( &hwconfig ) )
  {
    fprintf( stderr, "main: grSstQueryHardware failed!\n" );
    grGlideShutdown();
    exit( -1 );
  }
  grSstSelect( 0 );

  if ( !grSstOpen( screenRes,
                   GR_REFRESH_60Hz,
                   GR_COLORFORMAT_ABGR,
                   GR_ORIGIN_LOWER_LEFT,
                   GR_SMOOTHING_ENABLE,
                   2 ) )
  {
    fprintf( stderr, "main: grSstOpen failed!\n" );
    grGlideShutdown();
    exit( -1 );
  }

  /*
  ** load up texture maps
  */
  if ( !gu3dfGetInfo( fileName, &info ) )  
  {
    fprintf(stderr, "ERROR: could not load %s\n", fileName);
    grGlideShutdown();
    exit( -1 );
  }
  else
  {
     info.data = malloc( info.mem_required );

     if ( info.data == 0 ) {
        fprintf( stderr, "out of memory for texture\n" );
        grGlideShutdown();
        exit( -1 );
     }

     if ( !gu3dfLoad( fileName, &info ) ) {
        fprintf( stderr, "could not load texture file\n" );
        grGlideShutdown();
        exit( -1 );
     }

     decal0 = guTexAllocateMemory( 0, GR_MIPMAPLEVELMASK_BOTH,
                                  info.header.width, info.header.height,
                                  info.header.format,
                                  GR_MIPMAP_NEAREST,
                                  info.header.small_lod, info.header.large_lod,
                                  info.header.aspect_ratio,
                                  GR_TEXTURECLAMP_WRAP, GR_TEXTURECLAMP_WRAP,
                                  GR_TEXTUREFILTER_BILINEAR, GR_TEXTUREFILTER_BILINEAR,
                                  0.0F,
                                  FXFALSE );
     if ( decal0 == GR_NULL_MIPMAP_HANDLE ) {
        fprintf( stderr, "could not allocate memory for lava.3df\n" );
        grGlideShutdown();
        exit( -1 );
     }
     guTexDownloadMipMap( decal0, info.data, &info.table.nccTable );
     free( info.data );
  }

  grBufferClear( 0xFFFF0000, 0, GR_WDEPTHVALUE_FARTHEST );

  guColorCombineFunction(GR_COLORCOMBINE_DECAL_TEXTURE);

  guTexSource( decal0 );

  grTexCombineFunction(GR_TMU0, GR_TEXTURECOMBINE_DECAL);
 
  vtx1.x        = 160.f;
  vtx1.y        = 20.f;
  vtx1.r        = 255.f;
  vtx1.g        = 0.f;
  vtx1.b        = 0.f;
  vtx1.a        = 255.f;
  vtx1.oow = 1.f / near_z;
  vtx1.tmuvtx[0].sow = 0.f / near_z;
  vtx1.tmuvtx[0].tow = 255.f / near_z;
  
  vtx2.x        = 480.f;
  vtx2.y        = 20.f;
  vtx2.r        = 0.f;
  vtx2.g        = 255.f;
  vtx2.b        = 0.f;
  vtx2.a        = 255.f;
  vtx2.oow = 1.f / near_z;
  vtx2.tmuvtx[0].sow = 255.f / near_z;
  vtx2.tmuvtx[0].tow = 255.f / near_z;
  
  vtx3.x        = 300.f;
  vtx3.y        = 460.f;
  vtx3.r        = 0.f;
  vtx3.g        = 0.f;
  vtx3.b        = 255.f;
  vtx3.a        = 255.f;
  vtx3.oow =  1.f/ far_z;
  vtx3.tmuvtx[0].sow =  0.f/ far_z;
  vtx3.tmuvtx[0].tow = 0.f / far_z;
  
  vtx4.x        = 340.f;
  vtx4.y        = 460.f;
  vtx4.r        = 0.f;
  vtx4.g        = 0.f;
  vtx4.b        = 255.f;
  vtx4.a        = 255.f;
  vtx4.oow = 1.f / far_z;
  vtx4.tmuvtx[0].sow = 255.f / far_z;
  vtx4.tmuvtx[0].tow = 0.f / far_z;
  
  vtx1.x = WINSCALEX(vtx1.x);
  vtx1.y = WINSCALEX(vtx1.y);
  
  vtx2.x = WINSCALEX(vtx2.x);
  vtx2.y = WINSCALEX(vtx2.y);
  
  vtx3.x = WINSCALEX(vtx3.x);
  vtx3.y = WINSCALEX(vtx3.y);
  
  vtx4.x = WINSCALEX(vtx4.x);
  vtx4.y = WINSCALEX(vtx4.y);
  
  grDrawTriangle( &vtx1, &vtx2, &vtx3 );
  grDrawTriangle( &vtx3, &vtx4, &vtx2 );
  
  grBufferSwap( 1 );

  if(!automate)
  {
    printf("Press a key to end...\n");
    getch();
  }
  else
    for(i = 0; i < 700000000; i++);
  grGlideShutdown();
}
示例#4
0
void
main( int argc, char **argv ) {
  float
    minColor = 55.f,
    maxColor = 200.f;

  GrVertex
    localVerts[3],
    texVerts[4];

  float
    alpha = 192.0f,
    y_angle = 0.0f;

  int
    n,
    nTris = 0;

  FxBool
    depthBias = FXTRUE,
    blend = FXFALSE,
    texturing = FXFALSE,
    antialias = FXTRUE,
    bilinear = FXTRUE,
    render = FXTRUE,
    backbuffer = FXTRUE,
    background = FXTRUE;

  GrState
    nonBlendState, blendState;

  float
    wWidth, wHeight;

  GrScreenResolution_t
    screenRes;

  GrMipMapId_t
    triDecal,
    bgDecal;

  Gu3dfInfo
    bgInfo, triInfo;

  FxU16
    *scrnImage;

  GrColorCombineFnc_t
    ccFnc = GR_COLORCOMBINE_ITRGB;

  int
    numFrames = -1,
    frameCount = 0;

  char
    *bgFileName = NULL,
    *triFileName = NULL;
  wWidth = 640.0f;
  wHeight = 480.0f;

  screenRes = GR_RESOLUTION_640x480;

  --argc; ++argv;

  while (argc) {
    if (strstr(*argv, "320x200")) {
      wWidth = 320.0f; wHeight = 200.0f;
      screenRes = GR_RESOLUTION_320x200;
      --argc; ++argv;
    } else if (strstr(*argv, "320x240")) {
      wWidth = 320.0f; wHeight = 240.0f;
      screenRes = GR_RESOLUTION_320x240;
      --argc; ++argv;
    } else if (strstr(*argv, "400x256")) {
      wWidth = 400.0f; wHeight = 256.0f;
      screenRes = GR_RESOLUTION_400x256;
      --argc; ++argv;
    } else if (strstr(*argv, "512x384")) {
      wWidth = 512.0f; wHeight = 384.0f;
      screenRes = GR_RESOLUTION_512x384;
      --argc; ++argv;
    } else if (strstr(*argv, "640x480")) {
      wWidth = 640.0f; wHeight = 480.0f;
      screenRes = GR_RESOLUTION_640x480;
      --argc; ++argv;
    } else if (strstr(*argv, "800x600")) {
      wWidth = 800.0f; wHeight = 600.0f;
      screenRes = GR_RESOLUTION_800x600;
      --argc; ++argv;
    } else if (strstr(*argv, "856x480")) {
      wWidth = 856.0f; wHeight = 480.0f;
      screenRes = GR_RESOLUTION_856x480;
      --argc; ++argv;
    } else if (strstr(*argv, "960x720")) {
      wWidth = 960.0f; wHeight = 720.0f;
      screenRes = GR_RESOLUTION_960x720;
      --argc; ++argv;
    } else if (strstr(*argv, "640x200")) {
      wWidth = 640.f; wHeight = 200.f;
      screenRes = GR_RESOLUTION_640x200;
      --argc; ++argv;
    } else if (strstr(*argv, "640x350")) {
      wWidth = 640.f; wHeight = 350.f;
      screenRes = GR_RESOLUTION_640x350;
      --argc; ++argv;
    } else if (strstr(*argv, "640x400")) {
      wWidth = 640.f; wHeight = 400.f;
      screenRes = GR_RESOLUTION_640x400;
      --argc; ++argv;
    } else if (strstr(*argv, "bgFile")) {
      bgFileName = argv[1];
      argc-= 2; argv += 2;
    } else if (strstr(*argv, "triFile")) {
      triFileName = argv[1];
      argc-= 2; argv += 2;
    } else if (strstr(*argv, "alpha")) {
      alpha = (float)atof(argv[1]);
      argc -= 2; argv += 2;                    
    } else if (strstr(*argv, "-n")) {
      numFrames = atoi(argv[1]);
      argc -= 2; argv += 2;
    } else {
      fprintf(
              stderr,
              "Useage:  test24 [-bgFile bgfile.3ds] [-triFile triFile.3ds] [ScreenRes (i.e. 640x480 .. 960x720] [-alpha alphavalue] [-n numFrames]\n");
      exit(-1);
    }
  }

  scrnImage = malloc((int)wWidth * (int)wHeight * sizeof(FxU16));

  puts( "\ntest30:" );
  puts( "Depth Bias Level Test\n" );
  puts("press H for help\n");
  if(numFrames == -1)
  {
    puts("Press a key to continue");
    getch();
  }

  grGlideInit();

  if ( !grSstQueryHardware( &hwconfig ) )
  {
    fprintf( stderr, "main: grSstQueryHardware failed!\n" );
    grGlideShutdown();
    exit( -1 );
  }

  /* Select SST 0 */
  grSstSelect( 0 );

  /* Open up the hardware */
  if ( !grSstOpen( screenRes,
                   GR_REFRESH_60Hz,
                   GR_COLORFORMAT_ABGR,
                   GR_ORIGIN_LOWER_LEFT,
                   GR_SMOOTHING_ENABLE,
                   2 ) )
  {
    fprintf( stderr, "main: grSstOpen failed!\n" );
    grGlideShutdown();
    exit( -1 );
  }

  localVerts[0].x = 0.f;
  localVerts[0].y = 0.75f;
  localVerts[0].z = 0.0f;
  localVerts[0].tmuvtx[0].sow = 255.f;
  localVerts[0].tmuvtx[0].tow = 255.f;
  localVerts[0].oow = 1.f;  
  localVerts[0].r = maxColor;
  localVerts[0].g = minColor;
  localVerts[0].b = minColor;
  localVerts[0].a = 255.f;

  localVerts[1].x = -0.75f;
  localVerts[1].y = -0.75f;
  localVerts[1].z = 0.0f;
  localVerts[1].tmuvtx[0].sow = 0.f;
  localVerts[1].tmuvtx[0].tow = 255.f;
  localVerts[1].oow = 1.f;  
  localVerts[1].r = minColor;
  localVerts[1].g = maxColor;
  localVerts[1].b = minColor;
  localVerts[1].a = 255.f;

  localVerts[2].x = 0.75f;
  localVerts[2].y = -0.75f;
  localVerts[2].z = 0.0f;
  localVerts[2].tmuvtx[0].sow = 255.f;
  localVerts[2].tmuvtx[0].tow = 0.f;
  localVerts[2].oow = 1.f;  
  localVerts[2].r = minColor;
  localVerts[2].g = minColor;
  localVerts[2].b = maxColor;
  localVerts[2].a = 255.f;

  texVerts[0].x = 0.f;
  texVerts[0].y = 0.f;
  texVerts[0].a = 255.f;
  texVerts[0].oow = 1.f;
  texVerts[0].tmuvtx[0].sow = 0.f * texVerts[0].oow;
  texVerts[0].tmuvtx[0].tow = 255.f * texVerts[0].oow;

  texVerts[1].x = wWidth;
  texVerts[1].y = 0.f;
  texVerts[1].a = 255.f;
  texVerts[1].oow = 1.f;
  texVerts[1].tmuvtx[0].sow = 255.f * texVerts[1].oow;
  texVerts[1].tmuvtx[0].tow = 255.f * texVerts[1].oow;

  texVerts[2].x = wWidth;
  texVerts[2].y = wHeight;
  texVerts[2].a = 255.f;
  texVerts[2].oow = 1.f;
  texVerts[2].tmuvtx[0].sow = 255.f * texVerts[2].oow;
  texVerts[2].tmuvtx[0].tow = 0.f * texVerts[2].oow;
  
  texVerts[3].x = 0.f;
  texVerts[3].y = wHeight;
  texVerts[3].a = 255.f;
  texVerts[3].oow = 1.f;
  texVerts[3].tmuvtx[0].sow = 0.f * texVerts[3].oow;
  texVerts[3].tmuvtx[0].tow = 0.f * texVerts[3].oow;
  
  if (bgFileName == NULL)
    bgFileName = "miro.3df";
  if (triFileName == NULL)
    triFileName = "matt1.3df";

  if ( gu3dfGetInfo( bgFileName, &bgInfo ) )  {
     bgInfo.data = malloc( bgInfo.mem_required );

     if ( bgInfo.data == 0 ) {
       fprintf( stderr, "out of memory for texture file %s\n", bgFileName );
       grGlideShutdown();
       exit( -1 );
     }

     if ( !gu3dfLoad( bgFileName, &bgInfo ) ) {
       fprintf( stderr, "could not load texture file %s\n", bgFileName );
       grGlideShutdown();
       exit( -1 );
     }

     bgDecal = guTexAllocateMemory( 0, GR_MIPMAPLEVELMASK_BOTH,
                                  bgInfo.header.width, bgInfo.header.height,
                                  bgInfo.header.format,
                                  GR_MIPMAP_NEAREST,
                                  bgInfo.header.small_lod, bgInfo.header.large_lod,
                                  bgInfo.header.aspect_ratio,
                                  GR_TEXTURECLAMP_WRAP, GR_TEXTURECLAMP_WRAP,
                                  GR_TEXTUREFILTER_BILINEAR, GR_TEXTUREFILTER_BILINEAR,
                                  0.0F,
                                  FXFALSE );
     if ( bgDecal == GR_NULL_MIPMAP_HANDLE ) {
       fprintf( stderr, "could not allocate memory for texture file %s\n", bgFileName );
       grGlideShutdown();
       exit( -1 );
     }
     guTexDownloadMipMap( bgDecal, bgInfo.data, &bgInfo.table.nccTable );
     free( bgInfo.data );
  } else {
    fprintf( stderr, "could not get info on %s\n", bgFileName );
    grGlideShutdown();
    exit( -1 );
  }
  
  if ( gu3dfGetInfo( triFileName, &triInfo ) )  {
    triInfo.data = malloc( triInfo.mem_required );
    
    if ( triInfo.data == 0 ) {
      fprintf( stderr, "out of memory for texture file  %s\n", triFileName );
      grGlideShutdown();
      exit( -1 );
    }
    
    if ( !gu3dfLoad( triFileName, &triInfo ) ) {
      fprintf( stderr, "could not load texture file %s\n", triFileName );
      grGlideShutdown();
      exit( -1 );
    }

    triDecal = guTexAllocateMemory( 0, GR_MIPMAPLEVELMASK_BOTH,
                                    triInfo.header.width,  
                                    triInfo.header.height, 
                                    triInfo.header.format,
                                    GR_MIPMAP_NEAREST,
                                    triInfo.header.small_lod,
                                    triInfo.header.large_lod, 
                                    triInfo.header.aspect_ratio,
                                    GR_TEXTURECLAMP_WRAP,
                                    GR_TEXTURECLAMP_WRAP, 
                                    GR_TEXTUREFILTER_BILINEAR,
                                    GR_TEXTUREFILTER_BILINEAR, 
                                    0.0F,
                                    FXFALSE );
    if ( triDecal == GR_NULL_MIPMAP_HANDLE ) {
       fprintf( stderr, "could not allocate memory for %s\n", triFileName );
       grGlideShutdown();
       exit( -1 );
     }
     guTexDownloadMipMap( triDecal, triInfo.data, &triInfo.table.nccTable );
     free( triInfo.data );
  } else {
    fprintf( stderr, "could not get info on %s\n", triFileName );
    grGlideShutdown();
    exit( -1 );
  }

  grTexCombineFunction(GR_TMU0, GR_TEXTURECOMBINE_DECAL);
  grRenderBuffer(backbuffer == FXTRUE ? GR_BUFFER_BACKBUFFER : GR_BUFFER_FRONTBUFFER);

  /* Set up alpha blend state for compositing and antialiasing */
  guAlphaSource( GR_ALPHASOURCE_ITERATED_ALPHA );
  grAlphaBlendFunction( GR_BLEND_SRC_ALPHA,
                        GR_BLEND_ONE_MINUS_SRC_ALPHA, GR_BLEND_ONE,
                        GR_BLEND_ZERO ); 
  grAlphaTestFunction( GR_CMP_ALWAYS );
  
  while ( 1 ) {
    Matrix rotm;
    GrVertex xformedVerts[4];
    int i;

    grSstIdle();

    
    ++nTris;
    MatMakeYRot( rotm, DEG2RAD( y_angle ) );
    
    for( i = 0; i < 4; i++ ) {
      PointMatMult( &xformedVerts[i], &localVerts[i], rotm );
      xformedVerts[i].x = xformedVerts[i].x / ( xformedVerts[i].z + 2.0f );
      xformedVerts[i].y = xformedVerts[i].y / ( xformedVerts[i].z + 2.0f );
      xformedVerts[i].x *= wHeight / 2.0f;
      xformedVerts[i].y *= wHeight / 2.0f;
      xformedVerts[i].x += wHeight / 2.0f;
      xformedVerts[i].y += wHeight / 2.0f;
      xformedVerts[i].oow = 1.f / ((xformedVerts[i].z + 2) * wHeight);
      xformedVerts[i].tmuvtx[0].sow *= xformedVerts[i].oow;
      xformedVerts[i].tmuvtx[0].tow *= xformedVerts[i].oow;
      SNAP_COORD( xformedVerts[i].x );
      SNAP_COORD( xformedVerts[i].y );
    }
    

    if (render == FXTRUE) {
      grBufferClear( 0xffffffff, 0, GR_WDEPTHVALUE_FARTHEST );
    
      if (background == FXTRUE) {
        GrState
          oldState;

        grGlideGetState(&oldState);

        grAlphaBlendFunction(
                             GR_BLEND_ONE, GR_BLEND_ZERO,
                             GR_BLEND_ONE, GR_BLEND_ZERO);

        grColorCombine(
                       GR_COMBINE_FUNCTION_SCALE_OTHER,
                       GR_COMBINE_FACTOR_ONE,
                       GR_COMBINE_LOCAL_NONE,
                       GR_COMBINE_OTHER_TEXTURE, FXFALSE
                       );

        guTexSource(bgDecal);
        
        for (i = 0; i < NTRIS; i++) {
          grDrawTriangle(&texVerts[0], &texVerts[1], &texVerts[2]);
          grDrawTriangle(&texVerts[2], &texVerts[3], &texVerts[0]);
        }
        grGlideSetState(&oldState);

      }

      guTexSource(triDecal);

      if (antialias == FXTRUE) {
        if (depthBias) 
            grDepthBiasLevel((short)0x8000);
        guColorCombineFunction(GR_COLORCOMBINE_DECAL_TEXTURE);
        grAADrawTriangle(
                         &xformedVerts[0],  &xformedVerts[1],
                         &xformedVerts[2], FXTRUE, FXTRUE, FXTRUE
                         );
#define SHIFT 20.f;
        for (n = 0; n < 3; n++) {
          xformedVerts[n].x += SHIFT;
          xformedVerts[n].y -= SHIFT;
        }
        if (depthBias)
          grDepthBiasLevel(0x7fff);
        guColorCombineFunction(GR_COLORCOMBINE_ITRGB);
        grAADrawTriangle(
                         &xformedVerts[0],  &xformedVerts[1],
                         &xformedVerts[2], FXTRUE, FXTRUE, FXTRUE
                         );
        
      } else {
        if (depthBias)
            grDepthBiasLevel((short)0x8000);
        guColorCombineFunction(GR_COLORCOMBINE_DECAL_TEXTURE);
        grDrawTriangle(
                       &xformedVerts[0], &xformedVerts[1],
                       &xformedVerts[2]
                       );
        for (n = 0; n < 3; n++) {
          xformedVerts[n].x += SHIFT;
          xformedVerts[n].y -= SHIFT;
        }
        if (depthBias)
          grDepthBiasLevel(0x7fff);
        guColorCombineFunction(GR_COLORCOMBINE_ITRGB);
        grDrawTriangle(
                       &xformedVerts[0], &xformedVerts[1],
                       &xformedVerts[2]
                       );
      }
      if (backbuffer) {
        grBufferSwap( 1 );
      }
    }
    
    if (kbhit()) {
      char c = getch();
      
      switch (c) {
      case 'a':
      case 'A':
        if (antialias == FXFALSE) {
          printf("Turning ON Antialiasing\n");
          antialias = FXTRUE;
        } else {
          printf("Turning OFF Antialiasing\n");
          antialias = FXFALSE;
        }
        break;
      case 'B':
      case 'b':
        if (bilinear == FXFALSE) {
          bilinear = FXTRUE;
          printf("Turning ON BiLinear blending\n");
          guTexChangeAttributes(
                                triDecal, bgInfo.header.width,
                                bgInfo.header.height, 
                                bgInfo.header.format, GR_MIPMAP_NEAREST,
                                bgInfo.header.small_lod,
                                bgInfo.header.large_lod, 
                                bgInfo.header.aspect_ratio,
                                GR_TEXTURECLAMP_WRAP, GR_TEXTURECLAMP_WRAP,
                                GR_TEXTUREFILTER_BILINEAR,
                                GR_TEXTUREFILTER_BILINEAR);
        } else {
          bilinear = FXFALSE;
          printf("Turning OFF BiLinear blending\n");
          guTexChangeAttributes(
                                triDecal, bgInfo.header.width,
                                bgInfo.header.height, 
                                bgInfo.header.format, GR_MIPMAP_NEAREST,
                                bgInfo.header.small_lod,
                                bgInfo.header.large_lod,
                                bgInfo.header.aspect_ratio, 
                                GR_TEXTURECLAMP_WRAP, GR_TEXTURECLAMP_WRAP,
                                GR_TEXTUREFILTER_POINT_SAMPLED,
                                GR_TEXTUREFILTER_POINT_SAMPLED);
        }
        break;

      case 'c':
      case 'C':
        if (blend == FXTRUE) {
          blend = FXFALSE;
          localVerts[0].a = 255.0f;
          localVerts[1].a = 255.0f;
          localVerts[2].a = 255.0f;
          localVerts[3].a = 255.0f;

        } else {
          blend = FXTRUE;
          localVerts[0].a = alpha;
          localVerts[1].a = alpha;
          localVerts[2].a = alpha;
        }
        break;

      case 'd':
      case 'D':
        if (depthBias == FXTRUE)  {
          printf("Turning OFF depth bias level\n");
          depthBias = FXFALSE;
          grDepthBiasLevel(0);
        } else {
          printf("Turning ON depth bias level\n");        
          depthBias = FXTRUE;
        }
        break;

      case 'f':
      case 'F':
        if (backbuffer == FXTRUE) {
          backbuffer = FXFALSE;
          grRenderBuffer(GR_BUFFER_FRONTBUFFER);
        } else {
          backbuffer = FXTRUE;
          grRenderBuffer(GR_BUFFER_BACKBUFFER);
        }
        break;

      case 'g':
      case 'G':
        grLfbBegin();

        grLfbWriteMode(GR_LFBWRITEMODE_565);
        grLfbOrigin(GR_ORIGIN_UPPER_LEFT);
        grLfbGetReadPtr(GR_BUFFER_FRONTBUFFER);
        printf("Press a key to get front buffer\n");
        while (!kbhit());
        c = getch();
        guFbReadRegion(0,0,(int)wWidth,(int)wHeight,scrnImage,(int)wWidth * sizeof(FxU16));
        printf("Press a key to put image in back buffer and swap\n");
        while (!kbhit());
        getch();

        grLfbGetWritePtr(GR_BUFFER_BACKBUFFER);
        guFbWriteRegion(0,0,(int)wWidth,(int)wHeight,scrnImage,(int)wWidth * sizeof(FxU16));
        grBufferSwap(1);

        printf("Press a key to continue...\n");
        while (!kbhit());
        getch();

        grLfbEnd();

        break;

      case 'h':
      case 'H':
      case '?':
        grSstPassthruMode(GR_PASSTHRU_SHOW_VGA);
        printf("Keymap:\n");
        printf("        A or a:         toggle Antialiasing\n");
        printf("        B or b:         toggle Bilinear\n");
        printf("        D or d:         toggle Depth bias level\n");
        printf("        F or f:         toggle Front buffer \n");
        printf("        H, h, or ?:     Help\n");
        printf("        I or i:         toggle background Image\n");
        printf("        P or p:         Pause rendering\n");
        printf("        Q or q:         Quit\n");
        printf("Press a key to continue...\n");
        getch();
        grSstPassthruMode(GR_PASSTHRU_SHOW_SST1);
        break;

      case 'i':
      case 'I':
        if (background == FXTRUE) {
          background = FXFALSE;
          printf("Turning off background\n");
        } else {
          printf("Turning on background\n");
          background = FXTRUE;
        }
        break;

      case 'p':
      case 'P':
        if (render == FXTRUE)
          render = FXFALSE;
        else
          render = FXTRUE;
        break;
        
      case 'q':
      case 'Q':
        grGlideShutdown();
        exit(0);
        break;

      case 'T':
      case 't':
        if (texturing == FXFALSE) {
          printf("Turning ON texturing\n");
          ccFnc = GR_COLORCOMBINE_DECAL_TEXTURE;
          texturing = FXTRUE;
        } else {
          printf("Turning OFF texturing\n");
          ccFnc = GR_COLORCOMBINE_ITRGB;
          texturing = FXFALSE;
        }
        break;
        
      }
    }
    
    if (render) {
      y_angle += 2.f;
      if( y_angle > 360.0f )
        y_angle -= 360.0f;
    }

    frameCount++;
    if(frameCount < 0)
      frameCount = 0;
    if(numFrames == frameCount)
      break;
  }
  grGlideShutdown();
}
示例#5
0
void
main( int argc, char **argv ) {
  float color = 255.f;
  int
    i, j, num_sst, jj,
    numFrames = -1,
    frameCount = 0;
  char
    *texFileNames[2];
  float
    wWidth, wHeight;

  GrMipMapId_t
    mipmaps[2];
  GrScreenResolution_t
    screenRes;
  GrVertex
    vtx1, vtx2, vtx3;
    
  texFileNames[0] = "bfly.3df";
  texFileNames[1] = "lava.3df";

  wWidth = 640.f;
  wHeight = 480.f;
  screenRes = GR_RESOLUTION_640x480;

  if (argc > 1) {
    for(i = 1; i < argc; i++) {
      if (strstr(argv[i], "320x200")) {
        wWidth = 320.f; wHeight = 200.f;
        screenRes = GR_RESOLUTION_320x200;
      } else if (strstr(argv[i], "320x240")) {
        wWidth = 320.f; wHeight = 240.f;
        screenRes = GR_RESOLUTION_320x240;
      } else if (strstr(argv[i], "400x256")) {
        wWidth = 400.f; wHeight = 256.f;
        screenRes = GR_RESOLUTION_400x256;
      } else if (strstr(argv[i], "512x384")) {
        wWidth = 512.f; wHeight = 384.f;
	screenRes = GR_RESOLUTION_512x384;
      } else if (strstr(argv[i], "640x480")) {
        wWidth = 640.f; wHeight = 480.f;
        screenRes = GR_RESOLUTION_640x480;
      } else if (strstr(argv[i], "800x600")) {
        wWidth = 800.f; wHeight = 600.f;
        screenRes = GR_RESOLUTION_800x600;
      } else if (strstr(argv[i], "640x200")) {
        wWidth = 640.f; wHeight = 200.f;
        screenRes = GR_RESOLUTION_640x200;
      } else if (strstr(argv[i], "640x350")) {
        wWidth = 640.f; wHeight = 350.f;
        screenRes = GR_RESOLUTION_640x350;
      } else if (strstr(argv[i], "640x400")) {
        wWidth = 640.f; wHeight = 400.f;
        screenRes = GR_RESOLUTION_640x400;
      } else if (strstr(argv[i], "960x720")) {
        wWidth = 960.f; wHeight = 720.f;
        screenRes = GR_RESOLUTION_960x720;
      } else if(strstr(argv[i], "-n")) {
        if(argc > i + 1) {
          numFrames = atoi(argv[ i + 1]);
          i++;
        } else {
          fprintf(stderr, "Usage: test42 {320x200|320x240|400x256|512x384|640x480|800x600|640x200|640x350|640x400|960x720} {-n numFrames}");
          exit(-1);
        }
      } else {
        fprintf(stderr, "Usage: test42 {320x200|320x240|400x256|512x384|640x480|800x600|640x200|640x350|640x400|960x720} {-n numFrames}\n");
        exit(-1);
      }
    }
  }

  puts( "\nTEST42:" );
  puts( "renders a Gouraud-modulated, textured triangle on each screen" );
  if(numFrames == -1) {
    puts( "press a key to continue" );
    getch();
  }

  grGlideInit();

  if ( !grSstQueryHardware( &hwconfig ) ) {
    fprintf( stderr, "main: grSstQueryHardware failed!\n" );
    grGlideShutdown();
    exit( -1 );
  }

  for (i = 0; i < hwconfig.num_sst; i++) {
    if (hwconfig.SSTs[i].type != GR_SSTTYPE_VOODOO) {
      fprintf(stderr, "Somebody needs to update this program!\n");
      grGlideShutdown();
      exit( -1 );
    } else
      printf("SST %d: 3Dfx Voodoo Graphics:\n", 1);

    printf("    Pixelfx Revision %d, %d MB Frame Buffer RAM\n",
           hwconfig.SSTs[i].sstBoard.VoodooConfig.fbiRev,
           hwconfig.SSTs[i].sstBoard.VoodooConfig.fbRam);
    for (j = 0; j < hwconfig.SSTs[i].sstBoard.VoodooConfig.nTexelfx; j++) {
      printf("          Texelfx %d: Revision %d, %d MB Texture RAM\n",
             j,
             hwconfig.SSTs[i].sstBoard.VoodooConfig.tmuConfig[j].tmuRev,
             hwconfig.SSTs[i].sstBoard.VoodooConfig.tmuConfig[j].tmuRam);
    }
  }
  num_sst = hwconfig.num_sst;

  for(jj=0; jj<num_sst; jj++) {
      /*
      ** Select SST
      */
      grSstSelect( jj );
    
      /*
      ** Open up the hardware
      */
      if ( !grSstOpen( screenRes,
                       GR_REFRESH_60Hz,
                       GR_COLORFORMAT_ABGR,
                       GR_ORIGIN_LOWER_LEFT,
                       GR_SMOOTHING_ENABLE,
                       2 ) )
      {
        fprintf( stderr, "main: grSstOpen failed for SST#%d!\n", jj );
        grGlideShutdown();
        exit( -1 );
      }
      guColorCombineFunction( GR_COLORCOMBINE_TEXTURE_TIMES_ITRGB );
      grTexCombineFunction(GR_TMU0, GR_TEXTURECOMBINE_DECAL);
  }
  
  for (jj = 0; jj < num_sst; jj++) {
    Gu3dfInfo
      info;

    grSstSelect(jj);

    if ( gu3dfGetInfo(texFileNames[jj], &info)) {
      if ((info.data = malloc(info.mem_required)) == NULL) {
        fprintf(stderr, "couldn't allocate host memory for %s\n",
                texFileNames[jj]) ;
        grGlideShutdown();
        exit(-1);
      }
      if (!gu3dfLoad(texFileNames[jj], &info)) {
        fprintf(stderr, "Couldn't load %s\n", texFileNames[jj]);
        grGlideShutdown();
        exit(-1);
      }
      mipmaps[jj] = guTexAllocateMemory(0, 0x3,
                                        info.header.width,
                                        info.header.height,
                                        info.header.format,
                                        GR_MIPMAP_NEAREST_DITHER,
                                        info.header.small_lod,
                                        info.header.large_lod,
                                        info.header.aspect_ratio,
                                        GR_TEXTURECLAMP_CLAMP,
                                        GR_TEXTURECLAMP_CLAMP,
                                        GR_TEXTUREFILTER_BILINEAR,
                                        GR_TEXTUREFILTER_BILINEAR,
                                        0.f,
                                        FXFALSE);
      if (mipmaps[jj] == GR_NULL_MIPMAP_HANDLE) {
        fprintf(stderr, "could not allocate memory for %s\n",
                texFileNames[jj]);
        grGlideShutdown();
        exit(-1);
      }
      guTexDownloadMipMap( mipmaps[jj], info.data, &info.table.nccTable );

    } else {
      fprintf(stderr, "couldn't get info on %s\n", texFileNames[jj]);
      grGlideShutdown();
      exit(-1);
    }
      
    guTexSource(mipmaps[jj]);

  }

  vtx1.x        = 160.0F;
  vtx1.y        = 120.0F;
  vtx1.r        = (float) 0xff;
  vtx1.g        = 0.0F;
  vtx1.b        = 0.0F;
  vtx1.a        = 25.0F;
  vtx1.oow = 1.0F;
  vtx1.tmuvtx[0].sow = 0.0F;
  vtx1.tmuvtx[0].tow = 0.0F;
  
  vtx2.x        = 480.0F;
  vtx2.y        = 120.0F;
  vtx2.r        = 0.0F;
  vtx2.g        = (float) 0xff;
  vtx2.b        = 0.0F;
  vtx2.a        = 25.0F;
  vtx2.oow = 1.0F;
  vtx2.tmuvtx[0].sow = 255.0F;
  vtx2.tmuvtx[0].tow = 0.0F;
  
  vtx3.x        = 320.0F;
  vtx3.y        = 360.0F;
  vtx3.r        = 0.0F;
  vtx3.g        = 0.0F;
  vtx3.b        = (float) 0xff;
  vtx3.a        = 255.0F;
  vtx3.oow = 1.0F;
  vtx3.tmuvtx[0].sow = 128.0F;
  vtx3.tmuvtx[0].tow = 255.0F;
  
  while ( 1 ) {
    for(jj=0; jj<num_sst; jj++) {
      grSstSelect( jj );
      switch(jj & 0x3) {
        case 0:
            grBufferClear( 0xff0000, 0, GR_WDEPTHVALUE_FARTHEST );
            break;
        case 1:
            grBufferClear( 0xff, 0, GR_WDEPTHVALUE_FARTHEST );
            break;
        case 2:
            grBufferClear( 0xff00, 0, GR_WDEPTHVALUE_FARTHEST );
            break;
        default:
            grBufferClear( 0xff00ff, 0, GR_WDEPTHVALUE_FARTHEST );
            break;
      }
      grDrawTriangle( &vtx1, &vtx2, &vtx3 );
      grBufferSwap( 1 );
    }

    if (kbhit()) {
      getch();
      break;
    }
    frameCount++;
    if(frameCount < 0)
      frameCount = 0;
    if(frameCount == numFrames)
      break;
  }
  for(jj=0; jj<num_sst; jj++) {
    grSstSelect( jj );
    grGlideShutdown();
  }
}
示例#6
0
void main( int argc, char *argv[] ) {
    
    /*------------------------------------------------------------------
      Data
      ------------------------------------------------------------------*/
    char texFile[256];
    char texFile_2[256];

    FxU32        startAddress,nextAddress;
    FxU32        startAddress_2, nextAddress_2;
    GrTexInfo    texInfo, texInfo_2;
    Gu3dfInfo    info, info_2;
    GuNccTable   nccTable, nccTable_2;
    GuTexPalette pal, pal_2;
    FxBool       hasTable   = FXFALSE,
                 hasTable_2 = FXFALSE;
    FxBool       hasPalette = FXFALSE,
                 hasPalette_2 = FXFALSE;
    FxU32        numTmus = 1;
    FxU32        automate;
    FxU32        numFrames = -1;
    /*------------------------------------------------------------------
      Glide State Initialization 
      ------------------------------------------------------------------*/
    grGlideInit();
    grSstQueryHardware( &hwConfig );
    grSstSelect( 0 );
    grSstOpen( screenRes,
               GR_REFRESH_60Hz,
               GR_COLORFORMAT_ABGR,
               GR_ORIGIN_LOWER_LEFT,
               GR_SMOOTHING_ENABLE,
               2 );
    grColorCombine( GR_COMBINE_FUNCTION_SCALE_OTHER,
                    GR_COMBINE_FACTOR_ONE,
                    GR_COMBINE_LOCAL_NONE,
                    GR_COMBINE_OTHER_TEXTURE,
                    FXFALSE );
    grAlphaCombine( GR_COMBINE_FUNCTION_SCALE_OTHER,
                    GR_COMBINE_FACTOR_ONE,
                    GR_COMBINE_LOCAL_NONE,
                    GR_COMBINE_OTHER_TEXTURE,
                    FXFALSE );
    grTexCombine( GR_TMU0,
                  GR_COMBINE_FUNCTION_LOCAL,
                  GR_COMBINE_FACTOR_ZERO,
                  GR_COMBINE_FUNCTION_LOCAL,
                  GR_COMBINE_FACTOR_ZERO,
                  FXFALSE,
                  FXFALSE );

    if ( hwConfig.SSTs[0].sstBoard.VoodooConfig.nTexelfx == 2 ) {
        printf( "Detected 2 TMUs\n" );
        grTexCombine( GR_TMU1,
                      GR_COMBINE_FUNCTION_LOCAL,
                      GR_COMBINE_FACTOR_ZERO,
                      GR_COMBINE_FUNCTION_LOCAL,
                      GR_COMBINE_FACTOR_ZERO,
                      FXFALSE,
                      FXFALSE );
         numTmus = 2;
    }

    /*------------------------------------------------------------------
      Deal With Arguments
      ------------------------------------------------------------------*/
    if ( numTmus == 1 ) {
        if ( argc < 2 ) {
            puts( usage_1tmu );
            grGlideShutdown();
            return;        
        }
        else
        {
          if(strstr(argv[1], "-n"))
          {
            automate = 1;
	    numFrames = atoi(argv[2]);
            if(argc >= 4)  
              strcpy( texFile, argv[3] );    
            else
            {
              puts( usage_1tmu );
              grGlideShutdown();
              return;        
            }
          }
          else
          {
            strcpy( texFile, argv[1] );    
            if(argc > 3)
              if(strstr(argv[2], "-n"))
	      {
                automate = 1;
		numFrames = atoi(argv[3]);
	      }
              else 
              {
                puts( usage_1tmu );
                grGlideShutdown();
                return;    
              }    
          }
        } 
    }
    else
    {
      if(argc >= 3)
      {
	if(strstr(argv[1], "-n"))
	{
	  automate = 1;
	  if(argc >= 5)  
	  {
	    strcpy( texFile, argv[3] );    
	    strcpy( texFile_2, argv[4] );    
	  }
	  else
	  {
	    puts( usage_2tmu );
	    grGlideShutdown();
	    return;        
	  }
	}
	else
	{
	  strcpy( texFile, argv[1] );    
	  strcpy( texFile_2, argv[2] );    
	  if(argc >= 4)
	    if(strstr(argv[3], "-n"))
	      automate = 1;
	    else 
	    {
	      puts( usage_2tmu );
	      grGlideShutdown();
	      return;    
	    }    
	}
      }
      else
      {
	puts( usage_2tmu );
	grGlideShutdown();
	return;    
      }    
    }
    
    grAlphaBlendFunction( GR_BLEND_ONE, GR_BLEND_ZERO,
                          GR_BLEND_ONE, GR_BLEND_ZERO );

    grDepthBufferMode( GR_DEPTHBUFFER_DISABLE );
    grDepthBufferFunction( GR_CMP_LEQUAL );
    grDepthMask( FXFALSE );

    grCullMode( GR_CULL_DISABLE );

    grBufferClear( 0x0, 0x0, 0x0 );

    /*------------------------------------------------------------------
      Load Texture(s)
      ------------------------------------------------------------------*/
    if ( !gu3dfGetInfo( texFile, &info ) ) {
        printf( "Couldn't load %s.\n", texFile );
        return;
    }
    info.data = calloc( info.mem_required, 1 );
    gu3dfLoad( texFile, &info );

    texInfo.smallLod    = info.header.small_lod;
    texInfo.largeLod    = info.header.large_lod;
    texInfo.aspectRatio = info.header.aspect_ratio;
    texInfo.format      = info.header.format;
    texInfo.data        = info.data;

    if ( texInfo.format == GR_TEXFMT_YIQ_422 ||
         texInfo.format == GR_TEXFMT_AYIQ_8422 ) {
        puts( "*******************YIQ TEXTURE(TMU0)***************" );
        nccTable = info.table.nccTable;
        hasTable = FXTRUE;
    }

    if ( texInfo.format == GR_TEXFMT_P_8 ||
         texInfo.format == GR_TEXFMT_AP_88 ) {
        puts( "*******************PAL TEXTURE(TMU0)***************" );
        pal = info.table.palette;
        hasPalette = FXTRUE;
    }

    if ( numTmus == 2 ) {
        if ( !gu3dfGetInfo( texFile_2, &info_2 ) ) {
            printf( "Couldn't load %s.\n", texFile_2 );
            return;
        }
        info_2.data = calloc( info_2.mem_required, 1 );
        gu3dfLoad( texFile_2, &info_2 );
    
        texInfo_2.smallLod    = info_2.header.small_lod;
        texInfo_2.largeLod    = info_2.header.large_lod;
        texInfo_2.aspectRatio = info_2.header.aspect_ratio;
        texInfo_2.format      = info_2.header.format;
        texInfo_2.data        = info_2.data;
    
        if ( texInfo_2.format == GR_TEXFMT_YIQ_422 ||
             texInfo_2.format == GR_TEXFMT_AYIQ_8422 ) {
            puts( "*******************YIQ TEXTURE(TMU1)***************" );
            nccTable_2 = info_2.table.nccTable;
            hasTable_2 = FXTRUE;
        }
        if ( texInfo_2.format == GR_TEXFMT_P_8 ||
             texInfo_2.format == GR_TEXFMT_AP_88 ) {
            puts( "*******************PAL TEXTURE(TMU1)***************" );
            pal_2 = info_2.table.palette;
            hasPalette_2 = FXTRUE;
        }
    }


    /*------------------------------------------------------------------
      Allocate Texture RAM
      ------------------------------------------------------------------*/
    startAddress =  nextAddress = grTexMinAddress( GR_TMU0 );
    nextAddress  = startAddress + grTexTextureMemRequired( GR_MIPMAPLEVELMASK_BOTH,
                                                           &texInfo );

    printf( "tex0: startAddress: %d nextAddress %d\n", startAddress, nextAddress );

    if ( nextAddress > grTexMaxAddress( GR_TMU0 ) ) {
        printf( "Texture memory exhausted.\n" );
        return;
    }

    if ( numTmus == 2 ) {
        startAddress_2 =  nextAddress_2 = grTexMinAddress( GR_TMU1 );
        nextAddress_2  = startAddress_2 + 
                         grTexTextureMemRequired( GR_MIPMAPLEVELMASK_BOTH,
                                                  &texInfo_2 );
        printf( "tex1: startAddress: %d nextAddress %d\n", startAddress_2, nextAddress_2 );
    }

    /*------------------------------------------------------------------
      Download Texture(s)
      ------------------------------------------------------------------*/
    grTexDownloadMipMap( GR_TMU0,
                         startAddress,
                         GR_MIPMAPLEVELMASK_BOTH,
                         &texInfo );
    if ( hasTable ) {
        grTexNCCTable( GR_TMU0, GR_NCCTABLE_NCC1 );
        grTexDownloadTable( GR_TMU0,
                            GR_TEXTABLE_NCC1,
                            &nccTable );
    }
    if ( hasPalette ) {
        grTexDownloadTable( GR_TMU0,
                            GR_TEXTABLE_PALETTE,
                            &pal );
    }

    if ( numTmus == 2 ) {
        grTexDownloadMipMap( GR_TMU1,
                             startAddress_2,
                             GR_MIPMAPLEVELMASK_BOTH,
                             &texInfo_2 );
        if ( hasTable_2 ) {
            grTexNCCTable( GR_TMU1, GR_NCCTABLE_NCC0 );
            grTexDownloadTable( GR_TMU1,
                                GR_TEXTABLE_NCC0,
                                &nccTable_2 );
        }

        if ( hasPalette_2 ) {
            grTexDownloadTable( GR_TMU1,
                                GR_TEXTABLE_PALETTE,
                                &pal_2 );
        }
    }

    /*------------------------------------------------------------------
      Set up Texture Params and Set Texture As Current
      ------------------------------------------------------------------*/
    grTexFilterMode( GR_TMU0,
                     GR_TEXTUREFILTER_BILINEAR, 
                     GR_TEXTUREFILTER_BILINEAR );
    grTexClampMode( GR_TMU0,
                    GR_TEXTURECLAMP_WRAP,
                    GR_TEXTURECLAMP_WRAP );
    grTexMipMapMode( GR_TMU0,
                     GR_MIPMAP_NEAREST,
                     FXFALSE );
    grTexSource( GR_TMU0,
                 startAddress,
                 GR_MIPMAPLEVELMASK_BOTH,
                 &texInfo );

    if ( numTmus == 2 ) {
        grTexFilterMode( GR_TMU1,
                         GR_TEXTUREFILTER_BILINEAR, 
                         GR_TEXTUREFILTER_BILINEAR );
        grTexClampMode( GR_TMU1,
                        GR_TEXTURECLAMP_WRAP,
                        GR_TEXTURECLAMP_WRAP );
        grTexMipMapMode( GR_TMU1,
                         GR_MIPMAP_NEAREST,
                         FXFALSE );
        grTexSource( GR_TMU1,
                     startAddress_2,
                     GR_MIPMAPLEVELMASK_BOTH, 
                     &texInfo_2 );
    }


    /*------------------------------------------------------------------
      Render Triangles
      ------------------------------------------------------------------*/

    puts("TEST39:\n");
    puts("Tests the grTex routines\n");
    if(!automate)
    {
      puts("Press any key to continue\n");
      getch();
    }
    while(numFrames)
    {
      square(    0.0f,   0.0f, 256.0f, 256.0f );
      square(  255.0f,   0.0f, 128.0f, 128.0f );
      square(  382.0f,   0.0f,  64.0f,  64.0f );
      square(  445.0f,   0.0f,  32.0f,  32.0f );
      square(  476.0f,   0.0f,  16.0f,  16.0f );
      square(  491.0f,   0.0f,   8.0f,   8.0f );
      square(  498.0f,   0.0f,   4.0f,   4.0f );
      square(  501.0f,   0.0f,   2.0f,   2.0f );
      square(  502.0f,   0.0f,   1.0f,   1.0f );


      if ( numTmus == 2 ) {
        grTexCombine( GR_TMU0,
                      GR_COMBINE_FUNCTION_SCALE_OTHER,
                      GR_COMBINE_FACTOR_ONE,
                      GR_COMBINE_FUNCTION_SCALE_OTHER,
                      GR_COMBINE_FACTOR_ONE,
                      FXFALSE,
                      FXFALSE );
	
        grTexCombine( GR_TMU1,
                      GR_COMBINE_FUNCTION_LOCAL,
                      GR_COMBINE_FACTOR_ZERO,
                      GR_COMBINE_FUNCTION_LOCAL,
                      GR_COMBINE_FACTOR_ZERO,
                      FXFALSE,
                      FXFALSE );
	
        square(    0.0f,  300.0f, 256.0f, 256.0f );
        square(  255.0f,  300.0f, 128.0f, 128.0f );
        square(  382.0f,  300.0f,  64.0f,  64.0f );
        square(  445.0f,  300.0f,  32.0f,  32.0f );
        square(  476.0f,  300.0f,  16.0f,  16.0f );
        square(  491.0f,  300.0f,   8.0f,   8.0f );
        square(  498.0f,  300.0f,   4.0f,   4.0f );
        square(  501.0f,  300.0f,   2.0f,   2.0f );
        square(  502.0f,  300.0f,   1.0f,   1.0f );
      }


      grBufferSwap( 1 );    

      if(numFrames > 0)
	numFrames--;

      if(kbhit()) {
	getch();
	break;
      }
    } 
    grGlideShutdown();

    return;
}
示例#7
0
文件: test25.c 项目: basecq/q2dos
void main( int argc, char **argv) {
  char match; 
  char **remArgs;
  int  rv;

  GrScreenResolution_t resolution = GR_RESOLUTION_640x480;
  float                scrWidth   = 640.0f;
  float                scrHeight  = 480.0f;
  int frames                      = -1;

  float
    minColor = 10.f,            /* Vertex min color */
    maxColor = 245.f;           /* Vertex max color */
    
  GrVertex
    localVerts[VERT_COUNT],     /* Vertices in world coordinates */
    texVerts[4];                /* Texture vertices for background */
    
  float
    alpha = 192.0f,             /* Alpha for blending tringle over background */
    y_angle = 0.0f;             /* rotation amount */
    
  int
    firstTime;                  /* Used for performance calculations */

  FxBool
    plugging = FXFALSE,         /* Show shameless plug */
    printPerf = FXFALSE,        /* Print performance numbers */
    lines = FXFALSE,            /* Draw lines instead of triangles */
    blend = FXFALSE,            /* Blend the triangle over the background */
    texturing = FXFALSE,        /* Texture the tiangle */
    antialias = FXTRUE,         /* Antialias the triangle? */
    bilinear = FXTRUE,          /* Perform bilinear filtering on the texture? */
    render = FXTRUE,            /* Draw? */
    backbuffer = FXTRUE,        /* Draw to backbuffer? */
    background = FXTRUE;        /* Draw background? */

  GrOriginLocation_t
    origin = GR_ORIGIN_LOWER_LEFT; /* Origin */

  FxU32
    swapDelay = 1,              /* Arg to grBufferSwap */
    trisDrawn,                  /* # triangles drawn */
    trisProcessed,              /* # triangles through pipeline */
    lastFrame,                  /* Number of last frame we did perf stats */
    frameNum = 0L;              /* id of each frame drawn */
    
  GrCullMode_t
    cullMode = GR_CULL_DISABLE; /* backface culling */
    
  FxU32 startAddress = 0, bgDecalAddress = 0, triDecalAddress = 0;

  GrTexInfo
    triDecal,                   /* Triangle decal texture */
    bgDecal;                    /* Background decal texture */
    
  Gu3dfInfo
    bgInfo,                     /* Info on background texture */
    triInfo;                    /* Info on triangle texture */
    
  GrColorCombineFnc_t
    ccFnc = GR_COLORCOMBINE_ITRGB; /* Start of w/ Gouraud shading */
    
  char
    *bgFileName = NULL,         /* Name of background texture file */
    *triFileName = NULL;        /* Name of triangle texture file */
    
  int
    frameCount = 0;

  FxU32 wrange[2];
  FxI32 state_size;
  void *oldState;

  /* Initialize Glide */
  grGlideInit();
  assert( hwconfig = tlVoodooType() );

  /* Process Command Line Arguments */
  while( rv = tlGetOpt( argc, argv, "nrbtea", &match, &remArgs ) ) {
    if ( rv == -1 ) {
      printf( "Unrecognized command line argument\n" );
      printf( "%s %s\n", name, usage );
      printf( "Available resolutions:\n%s\n",
             tlGetResolutionList() );
      return;
    }
    switch( match ) {
    case 'n':
      frames = atoi( remArgs[0] );
      break;
    case 'r':
      resolution = tlGetResolutionConstant( remArgs[0], 
                                           &scrWidth, 
                                           &scrHeight );
      break;
    case 'b':
      bgFileName = strdup( remArgs[0] );
      break;
    case 't':
      triFileName = strdup( remArgs[0] );
      break;
    case 'a':
      alpha = (float)atof( remArgs[0] );
      break;
    }
  }

  tlSetScreen( scrWidth, scrHeight );

  version = grGetString( GR_VERSION );
    
  printf( "%s:\n%s\n", name, purpose );
  printf( "%s\n", version );
  printf( "Resolution: %s\n", tlGetResolutionString( resolution ) );
  if ( frames == -1 ) {
    printf( "Press A Key To Begin Test.\n" );
    tlGetCH();
  }
    
  grSstSelect( 0 );
  assert( grSstWinOpen(tlGethWnd(),
                       resolution,
                       GR_REFRESH_60Hz,
                       GR_COLORFORMAT_ABGR,
                       origin,
                       2, 1 ) );

  grVertexLayout(GR_PARAM_XY,  GR_VERTEX_X_OFFSET << 2, GR_PARAM_ENABLE);
  grVertexLayout(GR_PARAM_RGB, GR_VERTEX_R_OFFSET << 2, GR_PARAM_ENABLE);
  grVertexLayout(GR_PARAM_A,   GR_VERTEX_A_OFFSET << 2, GR_PARAM_ENABLE);

  grGet(GR_WDEPTH_MIN_MAX, 8, wrange);  
  grGet(GR_GLIDE_STATE_SIZE, 4, &state_size);
  oldState = malloc(state_size);        

  tlConSet( 0.0f, 0.0f, 1.0f, 1.0f,
           80, 40, 0xffffff );

  if(frames == -1) {
    doHelp();
  }

  localVerts[0].x = 0.f;
  localVerts[0].y = 0.75f;
  localVerts[0].z = 0.0f;
  localVerts[0].tmuvtx[0].sow = 255.f;
  localVerts[0].tmuvtx[0].tow = 255.f;
  localVerts[0].oow = 1.f;  
  localVerts[0].r = maxColor;
  localVerts[0].g = minColor;
  localVerts[0].b = minColor;
  localVerts[0].a = 255.f;

  localVerts[1].x = -0.75f;
  localVerts[1].y = -0.75f;
  localVerts[1].z = 0.0f;
  localVerts[1].tmuvtx[0].sow = 0.f;
  localVerts[1].tmuvtx[0].tow = 255.f;
  localVerts[1].oow = 1.f;  
  localVerts[1].r = minColor;
  localVerts[1].g = maxColor;
  localVerts[1].b = minColor;
  localVerts[1].a = 255.f;

  localVerts[2].x = 0.75f;
  localVerts[2].y = -0.75f;
  localVerts[2].z = 0.0f;
  localVerts[2].tmuvtx[0].sow = 255.f;
  localVerts[2].tmuvtx[0].tow = 0.f;
  localVerts[2].oow = 1.f;  
  localVerts[2].r = minColor;
  localVerts[2].g = minColor;
  localVerts[2].b = maxColor;
  localVerts[2].a = 255.f;

  texVerts[0].x = 0.f;
  texVerts[0].y = 0.f;
  texVerts[0].a = 255.f;
  texVerts[0].oow = 1.f;
  texVerts[0].tmuvtx[0].sow = 0.f * texVerts[0].oow;
  texVerts[0].tmuvtx[0].tow = 255.f * texVerts[0].oow;

  texVerts[1].x = scrWidth;
  texVerts[1].y = 0.f;
  texVerts[1].a = 255.f;
  texVerts[1].oow = 1.f;
  texVerts[1].tmuvtx[0].sow = 255.f * texVerts[1].oow;
  texVerts[1].tmuvtx[0].tow = 255.f * texVerts[1].oow;

  texVerts[2].x = scrWidth;
  texVerts[2].y = scrHeight;
  texVerts[2].a = 255.f;
  texVerts[2].oow = 1.f;
  texVerts[2].tmuvtx[0].sow = 255.f * texVerts[2].oow;
  texVerts[2].tmuvtx[0].tow = 0.f * texVerts[2].oow;
  
  texVerts[3].x = 0.f;
  texVerts[3].y = scrHeight;
  texVerts[3].a = 255.f;
  texVerts[3].oow = 1.f;
  texVerts[3].tmuvtx[0].sow = 0.f * texVerts[3].oow;
  texVerts[3].tmuvtx[0].tow = 0.f * texVerts[3].oow;
  
  if (bgFileName == NULL)
    bgFileName = "miro.3df";
  if (triFileName == NULL)
    triFileName = "matt1.3df";
  
  /* Read in background texture file  */
  if ( gu3dfGetInfo( bgFileName, &bgInfo ) )  {
    bgInfo.data = malloc( bgInfo.mem_required );

    if ( bgInfo.data == 0 ) {
      fprintf( stderr, "out of memory for texture file %s\n", bgFileName );
      grGlideShutdown();
      exit( -1 );
    }

    if ( !gu3dfLoad( bgFileName, &bgInfo ) ) {
      fprintf( stderr, "could not load texture file %s\n", bgFileName );
      grGlideShutdown();
      exit( -1 );
    }

    bgDecal.smallLodLog2    = bgInfo.header.small_lod;
    bgDecal.largeLodLog2    = bgInfo.header.large_lod;
    bgDecal.aspectRatioLog2 = bgInfo.header.aspect_ratio;
    bgDecal.data            = bgInfo.data;
    bgDecal.format          = bgInfo.header.format;
    grTexDownloadMipMap( GR_TMU0, startAddress, GR_MIPMAPLEVELMASK_BOTH, &bgDecal);
    grTexMipMapMode(GR_TMU0, GR_MIPMAP_NEAREST, FXTRUE);
    grTexClampMode( GR_TMU0, GR_TEXTURECLAMP_WRAP, GR_TEXTURECLAMP_WRAP);
    grTexFilterMode( GR_TMU0, GR_TEXTUREFILTER_BILINEAR, GR_TEXTUREFILTER_BILINEAR );
    bgDecalAddress = startAddress;
    startAddress += grTexCalcMemRequired ( bgDecal.smallLodLog2, bgDecal.largeLodLog2, 
                                           bgDecal.aspectRatioLog2, bgDecal.format );
    free( bgInfo.data );
  } else {
    fprintf( stderr, "could not get info on %s\n", bgFileName );
    grGlideShutdown();
    exit( -1 );
  }
  
  if ( gu3dfGetInfo( triFileName, &triInfo ) )  {
    triInfo.data = malloc( triInfo.mem_required );
    
    if ( triInfo.data == 0 ) {
      fprintf( stderr, "out of memory for texture file  %s\n", triFileName );
      grGlideShutdown();
      exit( -1 );
    }
    
    if ( !gu3dfLoad( triFileName, &triInfo ) ) {
      fprintf( stderr, "could not load texture file %s\n", triFileName );
      grGlideShutdown();
      exit( -1 );
    }

    triDecal.smallLodLog2    = triInfo.header.small_lod;
    triDecal.largeLodLog2    = triInfo.header.large_lod;
    triDecal.aspectRatioLog2 = triInfo.header.aspect_ratio;
    triDecal.data            = triInfo.data;
    triDecal.format          = triInfo.header.format;
    grTexDownloadMipMap( GR_TMU0, startAddress, GR_MIPMAPLEVELMASK_BOTH, &triDecal);
    grTexMipMapMode(GR_TMU0, GR_MIPMAP_NEAREST, FXTRUE);
    grTexClampMode( GR_TMU0, GR_TEXTURECLAMP_WRAP, GR_TEXTURECLAMP_WRAP);
    grTexFilterMode( GR_TMU0, GR_TEXTUREFILTER_BILINEAR, GR_TEXTUREFILTER_BILINEAR );
    triDecalAddress = startAddress;
    free( triInfo.data );
  } else {
    fprintf( stderr, "could not get info on %s\n", triFileName );
    grGlideShutdown();
    exit( -1 );
  }

  grTexCombine( GR_TMU0, GR_COMBINE_FUNCTION_LOCAL, GR_COMBINE_FACTOR_NONE,
                GR_COMBINE_FUNCTION_LOCAL, GR_COMBINE_FACTOR_NONE, FXFALSE, FXFALSE );
  grRenderBuffer(backbuffer == FXTRUE ? GR_BUFFER_BACKBUFFER : GR_BUFFER_FRONTBUFFER);

  /* Set up alpha blending for AA and compositing... */
  grAlphaCombine( GR_COMBINE_FUNCTION_LOCAL, 
                  GR_COMBINE_FACTOR_NONE, 
                  GR_COMBINE_LOCAL_ITERATED, 
                  GR_COMBINE_OTHER_NONE, 
                  FXFALSE );
  grAlphaBlendFunction( GR_BLEND_SRC_ALPHA,
                       GR_BLEND_ONE_MINUS_SRC_ALPHA, GR_BLEND_ONE,
                       GR_BLEND_ZERO );
  grAlphaTestFunction( GR_CMP_ALWAYS );


  while ( 1 ) {
    Matrix rotm;
    GrVertex xformedVerts[VERT_COUNT];
    int i;

    
    MatMakeYRot( rotm, DEG2RAD( y_angle ) );
    
    if (resolution == GR_RESOLUTION_NONE) 
      tlGetResolutionConstant("0",
                              &scrWidth, 
                              &scrHeight );


    for( i = 0; i < VERT_COUNT; i++ ) {
      PointMatMult( &xformedVerts[i], &localVerts[i], rotm );
      xformedVerts[i].x = xformedVerts[i].x / ( xformedVerts[i].z + 2.0f );
      xformedVerts[i].y = xformedVerts[i].y / ( xformedVerts[i].z + 2.0f );
      xformedVerts[i].x *= scrWidth / 2.0f;
      xformedVerts[i].y *= scrHeight / 2.0f;
      xformedVerts[i].x += scrWidth / 2.0f;
      xformedVerts[i].y += scrHeight / 2.0f;
      xformedVerts[i].oow = 1.f / ((xformedVerts[i].z + 2) * scrHeight);
      xformedVerts[i].tmuvtx[0].sow *= xformedVerts[i].oow;
      xformedVerts[i].tmuvtx[0].tow *= xformedVerts[i].oow;
      SNAP_COORD( xformedVerts[i].x );
      SNAP_COORD( xformedVerts[i].y );
    }
    
    switch ( ccFnc )
      {
      case GR_COLORCOMBINE_ITRGB:
        grColorCombine( GR_COMBINE_FUNCTION_LOCAL, GR_COMBINE_FACTOR_NONE, GR_COMBINE_LOCAL_ITERATED, GR_COMBINE_OTHER_NONE, FXFALSE );
        break;
        
      case GR_COLORCOMBINE_DECAL_TEXTURE:
        grColorCombine( GR_COMBINE_FUNCTION_SCALE_OTHER, GR_COMBINE_FACTOR_ONE, GR_COMBINE_LOCAL_NONE, GR_COMBINE_OTHER_TEXTURE, FXFALSE );
        break;
        
      case GR_COLORCOMBINE_TEXTURE_TIMES_ITRGB:
        grColorCombine( GR_COMBINE_FUNCTION_SCALE_OTHER, GR_COMBINE_FACTOR_LOCAL, GR_COMBINE_LOCAL_ITERATED, GR_COMBINE_OTHER_TEXTURE, FXFALSE );
        break;
      }
    
    /*    grLfbBypassMode(GR_LFBBYPASS_ENABLE); */

    if (render == FXTRUE) {
      ++frameNum;
      if ((frameNum % NFRAMES) == 0) {
        if (printPerf) {
          if (!firstTime)  {
            GrSstPerfStats_t
              pStats;
            FxU32
              lfbWritePixels,
              nFrames = frameNum - lastFrame,
              fillPixels = nFrames * screenFulls[resolution],
              totFail;
            
            lastFrame = frameNum;

            grGet(GR_STATS_PIXELS_IN,             4, &pStats.pixelsIn);
            grGet(GR_STATS_PIXELS_CHROMA_FAIL,    4, &pStats.chromaFail);
            grGet(GR_STATS_PIXELS_DEPTHFUNC_FAIL, 4, &pStats.zFuncFail);
            grGet(GR_STATS_PIXELS_AFUNC_FAIL,     4, &pStats.aFuncFail);
            grGet(GR_STATS_PIXELS_OUT,            4, &pStats.pixelsOut);
            grGet(GR_STATS_TRIANGLES_IN,          4, &trisProcessed);
            grGet(GR_STATS_TRIANGLES_OUT,         4, &trisDrawn);
            
            totFail = pStats.chromaFail + pStats.zFuncFail +
              pStats.aFuncFail;  
            
            lfbWritePixels = pStats.pixelsOut - pStats.pixelsIn - fillPixels;

            tlConOutput("In the last %d frames:\n", nFrames);
            tlConOutput("      Pixels Processed:               %d\n",
                        pStats.pixelsIn);
            tlConOutput("      Chroma Failures:                %d\n",
                        pStats.chromaFail);
            tlConOutput("      Z Compare Failures:             %d\n",
                        pStats.zFuncFail);
            tlConOutput("      Alpha Compare Failures:         %d\n",
                        pStats.aFuncFail);
            tlConOutput("      Fast Fill Pixels:               %d\n",
                        fillPixels);
            tlConOutput("      LFB Write Pixels:               %d\n",
                        lfbWritePixels);                   
            tlConOutput("      Total Pixels Drawn:             %d\n",
                        pStats.pixelsOut);
            tlConOutput("      Triangles Processed             %d\n",
                        trisProcessed);
            tlConOutput("      Triangles Drawn                 %d\n",
                        trisDrawn);

            if (
                (pStats.pixelsOut - lfbWritePixels - fillPixels - pStats.pixelsIn) != totFail)
              tlConOutput("Error:  %d != %d\n",
                          pStats.pixelsOut - lfbWritePixels - fillPixels,
                          totFail);

            grReset(GR_STATS_PIXELS);
          } else {
            lastFrame = frameNum;
            grReset(GR_STATS_PIXELS);
            firstTime = 0;
          }
        }
      }

      grBufferClear( 0xffffffff, 0, (FxU16)wrange[1] );
    
      if (background == FXTRUE) {

        texVerts[0].x = 0.f;
        texVerts[0].y = 0.f;

        texVerts[1].x = scrWidth;
        texVerts[1].y = 0.f;

        texVerts[1].x = scrWidth;
        texVerts[1].y = 0.f;

        texVerts[2].x = scrWidth;
        texVerts[2].y = scrHeight;

        texVerts[3].x = 0.f;
        texVerts[3].y = scrHeight;

        grGlideGetState(oldState);

        grVertexLayout(GR_PARAM_Q,   GR_VERTEX_OOW_OFFSET << 2, GR_PARAM_ENABLE);
        grVertexLayout(GR_PARAM_ST0, GR_VERTEX_SOW_TMU0_OFFSET << 2, GR_PARAM_ENABLE);

        grAlphaBlendFunction(
                             GR_BLEND_ONE, GR_BLEND_ZERO,
                             GR_BLEND_ONE, GR_BLEND_ZERO);

        grColorCombine(
                       GR_COMBINE_FUNCTION_SCALE_OTHER,
                       GR_COMBINE_FACTOR_ONE,
                       GR_COMBINE_LOCAL_NONE,
                       GR_COMBINE_OTHER_TEXTURE, FXFALSE
                       );

        grTexSource( GR_TMU0, bgDecalAddress, GR_MIPMAPLEVELMASK_BOTH, &bgDecal );
        
        for (i = 0; i < NTRIS; i++) {
          grDrawTriangle(&texVerts[0], &texVerts[1], &texVerts[2]);
          grDrawTriangle(&texVerts[2], &texVerts[3], &texVerts[0]);
        }
        grGlideSetState(oldState);
        grClipWindow(0, 0, (FxU32) scrWidth, (FxU32) scrHeight);

      }

      if (texturing == FXTRUE)
        grTexSource( GR_TMU0, bgDecalAddress, GR_MIPMAPLEVELMASK_BOTH, &bgDecal );

      if (texturing)
        grTexSource( GR_TMU0, triDecalAddress, GR_MIPMAPLEVELMASK_BOTH, &triDecal );

      if (antialias == FXTRUE) {
        grEnable(GR_AA_ORDERED);
        if (lines == FXTRUE) {
          grDrawLine(&xformedVerts[0], &xformedVerts[1]);
          grDrawLine(&xformedVerts[1], &xformedVerts[2]);
          grDrawLine(&xformedVerts[2], &xformedVerts[0]);
        } else {
          grAADrawTriangle(
                           &xformedVerts[0],  &xformedVerts[1],
                           &xformedVerts[2], FXTRUE, FXTRUE, FXTRUE
                           );
        }
      } else {
        grDisable(GR_AA_ORDERED);
        if (lines == FXTRUE) {
          grDrawLine(&xformedVerts[0], &xformedVerts[1]);
          grDrawLine(&xformedVerts[1], &xformedVerts[2]);
          grDrawLine(&xformedVerts[2], &xformedVerts[0]);
        } else {          
          grDrawTriangle(
                         &xformedVerts[0], &xformedVerts[1],
                         &xformedVerts[2]
                         );
        }
      }

      if (plugging) 
        grSplash(0.f, 0.f, scrWidth / 5.f, scrHeight / 5.f, frameNum);
      
      if (backbuffer) {
        tlConRender();
        grBufferSwap( swapDelay );
      }
    }
    
    if (tlKbHit()) {
      char c = (char) tlGetCH();
      
      switch (c) {
      case 'a':
      case 'A':
        if (antialias == FXFALSE) {
          tlConOutput("Turning ON Antialiasing\n");
          antialias = FXTRUE;
        } else {
          tlConOutput("Turning OFF Antialiasing\n");
          antialias = FXFALSE;
        }
        break;
      case 'B':
      case 'b':
        if (bilinear == FXFALSE) {
          bilinear = FXTRUE;
          tlConOutput("Turning ON BiLinear blending\n");
          grTexFilterMode ( GR_TMU0, GR_TEXTUREFILTER_BILINEAR, GR_TEXTUREFILTER_BILINEAR );
        } else {
          bilinear = FXFALSE;
          tlConOutput("Turning OFF BiLinear blending\n");
          grTexFilterMode ( GR_TMU0, GR_TEXTUREFILTER_POINT_SAMPLED, 
                          GR_TEXTUREFILTER_POINT_SAMPLED );
        }
        break;

      case 'c':
      case 'C':
        if (blend == FXTRUE) {
                  int i;
          blend = FXFALSE;
                  for(i=0;i<VERT_COUNT;i++) localVerts[i].a = 255.0f;
        } else {
                  int i;
          blend = FXTRUE;
          for(i=0;i<VERT_COUNT;i++) localVerts[i].a = alpha;
        }
        break;

      case 'd':
      case 'D':
        tlConOutput("vtxa = (%.2f, %.2f), vtxb = (%.2f, %.2f), vtxc = (%.2f, %.2f)\n",
                    xformedVerts[0].x, xformedVerts[0].y,
                    xformedVerts[1].x, xformedVerts[1].y,
                    xformedVerts[2].x, xformedVerts[2].y
                    );
        break;

      case 'f':
      case 'F':
        if (backbuffer == FXTRUE) {
          backbuffer = FXFALSE;
          grRenderBuffer(GR_BUFFER_FRONTBUFFER);
        } else {
          backbuffer = FXTRUE;
          grRenderBuffer(GR_BUFFER_BACKBUFFER);
        }
        break;

      case 'g':
      case 'G':
#if 0
        grLfbBegin();

        grLfbWriteMode(GR_LFBWRITEMODE_565);
        grLfbOrigin(GR_ORIGIN_UPPER_LEFT);
        grLfbGetReadPtr(GR_BUFFER_FRONTBUFFER);
        tlConOutput("Press a key to get front buffer\n");
        while (!tlKbHit());
        c = (char) tlGetCH();
        guFbReadRegion(0,0,(int)wWidth,(int)scrHeight,scrnImage,(int)wWidth * sizeof(FxU16));
        tlConOutput("Press a key to put image in back buffer and swap\n");
        while (!tlKbHit());
        tlGetCH();

        grLfbGetWritePtr(GR_BUFFER_BACKBUFFER);
        guFbWriteRegion(0,0,(int)wWidth,(int)scrHeight,scrnImage,(int)wWidth * sizeof(FxU16));
        grBufferSwap(swapDelay);

        tlConOutput("Press a key to continue...\n");
        while (!tlKbHit());
        tlGetCH();

        grLfbEnd();
#endif
        break;

      case 'h':
      case 'H':
      case '?':
        doHelp();
        break;

      case 'i':
      case 'I':
        if (background == FXTRUE) {
          background = FXFALSE;
          tlConOutput("Turning off background\n");
        } else {
          tlConOutput("Turning on background\n");
          background = FXTRUE;
        }
        break;

      case 'l':
      case 'L':
        if (lines == FXTRUE) {
          lines = FXFALSE;
          tlConOutput("Turning OFF lines\n");
        } else {
          lines = FXTRUE;
          tlConOutput("Turning ON lines\n");
        }
        break;
      case 'm':
      case 'M':
        ccFnc = GR_COLORCOMBINE_TEXTURE_TIMES_ITRGB;
        break;

      case 'n':
      case 'N':
        if (printPerf == FXFALSE) {
          printPerf = FXTRUE;
          firstTime = 1;
          grReset(GR_STATS_PIXELS);
          grReset(GR_STATS_TRIANGLES);
        } else {
          printPerf= FXFALSE;
        }
        break;

      case 'o':
      case 'O':
        if (origin == GR_ORIGIN_LOWER_LEFT)
          origin = GR_ORIGIN_UPPER_LEFT;
        else
          origin = GR_ORIGIN_LOWER_LEFT; 

        grSstOrigin(origin);
        break;

      case 'p':
      case 'P':
        if (render == FXTRUE)
          render = FXFALSE;
        else
          render = FXTRUE;
        break;
        
      case 'q':
      case 'Q':
      case 27:
        grGlideShutdown();
        exit(0);
        break;

      case 'r':
      case 'R':
        tlConOutput("Screen Resolution is %s\n", tlGetResolutionString( resolution ) );
        break;

      case 'S':
      case 's':
        if (cullMode == GR_CULL_DISABLE) {
          cullMode = GR_CULL_NEGATIVE;
          tlConOutput("Turning ON backface culling (hidden Surface removal)\n");
        } else  {
          cullMode = GR_CULL_DISABLE;
          tlConOutput("Turning OFF backface culling (hidden Surface removal)\n");
        }
        grCullMode(cullMode);
        break;
      case 'T':
      case 't':
        if (texturing == FXFALSE) {
          tlConOutput("Turning ON texturing\n");
          ccFnc = GR_COLORCOMBINE_DECAL_TEXTURE;
          texturing = FXTRUE;
          grVertexLayout(GR_PARAM_Q,   GR_VERTEX_OOW_OFFSET << 2, GR_PARAM_ENABLE);
          grVertexLayout(GR_PARAM_ST0, GR_VERTEX_SOW_TMU0_OFFSET << 2, GR_PARAM_ENABLE);
        } else {
          tlConOutput("Turning OFF texturing\n");
          ccFnc = GR_COLORCOMBINE_ITRGB;
          texturing = FXFALSE;
          grVertexLayout(GR_PARAM_Q,   GR_VERTEX_OOW_OFFSET << 2, GR_PARAM_DISABLE);
          grVertexLayout(GR_PARAM_ST0, GR_VERTEX_SOW_TMU0_OFFSET << 2, GR_PARAM_DISABLE);
        }
        break;
      case 'u':
      case 'U':
        if (plugging == FXTRUE) {
          plugging = FXFALSE;
          grDisable(GR_SHAMELESS_PLUG);
        }
        else {
          plugging = FXTRUE;
          grEnable(GR_SHAMELESS_PLUG);
        }
        break;
        
      case '1':
      case '2':
      case '3':
      case '4':
      case '5':
      case '6':
      case '7':
      case '8':
      case '9':
      case '0':
        {
          char str[256];
          swapDelay = (int) c - 0x30;
          sprintf(str, "Swapdelay = %d\n", swapDelay);
          tlConOutput(str);
        }
        break;
      }
    }
    
    if (render) {
      y_angle += 2.f;
      if( y_angle > 360.0f )
        y_angle -= 360.0f;
    }
    frameCount++;
    if(frameCount < 0)
      frameCount = 0;
    if(frames == frameCount)
      break;
  }
  grGlideShutdown();
}
示例#8
0
void main( int argc, char *argv[] ) {
  char
    texFile[256],
    texFile1[256],
    texFile2[256];
  float
    theta;
  
  FxU32
    numTmus = 1;
  
  FxBool
    paused = FXFALSE;

  Gu3dfInfo
    info, info2;
  FxU32
    numFrames = 0xffffffff;
 
  puts("TEST44: Tests complex, multi-tmu textures\n");
  puts("Press a key to continue...\n");
  getch();
  puts("Press q to quit\n");

  /* Glide State Initialization */
  grGlideInit();
  grSstQueryHardware( &hwConfig );
  grSstSelect( 0 );
  grSstOpen( screenRes,
            GR_REFRESH_60Hz,
            GR_COLORFORMAT_ABGR,
            GR_ORIGIN_LOWER_LEFT,
            GR_SMOOTHING_ENABLE,
            2 );
  grColorCombine( GR_COMBINE_FUNCTION_SCALE_OTHER,
                 GR_COMBINE_FACTOR_ONE,
                 GR_COMBINE_LOCAL_NONE,
                 GR_COMBINE_OTHER_TEXTURE,
                 FXFALSE );
  grAlphaCombine( GR_COMBINE_FUNCTION_SCALE_OTHER,
                 GR_COMBINE_FACTOR_ONE,
                 GR_COMBINE_LOCAL_NONE,
                 GR_COMBINE_OTHER_TEXTURE,
                 FXFALSE );
  grTexCombine( GR_TMU0,
               GR_COMBINE_FUNCTION_LOCAL,
               GR_COMBINE_FACTOR_ZERO,
               GR_COMBINE_FUNCTION_LOCAL,
               GR_COMBINE_FACTOR_ZERO,
               FXFALSE,
               FXFALSE );
  
  if ( hwConfig.SSTs[0].sstBoard.VoodooConfig.nTexelfx == 2 ) {
    printf( "Detected 2 TMUs\n" );
    grTexCombine( GR_TMU1,
                 GR_COMBINE_FUNCTION_LOCAL,
                 GR_COMBINE_FACTOR_ZERO,
                 GR_COMBINE_FUNCTION_LOCAL,
                 GR_COMBINE_FACTOR_ZERO,
                 FXFALSE,
                 FXFALSE );
    numTmus = 2;
  }
  
  /*------------------------------------------------------------------
    Deal With Arguments
    ------------------------------------------------------------------*/
  if ( numTmus == 1 ) {
    if ( argc < 2 ) {
      printf( "%s ", argv[0] );
      puts( usage_1tmu );
      grGlideShutdown();
      return;
    }
    argc--;argv++;
    while(argc) {
      if(strcmp(argv[0], "-n") == 0)  {
        argc--;argv++;
        if(argc)
          numFrames = atoi(argv[0]);
        else {
          puts( usage_1tmu );
          return;
        }
      }
      strcpy( texFile, argv[0] );
      strcpy( texFile1, argv[1] );
      argc--;argv++;
      argc--;argv++;
    }
  } else {
    if ( argc < 4 ) {
      printf( "%s ", argv[0] );
      puts( usage2tmu );
      grGlideShutdown();
      return;
    }
    argc--;argv++;
    while(argc) {
      if(strcmp(argv[0], "-n") == 0) {
        argc--;argv++;
        if(argc)
          numFrames = atoi(argv[0]);
        else {
          puts( usage_1tmu );
          return;
        }
      }
      strcpy( texFile, argv[0] );    
      strcpy( texFile1, argv[1]);
      strcpy( texFile2, argv[2] );
      argc -= 3;
      argv += 3;
    }
  }
  
  grAlphaBlendFunction( GR_BLEND_ONE, GR_BLEND_ZERO,
                       GR_BLEND_ONE, GR_BLEND_ZERO );
  
  grDepthBufferMode( GR_DEPTHBUFFER_DISABLE );
  grDepthBufferFunction( GR_CMP_LEQUAL );
  grDepthMask( FXFALSE );
  
  grCullMode( GR_CULL_DISABLE );
  
  grBufferClear( 0x0, 0x0, 0x0 );
  
  /*------------------------------------------------------------------
    Load Texture(s)
    ------------------------------------------------------------------*/
  if ( !gu3dfGetInfo( texFile, &info ) ) {
    printf( "Couldn't load %s.\n", texFile );
    return;
  }
  info.data = calloc( info.mem_required, 1 );
  gu3dfLoad( texFile, &info );
  
  texInfo.smallLod    = info.header.small_lod;
  texInfo.largeLod    = info.header.large_lod;
  texInfo.aspectRatio = info.header.aspect_ratio;
  texInfo.format      = info.header.format;
  texInfo.data        = info.data;
  
  if ( texInfo.format == GR_TEXFMT_YIQ_422 ||
      texInfo.format == GR_TEXFMT_AYIQ_8422 ) {
    puts( "*******************YIQ TEXTURE(TMU0)***************" );
    nccTable = info.table.nccTable;
    hasTable = FXTRUE;
  }
  
  if ( texInfo.format == GR_TEXFMT_P_8 ||
      texInfo.format == GR_TEXFMT_AP_88 ) {
    puts( "*******************PAL TEXTURE(TMU0)***************" );
    pal0 = info.table.palette;
   hasPalette = FXTRUE;
  }

  /* ++++ */
  if ( !gu3dfGetInfo( texFile1, &info ) ) {
    printf( "Couldn't load %s.\n", texFile1 );
    return;
  }
  info.data = calloc( info.mem_required, 1 );
  gu3dfLoad( texFile1, &info );
  
  texInfo1.smallLod    = info.header.small_lod;
  texInfo1.largeLod    = info.header.large_lod;
  texInfo1.aspectRatio = info.header.aspect_ratio;
  texInfo1.format      = info.header.format;
  texInfo1.data        = info.data;
  
  if ( texInfo1.format == GR_TEXFMT_YIQ_422 ||
      texInfo1.format == GR_TEXFMT_AYIQ_8422 ) {
    puts( "*******************YIQ TEXTURE(TMU0)***************" );
    nccTable = info.table.nccTable;
    hasTable = FXTRUE;
  }
  
  if ( texInfo1.format == GR_TEXFMT_P_8 ||
      texInfo1.format == GR_TEXFMT_AP_88 ) {
    puts( "*******************PAL TEXTURE(TMU0)***************" );
    pal0 = info.table.palette;
    hasPalette1 = FXTRUE;
  }


  /* ++++ */

  if ( numTmus == 2 ) {
    if ( !gu3dfGetInfo( texFile2, &info2 ) ) {
      printf( "Couldn't load %s.\n", texFile2 );
      return;
    }
    info2.data = calloc( info2.mem_required, 1 );
    gu3dfLoad( texFile2, &info2 );
    
    texInfo2.smallLod    = info2.header.small_lod;
    texInfo2.largeLod    = info2.header.large_lod;
    texInfo2.aspectRatio = info2.header.aspect_ratio;
    texInfo2.format      = info2.header.format;
    texInfo2.data        = info2.data;
    
    if ( texInfo2.format == GR_TEXFMT_YIQ_422 ||
        texInfo2.format == GR_TEXFMT_AYIQ_8422 ) {
      puts( "*******************YIQ TEXTURE(TMU1)***************" );
      nccTable2 = info2.table.nccTable;
      hasTable2 = FXTRUE;
    }
    if ( texInfo2.format == GR_TEXFMT_P_8 ||
        texInfo2.format == GR_TEXFMT_AP_88 ) {
      puts( "*******************PAL TEXTURE(TMU1)***************" );
      pal2 = info2.table.palette;
      hasPalette2 = FXTRUE;
    }
  }
  
  grHints(GR_HINT_STWHINT, GR_STWHINT_W_DIFF_TMU0 |
          GR_STWHINT_ST_DIFF_TMU0 | GR_STWHINT_W_DIFF_TMU1 |
          GR_STWHINT_ST_DIFF_TMU1);
  
  
  /*------------------------------------------------------------------
    Allocate Texture RAM
    ------------------------------------------------------------------*/
  tmu0Tex0Address = startAddress =
    nextAddress = grTexMinAddress( GR_TMU0 );
  tmu0Tex1Address = nextAddress  = startAddress +
    grTexTextureMemRequired( GR_MIPMAPLEVELMASK_BOTH, &texInfo );
  
  
  printf( "tex0: tmu0Tex0Address: %d tmu0Tex1Address %d\n",
         tmu0Tex0Address, tmu0Tex1Address);
  
  if ( nextAddress > grTexMaxAddress( GR_TMU0 ) ) {
    printf( "Texture memory exhausted.\n" );
    return;
  }
  
  if ( numTmus == 2 ) {
    startAddress2 =  nextAddress2 = grTexMinAddress( GR_TMU1 );
    nextAddress2  = startAddress2 + 
      grTexTextureMemRequired( GR_MIPMAPLEVELMASK_BOTH,
                              &texInfo2 );
    printf( "tex1: startAddress: %d nextAddress %d\n", startAddress2, nextAddress2 );
  }
  
  /*------------------------------------------------------------------
    Download Texture(s)
    ------------------------------------------------------------------*/
  grTexDownloadMipMap( GR_TMU0,
                      tmu0Tex0Address,
                      GR_MIPMAPLEVELMASK_BOTH,
                      &texInfo );
  /* ---- */
  grTexDownloadMipMap( GR_TMU0,
                      tmu0Tex1Address,
                      GR_MIPMAPLEVELMASK_BOTH,
                      &texInfo1 );


  /* ---- */

  if ( numTmus == 2 ) {
    grTexDownloadMipMap( GR_TMU1,
                        startAddress2,
                        GR_MIPMAPLEVELMASK_BOTH,
                        &texInfo2 );
    if ( hasTable2 ) {
      grTexNCCTable( GR_TMU1, GR_NCCTABLE_NCC0 );
      grTexDownloadTable( GR_TMU1,
                         GR_TEXTABLE_NCC0,
                         &nccTable2 );
    }

    if ( hasPalette2 ) {
      grTexDownloadTable( GR_TMU1,
                         GR_TEXTABLE_PALETTE,
                         &pal2 );
    }
  }
  
  /*------------------------------------------------------------------
    Set up Texture Params and Set Texture As Current
    ------------------------------------------------------------------*/
  grTexFilterMode( GR_TMU0,
                  GR_TEXTUREFILTER_BILINEAR, 
                  GR_TEXTUREFILTER_BILINEAR );
  grTexClampMode( GR_TMU0,
                 GR_TEXTURECLAMP_WRAP,
                 GR_TEXTURECLAMP_WRAP );
  grTexMipMapMode( GR_TMU0,
                  GR_MIPMAP_NEAREST,
                  FXFALSE );
  grTexSource( GR_TMU0,
              startAddress,
              GR_MIPMAPLEVELMASK_BOTH,
              &texInfo );
  


  if ( numTmus == 2 ) {
    grTexFilterMode( GR_TMU1,
                    GR_TEXTUREFILTER_BILINEAR, 
                    GR_TEXTUREFILTER_BILINEAR );
    grTexClampMode( GR_TMU1,
                   GR_TEXTURECLAMP_WRAP,
                   GR_TEXTURECLAMP_WRAP );
    grTexMipMapMode( GR_TMU1,
                    GR_MIPMAP_NEAREST,
                    FXFALSE );
    grTexSource( GR_TMU1,
                startAddress2,
                GR_MIPMAPLEVELMASK_BOTH, 
                &texInfo2 );
  }
  
  if ( numTmus == 2 ) {
    grTexCombine( GR_TMU1,
                  GR_COMBINE_FUNCTION_LOCAL,
                  GR_COMBINE_FACTOR_NONE,
                  GR_COMBINE_FUNCTION_LOCAL,
                  GR_COMBINE_FACTOR_NONE,
                  FXFALSE,
                  FXFALSE );

    grTexCombine( GR_TMU0,
                  GR_COMBINE_FUNCTION_SCALE_OTHER_ADD_LOCAL,
                  GR_COMBINE_FACTOR_ONE, 
                  GR_COMBINE_FUNCTION_SCALE_OTHER_ADD_LOCAL,
                  GR_COMBINE_FACTOR_ONE,
                  FXFALSE,
                  FXFALSE ); 
  }
  
#define INC 0.5f
  
  theta = 0.f;
  while (1 && numFrames) {
    if (paused == FXFALSE) {
      theta += INC;
      if (theta > 180.f)
        theta -= 180.f;
    }

    square(0.f, 0.f, 640.3f, 480.f, DEG2RAD(theta));

    grBufferSwap( 1 );

    if (kbhit()) {
      char c;
      c = getch();

      switch (c) {
      case '-':
        theta -= INC;
        break;

      case '+':
        theta += INC;
        break;

      case 'd':
      case 'D':
        printf("theta = %3.1f\n", theta);
        break;

      case 'P':
      case 'p':
        if (paused == FXFALSE)
          paused = FXTRUE;
        else
          paused = FXFALSE;
        break;

      case 'q':
      case 'Q':
      case 27:
        grGlideShutdown();
        exit(0);
        break;
      }
    } /* input switch */
    if(numFrames != -1)
      numFrames--;
  } /* render loop */
}/* main */