示例#1
0
文件: tr_init.c 项目: Lrns123/jkaq3
void R_ScreenShotPNG_f (void) {
	char		checkname[MAX_OSPATH];
	static	int	lastNumber = -1;
	qboolean	silent;

	if ( !strcmp( ri.Cmd_Argv(1), "levelshot" ) ) {
		R_LevelShot();
		return;
	}

	if ( !strcmp( ri.Cmd_Argv(1), "silent" ) ) {
		silent = qtrue;
	} else {
		silent = qfalse;
	}

	if ( ri.Cmd_Argc() == 2 && !silent ) {
		// explicit filename
		Com_sprintf( checkname, MAX_OSPATH, "screenshots/%s.png", ri.Cmd_Argv( 1 ) );
	} else {
		// scan for a free filename

		// if we have saved a previous screenshot, don't scan
		// again, because recording demo avis can involve
		// thousands of shots
		if ( lastNumber == -1 ) {
			lastNumber = 0;
		}
		// scan for a free number
		for ( ; lastNumber <= 9999 ; lastNumber++ ) {
			R_ScreenshotFilenamePNG( lastNumber, checkname );

      if (!ri.FS_FileExists( checkname ))
      {
        break; // file doesn't exist
      }
		}

		if ( lastNumber == 10000 ) {
			ri.Printf (PRINT_ALL, "ScreenShot: Couldn't create a file\n"); 
			return;
 		}

		lastNumber++;
	}

	R_TakeScreenshot( 0, 0, glConfig.vidWidth, glConfig.vidHeight, checkname, SSF_PNG );

	if ( !silent ) {
		ri.Printf (PRINT_ALL, "Wrote %s\n", checkname);
	}
}
示例#2
0
/*
==================
R_ScreenShot_f

screenshot[JPEG|PNG] [silent | <filename>]
==================
*/
void R_ScreenShot_f( void )
{
	char       checkname[ MAX_OSPATH ];
	int        len;
	static int lastNumber = -1;
	ssFormat_t format;
	qboolean   silent;

	if ( !Q_stricmp( ri.Cmd_Argv( 0 ), "screenshotJPEG" ) )
	{
		format = SSF_JPEG;
	}
	else if ( !Q_stricmp( ri.Cmd_Argv( 0 ), "screenshotPNG" ) )
	{
		format = SSF_PNG;
	}
	else
	{
		format = SSF_TGA;
	}

	if ( !strcmp( ri.Cmd_Argv( 1 ), "silent" ) )
	{
		silent = qtrue;
	}
	else
	{
		silent = qfalse;
	}

	if ( ri.Cmd_Argc() == 2 && !silent )
	{
		// explicit filename
		switch ( format )
		{
			case SSF_TGA:
				Com_sprintf( checkname, MAX_OSPATH, "screenshots/%s.tga", ri.Cmd_Argv( 1 ) );
				break;

			case SSF_JPEG:
				Com_sprintf( checkname, MAX_OSPATH, "screenshots/%s.jpeg", ri.Cmd_Argv( 1 ) );
				break;

			case SSF_PNG:
				Com_sprintf( checkname, MAX_OSPATH, "screenshots/%s.png", ri.Cmd_Argv( 1 ) );
				break;
		}
	}
	else
	{
		// scan for a free filename

		// if we have saved a previous screenshot, don't scan
		// again, because recording demo avis can involve
		// thousands of shots
		if ( lastNumber == -1 )
		{
			lastNumber = 0;
		}

		// scan for a free number
		for ( ; lastNumber <= 9999; lastNumber++ )
		{
			switch ( format )
			{
				case SSF_TGA:
					R_ScreenshotFilename( lastNumber, checkname );
					break;

				case SSF_JPEG:
					R_ScreenshotFilenameJPEG( lastNumber, checkname );
					break;

				case SSF_PNG:
					R_ScreenshotFilenamePNG( lastNumber, checkname );
					break;
			}

			len = ri.FS_ReadFile( checkname, NULL );

			if ( len <= 0 )
			{
				break; // file doesn't exist
			}
		}

		if ( lastNumber >= 10000 )
		{
			ri.Printf( PRINT_ALL, "ScreenShot: Couldn't create a file\n" );
			return;
		}

		lastNumber++;
	}

	switch ( format )
	{
		case SSF_TGA:
			R_TakeScreenshot( 0, 0, glConfig.vidWidth, glConfig.vidHeight, checkname );
			break;

		case SSF_JPEG:
			R_TakeScreenshotJPEG( 0, 0, glConfig.vidWidth, glConfig.vidHeight, checkname );
			break;

		case SSF_PNG:
			R_TakeScreenshotPNG( 0, 0, glConfig.vidWidth, glConfig.vidHeight, checkname );
			break;
	}

	if ( !silent )
	{
		ri.Printf( PRINT_ALL, "Wrote %s\n", checkname );
	}
}