Example #1
0
int glide64InitGfx(void)
{
   rdp_reset ();

   if (!grSstWinOpen())
   {
      ERRLOG("Error setting display mode");
      return false;
   }

   // get the # of TMUs available
   voodoo.tex_max_addr = grTexMaxAddress(GR_TMU0);

   grStipplePattern(settings.stipple_pattern);

   InitCombine();

   if (settings.fog)
   {
      guFogGenerateLinear(0.0f, 255.0f);
   }
   else
      settings.fog = false;

   grDepthBufferMode (GR_DEPTHBUFFER_ZBUFFER);
   grDepthBufferFunction(GR_CMP_LESS);
   grDepthMask(FXTRUE);

   settings.res_x = settings.scr_res_x;
   settings.res_y = settings.scr_res_y;
   ChangeSize();

   guLoadTextures ();
   ClearCache ();

   return true;
}
Example #2
0
//==================================================================================
//	GMain_InitGlideRegisters
//==================================================================================
geBoolean GMain_InitGlideRegisters(void)
{
	//
	// Setup card register states
	//

	// fix up the z-buffer
	grDepthBufferMode( GR_DEPTHBUFFER_ZBUFFER );
	grDepthBufferFunction( GR_CMP_GEQUAL );
	grDepthMask( FXTRUE );
	
	// Fixup the transparent color
	grChromakeyMode(GR_CHROMAKEY_DISABLE);			// Off by default, on for decals though...
	grChromakeyValue(1);

	// Fixup the Mipmapping 
	//	TMU
	//	Bias			-32...+31
	//	Detail scale	0...7
	//	Detail Max		0...1.0
	grTexDetailControl(TMU[0], 0, 1, 1.0f);

	// -8... 7.75
	grTexLodBiasValue(TMU[0], -1.0f);
	//grTexLodBiasValue(TMU[0], 7.0f);

	// Tell it how we like it...
	guColorCombineFunction( GR_COLORCOMBINE_DECAL_TEXTURE );

	guTexCombineFunction( TMU[0], GR_TEXTURECOMBINE_DECAL );
	
	//rTexMipMapMode( TMU[0], GR_MIPMAP_NEAREST, FXFALSE);
	//grTexMipMapMode( TMU[0], GR_MIPMAP_DISABLE, FXFALSE );

	//grTexFilterMode( TMU[0], GR_TEXTUREFILTER_POINT_SAMPLED,GR_TEXTUREFILTER_BILINEAR);
	//grTexFilterMode( TMU[0], GR_TEXTUREFILTER_BILINEAR, GR_TEXTUREFILTER_POINT_SAMPLED);
	grTexFilterMode( TMU[0], GR_TEXTUREFILTER_BILINEAR, GR_TEXTUREFILTER_BILINEAR);
	grTexClampMode( TMU[0], GR_TEXTURECLAMP_WRAP,GR_TEXTURECLAMP_WRAP);

    grTexCombine( TMU[0],
                  GR_COMBINE_FUNCTION_LOCAL,
                  GR_COMBINE_FACTOR_NONE,
                  GR_COMBINE_FUNCTION_LOCAL,
                  GR_COMBINE_FACTOR_NONE,
                  FXFALSE, FXFALSE );
	
	
	// turn on gouraud shading
	grColorCombine( GR_COMBINE_FUNCTION_SCALE_OTHER,
					GR_COMBINE_FACTOR_LOCAL,
					GR_COMBINE_LOCAL_ITERATED,
					GR_COMBINE_OTHER_TEXTURE,
					FXFALSE );
	
	
	grAlphaCombine( GR_COMBINE_FUNCTION_BLEND_OTHER,
					GR_COMBINE_FACTOR_LOCAL_ALPHA,
					GR_COMBINE_LOCAL_ITERATED,
					GR_COMBINE_OTHER_TEXTURE,
					FXFALSE );
	
	/*
	grAlphaCombine( GR_COMBINE_FUNCTION_LOCAL,
                    GR_COMBINE_FACTOR_LOCAL,
                    GR_COMBINE_LOCAL_ITERATED,
                    GR_COMBINE_OTHER_TEXTURE,
                    FXFALSE );
	*/

	//grAlphaControlsITRGBLighting(FXTRUE);
	//grGlideShamelessPlug(FXTRUE);

	if (g_BoardInfo.NumTMU >= 2)
	{
		grTexDetailControl(TMU[1], 0, 1, 0.3f);
		grTexLodBiasValue(TMU[1], 0.3f);

		guTexCombineFunction( TMU[1], GR_TEXTURECOMBINE_DECAL );
	
		grTexFilterMode( TMU[1], GR_TEXTUREFILTER_BILINEAR, GR_TEXTUREFILTER_BILINEAR);
		grTexClampMode( TMU[1], GR_TEXTURECLAMP_CLAMP,GR_TEXTURECLAMP_CLAMP);

		grTexCombine(	TMU[1], 
						GR_COMBINE_FUNCTION_SCALE_OTHER, 
						GR_COMBINE_FACTOR_LOCAL,
						GR_COMBINE_FUNCTION_SCALE_OTHER, 
						GR_COMBINE_FACTOR_LOCAL,
						FXFALSE, FXFALSE ); 

		// Always texture clamp on second TMU (it only uses lightmaps for now)
		grTexClampMode(TMU[1], GR_TEXTURECLAMP_CLAMP,GR_TEXTURECLAMP_CLAMP);

		grHints(GR_HINT_STWHINT, GR_STWHINT_ST_DIFF_TMU0 | GR_STWHINT_ST_DIFF_TMU1);
	}

	//GMain_SetFogEnable(GE_TRUE, 0.0f, 255.0f, 0.0f, 500.0f, 1500.0f);
	GMain_SetFogEnable(GE_FALSE, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f);

	return GE_TRUE;
}
Example #3
0
int _3dfx_Init( void )
{
   int         i;

   mprintf( ( 0, "Initializing 3Dfx Interactive Voodoo Graphics hardware\n" ) );
   grGlideInit();
   grErrorSetCallback( MyErrorHandler );

   if ( !grSstQueryHardware( &hwconfig ) )
   {
      mprintf( ( 0, "3Dfx Interactive Voodoo Graphics not found!" ) );
      return 0;
   }
   grSstSelect( 0 );
   if ( !grSstOpen( GR_RESOLUTION_640x480,
                    GR_REFRESH_60Hz,
                    GR_COLORFORMAT_ARGB,
                    GR_ORIGIN_UPPER_LEFT,
                    GR_SMOOTHING_ENABLE,
                    2 ) )
   {
      mprintf( ( 0, "3Dfx Interactive Voodoo Graphics not opened!" ) );
      return 0;
   }

   if ( getenv( "GLIDE_OFF" ) != 0 )
   {
      mprintf( ( 0, "3Dfx Interactive Voodoo Graphics disabled!" ) );
      return 0;
   }

   grDepthBufferMode( GR_DEPTHBUFFER_DISABLE );
   grBufferClear( 0x00000000, 0, 0 );
   grCullMode( GR_CULL_DISABLE );

   /*
   ** configure environment variable controlled options
   */
   if ( getenv( "GLIDE_NO_BILINEAR" ) )
      _3dfx_no_bilinear = 1;
   if ( getenv( "GLIDE_NO_DDRAW" ) )
      _3dfx_skip_ddraw = 1;
   if ( getenv( "GLIDE_NO_TEXTURE" ) )
      _3dfx_no_texture = 1;
   if ( getenv( "GLIDE_NO_TRANSPARENCY" ) )
      _3dfx_allow_transparency = 0;
   else
      _3dfx_allow_transparency = 1;
   if ( getenv( "GLIDE_NO_SYNC" ) )
      _3dfx_should_sync = 0;
   else
      _3dfx_should_sync = 1;

   /*
   ** allocate texture memory
   */
   for ( i = 0; i < MAX_BITMAP_FILES; i++ )
   {
      _3dfx_texture_info[i].handle = GR_NULL_MIPMAP_HANDLE;
   }

   _3dfx_current_handle = 0;
   for ( i = 0; i < _3DFX_MAX_HANDLES; i++ )
   {
      GrMipMapId_t id;

      id = grTexAllocateMemory( GR_TMU0,
                                GR_MIPMAPLEVELMASK_BOTH,
                                64, 64,
                                GR_TEXFMT_ARGB_1555,
                                GR_MIPMAP_NEAREST,
                                GR_LOD_1, GR_LOD_64,
                                GR_ASPECT_1x1,
                                GR_TEXTURECLAMP_WRAP, GR_TEXTURECLAMP_WRAP,
                                GR_TEXTUREFILTER_BILINEAR, _3dfx_no_bilinear ? GR_TEXTUREFILTER_POINT_SAMPLED : GR_TEXTUREFILTER_BILINEAR,
                                1.0F,
                                FXFALSE );

      if ( id == GR_NULL_MIPMAP_HANDLE )
      {
         mprintf( ( 0, "            - unexpected null mmid returned\n" ) );
         exit( 1 );
      }
   }

   return 1;
}
Example #4
0
int
sage_bind (sageContext *ctx, void *win, int width, int height)
{
    if (hardware < 0) {
	return -1;
    }

    if (ctx == NULL || win == NULL) {
	if (current != NULL) {
	    /* unbind */
	    grSstWinClose(current->gr_ctx);
	    current = NULL;
	}
	return 0;
    }
    if (ctx == current) {
	if (win == current->drawable) {
	    /* nop */
	    return 0;
	}
	/* XXX can't rebind */
	return -1;
    }
    if (ctx->gr_ctx != 0) {
	/* XXX can't rebind */
	return -1;
    }

    if (hwext_pixext) {
	ctx->gr_ctx = gfSstWinOpenExt((int)win,
				findBestRes(width, height),
				GR_REFRESH_60Hz,
				GR_COLORFORMAT_ABGR,
				GR_ORIGIN_LOWER_LEFT,
				ctx->fmt, 2, 1);
    } else if (ctx->fmt == GR_PIXFMT_RGB_565) {
	ctx->gr_ctx = grSstWinOpen((int)win,
				findBestRes(width, height),
				GR_REFRESH_60Hz,
				GR_COLORFORMAT_ABGR,
				GR_ORIGIN_LOWER_LEFT, 2, 1);
    }
    if (ctx->gr_ctx == 0) {
	return -1;
    }
    ctx->drawable = win;
    current = ctx;

    /* XXX implement Glide{Get|Set}State */
    setupGrVertexLayout();
    grDepthBufferMode(GR_DEPTHBUFFER_ZBUFFER);
    drv_setupDepth();
    drv_setupTexture();

    getGeometry(&screen_width, &screen_height);

    GLCALL(Viewport)(0, 0, width, height);

    /* XXX grDisable(GR_PASSTHRU); */
    return 0;
}
Example #5
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;
}
Example #6
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 */