示例#1
0
文件: 3dfx.c 项目: gameplayer22/d2x-1
void _3dfx_DrawFlatShadedPoly( g3ds_tmap *Tmap1, unsigned long argb )
{
   GrVertex a, b, c;
   int      i;
   float    lowest_y = 10000, highest_y = 0;
   float    lowest_x = 10000, highest_x = 0;

   for ( i = 0; i < Tmap1->nv; i++ )
   {
      float x = SNAP( Tmap1->verts[i].x2d ) * fix_to_float;
      float y = SNAP( Tmap1->verts[i].y2d ) * fix_to_float;

      if ( x < lowest_x ) lowest_x = x;
      if ( x > highest_x ) highest_x = x;
      if ( y < lowest_y ) lowest_y = y;
      if ( y > highest_y ) highest_y = y;
   }

   if ( highest_x < 0 || highest_y < 0 || lowest_x > 639 || lowest_y > 479 )
   {
      mprintf( ( 0, "3dfx - rejecting fspoly way off screen\n" ) );
      return;
   }

   guColorCombineFunction( GR_COLORCOMBINE_CCRGB );
   grConstantColorValue( argb );

   a.x = SNAP( Tmap1->verts[0].x2d ) * fix_to_float;
   a.y = SNAP( Tmap1->verts[0].y2d ) * fix_to_float;

   for ( i = 1; i < Tmap1->nv - 1; i++ )
   {
      b.x   = SNAP( Tmap1->verts[i].x2d ) * fix_to_float;
      b.y   = SNAP( Tmap1->verts[i].y2d ) * fix_to_float;
      c.x   = SNAP( Tmap1->verts[i+1].x2d ) * fix_to_float;
      c.y   = SNAP( Tmap1->verts[i+1].y2d ) * fix_to_float;

      grDrawTriangle( &a, &b, &c );
   }
}
示例#2
0
void
main(int argc, char **argv) {
  float
    wWidth, wHeight;
  GrScreenResolution_t
    screenRes;
  int 
    numFrames = -1,
    frameCount = 0;
  int
    i;

  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: test09 {320x200|320x240|400x256|512x384|640x480|800x600|640x200|640x350|640x400|960x720} {-n numFrames}\n");
          exit(-1);
        }
      } else {
        fprintf(stderr, "Usage: test09 {320x200|320x240|400x256|512x384|640x480|800x600|640x200|640x350|640x400|960x720} {-n numFrames}\n");
        exit(-1);
      }
    }
  }
  puts( "\nTEST09:" );
  puts( "tests alpha blending" );
  if(numFrames == -1)
  {
    puts( "Press any 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 );
  }

  /*
  ** Configure Glide to test alpha blending
  */
  guAlphaSource( GR_ALPHASOURCE_CC_ALPHA );
  grAlphaBlendFunction( GR_BLEND_SRC_ALPHA, GR_BLEND_ONE_MINUS_SRC_ALPHA, GR_BLEND_ONE, GR_BLEND_ZERO );
  grColorCombine(
    GR_COMBINE_FUNCTION_LOCAL, GR_COMBINE_FACTOR_ONE, 
    GR_COMBINE_LOCAL_CONSTANT, GR_COMBINE_OTHER_NONE, FXFALSE);
  
  while ( 1 ) 
  {
    static GrVertex vtxlist[3];
    int i;

    grBufferClear( 0, 0, 0 );

    vtxlist[0].x   = 160.f;
    vtxlist[0].y   = 100.f;
    vtxlist[1].x   = 480.f;
    vtxlist[1].y   = 100.f;
    vtxlist[2].x   = 320.f;
    vtxlist[2].y   = 380.f;

    grConstantColorValue4(255.f, 0.f, 0.f, 255.f);
    grConstantColorValue( 0xFF0000FF );

    for (i = 0; i < 3; i++) {
        vtxlist[i].x = WINSCALEX(vtxlist[i].x);
        vtxlist[i].y = WINSCALEY(vtxlist[i].y);
    }
    grDrawTriangle( &vtxlist[0], &vtxlist[2], &vtxlist[1] );

    vtxlist[0].x   = 160.f;
    vtxlist[0].y   = 380.f;
    vtxlist[1].x   = 480.f;
    vtxlist[1].y   = 380.f;
    vtxlist[2].x   = 320.f;
    vtxlist[2].y   = 100.f;

    grConstantColorValue4(128.f, 255.f, 0.f, 0.f);
    grConstantColorValue( 0x80FF0000 );

    for (i = 0; i < 3; i++) {
      vtxlist[i].x = WINSCALEX(vtxlist[i].x);
      vtxlist[i].y = WINSCALEY(vtxlist[i].y);
    }
    grDrawTriangle( &vtxlist[0], &vtxlist[1], &vtxlist[2] );

    grBufferSwap( 0 );
    if (kbhit()) {
      getch();
      break;
    }
    frameCount++;
    if(frameCount < 0)
      frameCount = 0;
    if(frameCount == numFrames)
      break;
  }
  grGlideShutdown();
}
示例#3
0
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;
  FxBool               scrgrab = FXFALSE;
  char                 filename[256];
  FxU32                wrange[2];

  
  /* Process Command Line Arguments */
  while( rv = tlGetOpt( argc, argv, "nrd", &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 'd':
      scrgrab = FXTRUE;
      frames = 1;
      strcpy(filename, 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();
  }
  
  /* Initialize Glide */
  grGlideInit();

  assert( hwconfig = tlVoodooType() );

  grSstSelect( 0 );
  assert( grSstWinOpen( 0,
                       resolution,
                       GR_REFRESH_60Hz,
                       GR_COLORFORMAT_ABGR,
                       GR_ORIGIN_UPPER_LEFT,
                       2, 1 ) );
  
  grGet(GR_WDEPTH_MIN_MAX, 8, wrange);  
  grVertexLayout(GR_PARAM_XY, 0, GR_PARAM_ENABLE);

  tlConSet( 0.0f, 0.0f, 1.0f, 1.0f, 
           60, 30, 0xffffff );
  
  /* Set up Render State - flat shading */
  grColorCombine( GR_COMBINE_FUNCTION_LOCAL,
                 GR_COMBINE_FACTOR_NONE,
                 GR_COMBINE_LOCAL_CONSTANT,
                 GR_COMBINE_OTHER_NONE,
                 FXFALSE );
  grConstantColorValue( 0xFFFFFF );
  
  
  tlConOutput( "Press a key to quit\n" );
  while( frames-- && tlOkToRender()) {
    int i;
    GrVertex vtx;

    if (hwconfig == TL_VOODOORUSH) {
      tlGetDimsByConst(resolution,
                       &scrWidth, 
                       &scrHeight );
        
      grClipWindow(0, 0, (FxU32) scrWidth, (FxU32) scrHeight);
    } 
    grBufferClear(0x00000000, 0, wrange[1]);

    for( i = 0; i < 100; i++ ) {
      float pos = ((float)i)/100.0f;

      vtx.x = tlScaleX( pos ), vtx.y = tlScaleY( pos );
      grDrawPoint( &vtx );
    }


    tlConRender();
    grBufferSwap( 1 );

    /* grab the frame buffer */
    if (scrgrab) {
      if (!tlScreenDump(filename, (FxU16)scrWidth, (FxU16)scrHeight))
        printf( "Cannot open %s\n", filename);
      scrgrab = FXFALSE;
    }
    if ( tlKbHit() ) frames = 0;
  }
  
  grGlideShutdown();
  return;
}
示例#4
0
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;
    FxBool               scrgrab = FXFALSE;
    char                 filename[256];

    /* Process Command Line Arguments */
    while( rv = tlGetOpt( argc, argv, "nrd", &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 'd':
            scrgrab = FXTRUE;
            frames = 1;
            strcpy(filename, remArgs[0]);
            break;
        }
    }

    tlSetScreen( scrWidth, scrHeight );

    grGlideGetVersion( 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();
    }

    /* Initialize Glide */
    grGlideInit();
    assert( grSstQueryHardware( &hwconfig ) );
    grSstSelect( 0 );
    assert( grSstWinOpen( 0,
                          resolution,
                          GR_REFRESH_60Hz,
                          GR_COLORFORMAT_ABGR,
                          GR_ORIGIN_UPPER_LEFT,
                          2, 1 ) );

    tlConSet( 0.0f, 0.0f, 1.0f, 0.5f,
              60, 15, 0xffffff );

    /* Set up Render State - iterated alpha + constant color */
    grColorCombine( GR_COMBINE_FUNCTION_LOCAL,
                    GR_COMBINE_FACTOR_NONE,
                    GR_COMBINE_LOCAL_CONSTANT,
                    GR_COMBINE_OTHER_NONE,
                    FXFALSE );
    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_ZERO, GR_BLEND_ZERO );

#define RED  0x000000ff
#define BLUE 0x00ff0000

    tlConOutput( "Press any key to quit\n" );
    while( frames-- && tlOkToRender()) {
        GrVertex vtxA, vtxB, vtxC;

        if (hwconfig.SSTs[0].type == GR_SSTTYPE_SST96) {
            tlGetDimsByConst(resolution,
                             &scrWidth,
                             &scrHeight );

            grClipWindow(0, 0, (FxU32) scrWidth, (FxU32) scrHeight);
        }

        grBufferClear( 0x00, 0, 0 );

        vtxA.x = tlScaleX( 0.5f ), vtxA.y = tlScaleY( 0.1f );
        vtxB.x = tlScaleX( 0.8f ), vtxB.y = tlScaleY( 0.9f );
        vtxC.x = tlScaleX( 0.2f ), vtxC.y = tlScaleY( 0.9f );
        vtxA.a = vtxB.a = vtxC.a = 255.0f;

        grConstantColorValue( RED );
        grDrawTriangle( &vtxA, &vtxB, &vtxC );

        grSstOrigin( GR_ORIGIN_LOWER_LEFT );

        vtxA.a = 0.0f;
        grConstantColorValue( BLUE );
        grDrawTriangle( &vtxA, &vtxB, &vtxC );

        grSstOrigin( GR_ORIGIN_UPPER_LEFT );

        tlConRender();
        grBufferSwap( 1 );

        /* grab the frame buffer */
        if (scrgrab) {
            if (!tlScreenDump(filename, (FxU16)scrWidth, (FxU16)scrHeight))
                printf( "Cannot open %s\n", filename);
            scrgrab = FXFALSE;
        }

        while( tlKbHit() ) {
            switch( tlGetCH() ) {
            default:
                frames = 0;
                break;
            }
        }
    }

    grGlideShutdown();
    return;
}
示例#5
0
文件: test15.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 clipX, clipY, clipSize, clipSizeDelta, clipPosDelta;
    FxU32 zrange[2];

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

    /* Process Command Line Arguments */
    while( rv = tlGetOpt( argc, argv, "nr", &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;
        }
    }

    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,
                         GR_ORIGIN_UPPER_LEFT,
                         2, 1 ) );
    
    tlConSet( 0.0f, 0.0f, 1.0f, 0.5f, 
              60, 15, 0xffffff );

    /* Set up Render State - iterated alpha + z buffering */
    grGet(GR_ZDEPTH_MIN_MAX, 8, zrange);  
    grVertexLayout(GR_PARAM_XY, 0, GR_PARAM_ENABLE);

    grColorCombine( GR_COMBINE_FUNCTION_LOCAL,
                    GR_COMBINE_FACTOR_NONE,
                    GR_COMBINE_LOCAL_CONSTANT,
                    GR_COMBINE_OTHER_NONE,
                    FXFALSE );
    
    clipX    = 0.2f;
    clipY    = 0.5f;
    clipSize = 0.3f;
    
    clipSizeDelta = 0.005f;
    clipPosDelta = 0.01f;

#define CLIPSIZE_MIN 0.05f
#define CLIPSIZE_MAX 0.6f

#define GRAY  0x00808080
#define BLACK 0x00000000

    tlConOutput( "+/- - grow/shrink clip rectangle\n" );
    tlConOutput( "a/d - clip window left/right \n" );
    tlConOutput( "w/s - clip window up/down \n" );
    tlConOutput( "Press any other key to quit\n" );
    while( frames-- && tlOkToRender()) {
        int x, y;
        GrVertex vtxA, vtxB, vtxC;
        int minx, miny, maxx, maxy;

        if (hwconfig == TL_VOODOORUSH) {
          tlGetDimsByConst(resolution,
                           &scrWidth, 
                           &scrHeight );
        
          grClipWindow(0, 0, (FxU32) scrWidth, (FxU32) scrHeight);
        }

        grClipWindow( (int)tlScaleX(0.0f),(int)tlScaleY(0.0f),
                      (int)tlScaleX(1.0f),(int)tlScaleY(1.0f) );
        grBufferClear( BLACK, 0, zrange[1] );

        /* Set Clipping Rectangle */
        minx = (int)tlScaleX(clipX);
        miny = (int)tlScaleY(clipY);
        if ( (clipX+clipSize)>1.0f ) 
            maxx = (int)tlScaleX( 1.0f );
        else 
            maxx = (int)tlScaleX( clipX + clipSize );
        if ( (clipY+clipSize)>1.0f ) 
            maxy = (int)tlScaleY( 1.0f );
        else 
            maxy = (int)tlScaleY( clipY + clipSize );
        grClipWindow( minx, miny, maxx, maxy );

        /* Draw 10x10 grid of triangles */
        for( y = 0; y < 10; y++ ) {
            for( x = 0; x < 10; x++ ) {
                /* 
                   A
                   |\
                   B-C
                 */
                vtxA.x = vtxB.x = tlScaleX( ((float)x)/10.0f );
                vtxA.y = tlScaleY( ((float)y)/10.0f );
                vtxB.y = vtxC.y = tlScaleY( (((float)y)/10.0f) + 0.1f );
                vtxC.x = tlScaleX( (((float)x)/10.0f) + 0.1f );
                
                grConstantColorValue( GRAY );
                grDrawTriangle( &vtxA, &vtxB, &vtxC );
            }
        }

        tlConRender();
        grBufferSwap( 1 );
        grFinish();
        
        while( tlKbHit() ) {
            switch( tlGetCH() ) {
            case '+':
                if ( clipSize < CLIPSIZE_MAX )
                    clipSize += clipSizeDelta;
                break;
            case '-':
                if ( clipSize > CLIPSIZE_MIN )
                    clipSize -= clipSizeDelta;
                break;
            case 'a':
            case 'A':
                if ( clipX > 0.0f )
                    clipX -= clipPosDelta;
                if ( clipX < 0.0f ) clipX = 0.0f;
                break;
            case 'd':
            case 'D':
                if ( clipX < 1.0f )
                    clipX += clipPosDelta;
                break;
            case 'w':
            case 'W':
                if ( clipY > 0.0f ) 
                    clipY -= clipPosDelta;
                if ( clipY < 0.0f ) clipY = 0.0f;
                break;
            case 's':
            case 'S':
                if ( clipY < 1.0f ) 
                    clipY += clipPosDelta;
                break;
            default:
                frames = 0;
                break;
            }
        }
    }
    
    grGlideShutdown();
    return;
}
示例#6
0
void 
main(int argc, char **argv)
{
  float
    wWidth, wHeight;
  GrScreenResolution_t
    screenRes;
  int 
    numFrames = -1,
    frameCount = 0;
  int 
    i;
  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: test13 {320x200|320x240|400x256|512x384|640x480|800x600|640x200|640x350|640x400|960x720} {-n numFrames}\n");
          exit(-1);
        } 
      } else {
        fprintf(stderr, "Usage: test13 {320x200|320x240|400x256|512x384|640x480|800x600} {-n numFrames}\n");
        exit(-1);
      }
    }
  }

  puts( "\nTEST13:" );
  puts( "backface culling test.  Green triangle should be backface" );
  puts( "culled, thus only a red triangle should be visible." );
  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 );
  }

  /*
  ** Configure Glide to test backface culling
  */
  guColorCombineFunction( GR_COLORCOMBINE_CCRGB );
  grCullMode( GR_CULL_NEGATIVE );
  
  /*
  ** Render a green triangle on a red triangle.  The green triangle
  ** is clockwise and thus should not be rendered.  The red triangle
  ** is counterclockwise and should be rendered.
  */
  while ( 1 ) 
  {
    int i;
    GrVertex vtxlist[3];

    grBufferClear( 0, 0, 0 );

    vtxlist[0].x   = 160.f;
    vtxlist[0].y   = 100.f;

    vtxlist[1].x   = 320.f;
    vtxlist[1].y   = 380.f;

    vtxlist[2].x   = 480.f;
    vtxlist[2].y   = 100.f;

    for (i = 0; i < 3; i++) {
        vtxlist[i].x = WINSCALEX(vtxlist[i].x);
        vtxlist[i].y = WINSCALEY(vtxlist[i].y);
    }

    /*
    ** Red triangle (counterclockwise, should be visible)
    */
    grConstantColorValue( 0x000000FF );
    grDrawTriangle( &vtxlist[0], &vtxlist[2], &vtxlist[1] );

    /*
    ** Green triangle (clockwise, should be rejected)
    */
    grConstantColorValue( 0x0000FF00 );
    grDrawTriangle( &vtxlist[0], &vtxlist[1], &vtxlist[2] );

    grBufferSwap( 1 );

    if (kbhit())
    {
      getch();
      break;
    }
    frameCount++;
    if(frameCount < 0)
      frameCount = 0;
    if(frameCount == numFrames)
      break;
  }
  grGlideShutdown();
}
示例#7
0
文件: test42.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;
  FxBool               scrgrab = FXFALSE;
  char                 filename[256];
  FxU8                 subframe = 0;

  TlTexture            texture;
  FxU32                zrange[2];
  GrContext_t          gc = 0;
  FxU32                pixelformat = 0x0003; /* 16 bit 565 */
  static FxBool        useCCExt = 1;
  char                 textureFile[256];
  int                  bigTex = 0;
  FxBool               needToLoadNewTexture = FXFALSE;
  FxBool               umaIsEnabled = FXFALSE;

  float 
    xLeft,
    xRight,
    yTop,
    yBottom;

  /* Process Command Line Arguments */
  while(rv = tlGetOpt(argc, argv, "nrdxp", &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 'd':
      scrgrab = FXTRUE;
      frames = 5;      
      strcpy(filename, remArgs[0]);
      break;

    case 'p':
      pixelformat = tlGetPixelFormat( 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();
  }
    
  /* Initialize Glide */
  grGlideInit();
  assert(hwconfig = tlVoodooType());

  grGet(GR_ZDEPTH_MIN_MAX, 8, (FxI32 *)zrange);

  grSstSelect(0);

  tlInitGlideExt(&glideext);
  
  if (!glideext.combineext) {
    printf("Could not use COMBINE extension.\n");
    useCCExt = 0;
  }

  if (glideext.canDo32BitTexture) {
    printf("Using TEXFMT 32-bit extension.\n");
    strcpy(textureFile, "t256x32.3df"); /* 32 bits deep */
  } else {
    printf("Could not use TEXFMT 32-bit extension.\n");
    strcpy(textureFile, "miro.3df");    /* 16 bits deep */
  }

  if (glideext.umaExt) {
    printf("Using TEXUMA extension.\n");
    grEnable(GR_TEXTURE_UMA_EXT);
    umaIsEnabled = FXTRUE;
  } else {
    printf("Could not use TEXUMA extension.\n");
    grDisable(GR_TEXTURE_UMA_EXT);
    umaIsEnabled = FXFALSE;
  }

  if (glideext.grSstWinOpen) {
    gc = glideext.grSstWinOpen(tlGethWnd(),
                               resolution,
                               GR_REFRESH_60Hz,
                               GR_COLORFORMAT_ABGR,
                               GR_ORIGIN_UPPER_LEFT,
                               pixelformat,
                               2, 1);
  } else {
    gc = grSstWinOpen(tlGethWnd(),
                      resolution,
                      GR_REFRESH_60Hz,
                      GR_COLORFORMAT_ABGR,
                      GR_ORIGIN_UPPER_LEFT,
                      2, 1);
  }
  if (!gc) {
    printf("Could not allocate glide fullscreen context.\n");
    goto __errExit;
  }
  
  tlVertexLayout();
  tlConSet(0.0f, 0.0f, 1.0f, 0.5f, 
           60, 15, 0xffffff);
    
  /* Load texture data into system ram */
  assert(tlLoadTexture(textureFile,
                       &texture.info, 
                       &texture.tableType, 
                       &texture.tableData));
  /* Download texture data to TMU */
  grTexDownloadMipMap(GR_TMU0,
                      grTexMinAddress(GR_TMU0),
                      GR_MIPMAPLEVELMASK_BOTH,
                      &texture.info);
  if (texture.tableType != NO_TABLE) {
    grTexDownloadTable(texture.tableType,
                       &texture.tableData);
  }

  /* Select Texture As Source of all texturing operations */
  grTexSource(GR_TMU0,
              grTexMinAddress(GR_TMU0),
              GR_MIPMAPLEVELMASK_BOTH,
              &texture.info);


  /* Enable Bilinear Filtering + Mipmapping */
  grTexFilterMode(GR_TMU0,
                  GR_TEXTUREFILTER_BILINEAR,
                  GR_TEXTUREFILTER_BILINEAR);
  grTexMipMapMode(GR_TMU0,
                  GR_MIPMAP_NEAREST,
                  FXFALSE);

  xLeft   = tlScaleX( 0.2f );
  xRight  = tlScaleX( 0.8f );
  yTop    = tlScaleY( 0.2f );
  yBottom = tlScaleY( 0.8f );

  while(frames-- && tlOkToRender()) {
    GrVertex vtxA, vtxB, vtxC, vtxD;
    static TextureMode textureMode;

    if (hwconfig == TL_VOODOORUSH) {
      tlGetDimsByConst(resolution,
                       &scrWidth, 
                       &scrHeight);
        
      grClipWindow(0, 0, (FxU32) scrWidth, (FxU32) scrHeight);
    }

    grBufferClear(0x00, 0, zrange[1]);

    tlConOutput(  "m   : change lighting mode\n");
    tlConOutput(  "e   : toggle combine extension\n");
    tlConOutput(  "b   : big textures (if TEXFMT extension is available)\n");
    tlConOutput(  "u   : toggle UMA (if TEXUMA extension is available)\n");
    tlConOutput("Press any other key to quit\n");
    tlConOutput("Current Texture Mode: %s\n", textureModeNames[textureMode]);
    tlConOutput("COMBINE extension %s\n", cmodeName[useCCExt]);

    if (needToLoadNewTexture) {
      /*
       * This is only true if TEXFMT extension is available, which
       * implies 2k texture capability.  Also, this is only true if
       * the user has just hit 'b' for big texture testing.
       */
      assert(bigTex <= TEX_MAX);
      strcpy(textureFile, texFileNames[bigTex]);

      /* Redo all the texture loading stuff. */
      /* Load texture data into system ram */
      assert(tlLoadTexture(textureFile, &texture.info, &texture.tableType, 
                           &texture.tableData));
      /* Download texture data to TMU */
      grTexDownloadMipMap(GR_TMU0, grTexMinAddress(GR_TMU0),
                          GR_MIPMAPLEVELMASK_BOTH, &texture.info);
      if (texture.tableType != NO_TABLE) {
        grTexDownloadTable(texture.tableType, &texture.tableData);
      }
      
      /* Select Texture As Source of all texturing operations */
      grTexSource(GR_TMU0, grTexMinAddress(GR_TMU0), 
                  GR_MIPMAPLEVELMASK_BOTH, &texture.info);

      needToLoadNewTexture = FXFALSE;
    }

    if (useCCExt) {
#ifdef FX_GLIDE_NAPALM
      glideext.grTexColorCombineExt(GR_TMU0,
                                    GR_CMBX_ZERO, GR_FUNC_MODE_X, 
                                    GR_CMBX_LOCAL_TEXTURE_RGB, GR_FUNC_MODE_X, 
                                    GR_CMBX_ZERO, FXFALSE,
                                    GR_CMBX_B, FXFALSE,
                                    0, FXFALSE);
      switch(textureMode) {
      case DECAL:
        glideext.grColorCombineExt(GR_CMBX_TEXTURE_RGB, GR_FUNC_MODE_X, 
                                   GR_CMBX_ZERO, GR_FUNC_MODE_X, 
                                   GR_CMBX_ZERO, FXTRUE, 
                                   GR_CMBX_ZERO, FXFALSE,
                                   0, FXFALSE);
        break;
      case FLATLIT:
        glideext.grColorCombineExt(GR_CMBX_TEXTURE_RGB, GR_FUNC_MODE_X, 
                                   GR_CMBX_ZERO, GR_FUNC_MODE_X, 
                                   GR_CMBX_CONSTANT_COLOR, FXFALSE,
                                   GR_CMBX_ZERO, FXFALSE,
                                   0, FXFALSE);
        break;
      case RGBLIT:
        glideext.grColorCombineExt(GR_CMBX_TEXTURE_RGB, GR_FUNC_MODE_X, 
                                   GR_CMBX_ZERO, GR_FUNC_MODE_X, 
                                   GR_CMBX_ITRGB, FXFALSE,
                                   GR_CMBX_ZERO, FXFALSE,
                                   0, FXFALSE);
        break;
      case WHITELIT:
        glideext.grColorCombineExt(GR_CMBX_TEXTURE_RGB, GR_FUNC_MODE_X, 
                                   GR_CMBX_ITALPHA, GR_FUNC_MODE_ZERO, 
                                   GR_CMBX_B, FXFALSE,
                                   GR_CMBX_ZERO, FXFALSE,
                                   0, FXFALSE);
        glideext.grAlphaCombineExt(GR_CMBX_ITALPHA, GR_FUNC_MODE_X, 
                                   GR_CMBX_ZERO, GR_FUNC_MODE_X, 
                                   GR_CMBX_ZERO, FXTRUE,
                                   GR_CMBX_ALOCAL, FXFALSE,
                                   0, FXFALSE);
        break;
      case SPECALPHA:
        glideext.grColorCombineExt(GR_CMBX_TEXTURE_RGB, GR_FUNC_MODE_X, 
                                   GR_CMBX_ITALPHA, GR_FUNC_MODE_ZERO,
                                   GR_CMBX_ITRGB, FXFALSE,
                                   GR_CMBX_B, FXFALSE,
                                   0, FXFALSE);
        glideext.grAlphaCombineExt(GR_CMBX_ITALPHA, GR_FUNC_MODE_X, 
                                   GR_CMBX_ZERO, GR_FUNC_MODE_X, 
                                   GR_CMBX_ZERO, FXTRUE,
                                   GR_CMBX_ALOCAL, FXFALSE,
                                   0, FXFALSE);
        break;
      }
#endif
    }
    else {
      /* Set up Render State - Decal Texture - color combine set in render loop */
      grTexCombine(GR_TMU0,
                   GR_COMBINE_FUNCTION_LOCAL,
                   GR_COMBINE_FACTOR_NONE,
                   GR_COMBINE_FUNCTION_NONE,
                   GR_COMBINE_FACTOR_NONE,
                   FXFALSE, FXFALSE);

      switch(textureMode) {
      case DECAL:
        grColorCombine(GR_COMBINE_FUNCTION_SCALE_OTHER,
                       GR_COMBINE_FACTOR_ONE,
                       GR_COMBINE_LOCAL_NONE,
                       GR_COMBINE_OTHER_TEXTURE,
                       FXFALSE);
        break;
      case FLATLIT:
        grColorCombine(GR_COMBINE_FUNCTION_SCALE_OTHER,
                       GR_COMBINE_FACTOR_LOCAL,
                       GR_COMBINE_LOCAL_CONSTANT,
                       GR_COMBINE_OTHER_TEXTURE,
                       FXFALSE);
        break;
      case RGBLIT:
        grColorCombine(GR_COMBINE_FUNCTION_SCALE_OTHER,
                       GR_COMBINE_FACTOR_LOCAL,
                       GR_COMBINE_LOCAL_ITERATED,
                       GR_COMBINE_OTHER_TEXTURE,
                       FXFALSE);
        break;
      case WHITELIT:
        grColorCombine(GR_COMBINE_FUNCTION_SCALE_OTHER,
                       GR_COMBINE_FACTOR_LOCAL_ALPHA,
                       GR_COMBINE_LOCAL_NONE,
                       GR_COMBINE_OTHER_TEXTURE,
                       FXFALSE);
        grAlphaCombine(GR_COMBINE_FUNCTION_LOCAL,
                       GR_COMBINE_FACTOR_NONE,
                       GR_COMBINE_LOCAL_ITERATED,
                       GR_COMBINE_OTHER_TEXTURE,
                       FXFALSE);
        break;
      case SPECALPHA:
        grColorCombine(GR_COMBINE_FUNCTION_SCALE_OTHER_ADD_LOCAL_ALPHA,
                       GR_COMBINE_FACTOR_LOCAL,
                       GR_COMBINE_LOCAL_ITERATED,
                       GR_COMBINE_OTHER_TEXTURE,
                       FXFALSE);
        grAlphaCombine(GR_COMBINE_FUNCTION_LOCAL,
                       GR_COMBINE_FACTOR_NONE,
                       GR_COMBINE_LOCAL_ITERATED,
                       GR_COMBINE_OTHER_TEXTURE,
                       FXFALSE);
        break;
      }
    }
        
    /*---- 
      A-B
      |\|
      C-D
      -----*/
    vtxA.oow = 1.0f;
    vtxB = vtxC = vtxD = vtxA;

    vtxA.x = vtxC.x = xLeft;
    vtxB.x = vtxD.x = xRight;
    vtxA.y = vtxB.y = yTop;
    vtxC.y = vtxD.y = yBottom;

    vtxA.tmuvtx[0].sow = vtxC.tmuvtx[0].sow = 0.0f;
    vtxB.tmuvtx[0].sow = vtxD.tmuvtx[0].sow = 255.0f;
    vtxA.tmuvtx[0].tow = vtxB.tmuvtx[0].tow = 0.0f;
    vtxC.tmuvtx[0].tow = vtxD.tmuvtx[0].tow = 255.0f;

    vtxA.r = 255.0f, vtxA.g =   0.0f, vtxA.b =   0.0f, vtxA.a = 255.0f;
    vtxB.r =   0.0f, vtxB.g = 255.0f, vtxB.b =   0.0f, vtxB.a = 128.0f;
    vtxC.r =   0.0f, vtxC.g =   0.0f, vtxC.b = 255.0f, vtxC.a = 128.0f;
    vtxD.r =   0.0f, vtxD.g =   0.0f, vtxD.b =   0.0f, vtxD.a =   0.0f;

    grConstantColorValue(0xFF0000FFUL);
    grTexSource(GR_TMU0,
                grTexMinAddress(GR_TMU0),
                GR_MIPMAPLEVELMASK_BOTH,
                &texture.info);

    grDrawTriangle(&vtxA, &vtxD, &vtxC);
    grDrawTriangle(&vtxA, &vtxB, &vtxD);

    tlConRender();
    tlConClear();
    grBufferSwap(1);
    grFinish();

    /* grab the frame buffer */
    if (scrgrab) {
      char fname[256], tmp[32];
      FxU16 cnt;

      cnt = strcspn(filename, ".");
      strncpy(fname, filename, cnt);
      fname[cnt] = 0;
      sprintf(tmp,"_%d\0", subframe);
      strcat(fname, tmp);
      strcat(fname, filename+cnt);
      if (!tlScreenDump(fname, (FxU16)scrWidth, (FxU16)scrHeight))
        printf("Cannot open %s\n", filename);

      /* cycle through all mode */
      textureMode++;
      if (textureMode > SPECALPHA) textureMode = DECAL;

      subframe++;
    }
        
    while(tlKbHit()) {
      const char curKey = tlGetCH();

      switch(curKey) {
      case 'e':
      case 'E':
        useCCExt = (!useCCExt);
        if (!glideext.combineext)
          useCCExt = 0;
        break;
      case 'm':
      case 'M':
        textureMode++;
        if (textureMode > SPECALPHA) textureMode = DECAL;
        break;
      case 'b':
      case 'B':
        /* Cycle through some texture sizes */
        if (glideext.canDo2kTexture) {
          needToLoadNewTexture = FXTRUE;
          bigTex = (bigTex + 1) % (TEX_MAX + 1); /* [0,...,TEX_MAX] */
          printf ("%s", texWidthString[bigTex]);
        }
        break;
      case 'u':
      case 'U':
        if (glideext.umaExt) {
          /* Toggle UMA on/off */
          if (umaIsEnabled) {
            grDisable(GR_TEXTURE_UMA_EXT);
            printf ("UMA extension is disabled.\n");
            umaIsEnabled = FXFALSE;
          } else {
            grEnable(GR_TEXTURE_UMA_EXT);
            printf ("UMA extension is enabled.\n");
            umaIsEnabled = FXTRUE;
          }
        }
        break;
      default:
        frames = 0;
        break;
      }
    }
  }
    
 __errExit:    
  grGlideShutdown();
}