?? dxut.cpp
字號(hào):
WCHAR wszPath[MAX_PATH+1];
if( GetSystemDirectory( wszPath, MAX_PATH+1 ) )
{
StringCchCat( wszPath, MAX_PATH, L"\\winmm.dll" );
HINSTANCE hInstWinMM = LoadLibrary( wszPath );
if( hInstWinMM )
{
LPTIMEBEGINPERIOD pTimeBeginPeriod = (LPTIMEBEGINPERIOD)GetProcAddress( hInstWinMM, "timeBeginPeriod" );
if( NULL != pTimeBeginPeriod )
pTimeBeginPeriod(1);
FreeLibrary(hInstWinMM);
}
}
GetDXUTState().SetShowMsgBoxOnError( bShowMsgBoxOnError );
GetDXUTState().SetHandleDefaultHotkeys( bHandleDefaultHotkeys );
GetDXUTState().SetHandleAltEnter( bHandleAltEnter );
if( bParseCommandLine )
DXUTParseCommandLine();
// Verify D3DX version
if( !D3DXCheckVersion( D3D_SDK_VERSION, D3DX_SDK_VERSION ) )
{
DXUTDisplayErrorMessage( DXUTERR_INCORRECTVERSION );
return DXUT_ERR( L"D3DXCheckVersion", DXUTERR_INCORRECTVERSION );
}
// Create a Direct3D object if one has not already been created
IDirect3D9* pD3D = DXUTGetD3DObject();
if( pD3D == NULL )
{
// This may fail if DirectX 9 isn't installed
// This may fail if the DirectX headers are out of sync with the installed DirectX DLLs
pD3D = DXUT_Dynamic_Direct3DCreate9( D3D_SDK_VERSION );
GetDXUTState().SetD3D( pD3D );
}
if( pD3D == NULL )
{
// If still NULL, then something went wrong
DXUTDisplayErrorMessage( DXUTERR_NODIRECT3D );
return DXUT_ERR( L"Direct3DCreate9", DXUTERR_NODIRECT3D );
}
// Reset the timer
DXUTGetGlobalTimer()->Reset();
GetDXUTState().SetDXUTInited( true );
return S_OK;
}
//--------------------------------------------------------------------------------------
// Parses the command line for parameters. See DXUTInit() for list
//--------------------------------------------------------------------------------------
void DXUTParseCommandLine()
{
WCHAR* strCmdLine = GetCommandLine();
// Skip past program name (first token in command line).
if (*strCmdLine == L'"') // Check for and handle quoted program name
{
strCmdLine++;
// Skip over until another double-quote or a null
while (*strCmdLine && (*strCmdLine != L'"'))
strCmdLine++;
// Skip over double-quote
if (*strCmdLine == L'"')
strCmdLine++;
}
else
{
// First token wasn't a quote
while (*strCmdLine > L' ')
strCmdLine++;
}
for(;;)
{
// Skip past any white space preceding the next token
while (*strCmdLine && (*strCmdLine <= L' '))
strCmdLine++;
if( *strCmdLine == 0 )
break;
WCHAR strFlag[256];
int nFlagLen = 0;
// Skip past the flag marker
if( *strCmdLine == L'/' ||
*strCmdLine == L'-' )
strCmdLine++;
// Compare the first N letters w/o regard to case
StringCchCopy( strFlag, 256, L"adapter" ); nFlagLen = (int) wcslen(strFlag);
if( _wcsnicmp( strCmdLine, strFlag, nFlagLen ) == 0 )
{
if( DXUTGetCmdParam( strCmdLine, strFlag, nFlagLen ) )
{
int nAdapter = _wtoi(strFlag);
GetDXUTState().SetOverrideAdapterOrdinal( nAdapter );
}
continue;
}
StringCchCopy( strFlag, 256, L"windowed" ); nFlagLen = (int) wcslen(strFlag);
if( _wcsnicmp( strCmdLine, strFlag, nFlagLen ) == 0 )
{
GetDXUTState().SetOverrideWindowed( true );
strCmdLine += nFlagLen;
continue;
}
StringCchCopy( strFlag, 256, L"fullscreen" ); nFlagLen = (int) wcslen(strFlag);
if( _wcsnicmp( strCmdLine, strFlag, nFlagLen ) == 0 )
{
GetDXUTState().SetOverrideFullScreen( true );
strCmdLine += nFlagLen;
continue;
}
StringCchCopy( strFlag, 256, L"forcehal" ); nFlagLen = (int) wcslen(strFlag);
if( _wcsnicmp( strCmdLine, strFlag, nFlagLen ) == 0 )
{
GetDXUTState().SetOverrideForceHAL( true );
strCmdLine += nFlagLen;
continue;
}
StringCchCopy( strFlag, 256, L"forceref" ); nFlagLen = (int) wcslen(strFlag);
if( _wcsnicmp( strCmdLine, strFlag, nFlagLen ) == 0 )
{
GetDXUTState().SetOverrideForceREF( true );
strCmdLine += nFlagLen;
continue;
}
StringCchCopy( strFlag, 256, L"forcepurehwvp" ); nFlagLen = (int) wcslen(strFlag);
if( _wcsnicmp( strCmdLine, strFlag, nFlagLen ) == 0 )
{
GetDXUTState().SetOverrideForcePureHWVP( true );
strCmdLine += nFlagLen;
continue;
}
StringCchCopy( strFlag, 256, L"forcehwvp" ); nFlagLen = (int) wcslen(strFlag);
if( _wcsnicmp( strCmdLine, strFlag, nFlagLen ) == 0 )
{
GetDXUTState().SetOverrideForceHWVP( true );
strCmdLine += nFlagLen;
continue;
}
StringCchCopy( strFlag, 256, L"forceswvp" ); nFlagLen = (int) wcslen(strFlag);
if( _wcsnicmp( strCmdLine, strFlag, nFlagLen ) == 0 )
{
GetDXUTState().SetOverrideForceSWVP( true );
strCmdLine += nFlagLen;
continue;
}
StringCchCopy( strFlag, 256, L"width" ); nFlagLen = (int) wcslen(strFlag);
if( _wcsnicmp( strCmdLine, strFlag, nFlagLen ) == 0 )
{
if( DXUTGetCmdParam( strCmdLine, strFlag, nFlagLen ) )
{
int nWidth = _wtoi(strFlag);
GetDXUTState().SetOverrideWidth( nWidth );
}
continue;
}
StringCchCopy( strFlag, 256, L"height" ); nFlagLen = (int) wcslen(strFlag);
if( _wcsnicmp( strCmdLine, strFlag, nFlagLen ) == 0 )
{
if( DXUTGetCmdParam( strCmdLine, strFlag, nFlagLen ) )
{
int nHeight = _wtoi(strFlag);
GetDXUTState().SetOverrideHeight( nHeight );
}
continue;
}
StringCchCopy( strFlag, 256, L"startx" );
nFlagLen = (int) wcslen(strFlag);
if( _wcsnicmp( strCmdLine, strFlag, nFlagLen ) == 0 )
{
if( DXUTGetCmdParam( strCmdLine, strFlag, nFlagLen ) )
{
int nX = _wtoi(strFlag);
GetDXUTState().SetOverrideStartX( nX );
}
continue;
}
StringCchCopy( strFlag, 256, L"starty" );
nFlagLen = (int) wcslen(strFlag);
if( _wcsnicmp( strCmdLine, strFlag, nFlagLen ) == 0 )
{
if( DXUTGetCmdParam( strCmdLine, strFlag, nFlagLen ) )
{
int nY = _wtoi(strFlag);
GetDXUTState().SetOverrideStartY( nY );
}
continue;
}
StringCchCopy( strFlag, 256, L"constantframetime" ); nFlagLen = (int) wcslen(strFlag);
if( _wcsnicmp( strCmdLine, strFlag, nFlagLen ) == 0 )
{
float fTimePerFrame;
if( DXUTGetCmdParam( strCmdLine, strFlag, nFlagLen ) )
fTimePerFrame = (float)wcstod( strFlag, NULL );
else
fTimePerFrame = 0.0333f;
GetDXUTState().SetOverrideConstantFrameTime( true );
GetDXUTState().SetOverrideConstantTimePerFrame( fTimePerFrame );
DXUTSetConstantFrameTime( true, fTimePerFrame );
continue;
}
StringCchCopy( strFlag, 256, L"quitafterframe" ); nFlagLen = (int) wcslen(strFlag);
if( _wcsnicmp( strCmdLine, strFlag, nFlagLen ) == 0 )
{
if( DXUTGetCmdParam( strCmdLine, strFlag, nFlagLen ) )
{
int nFrame = _wtoi(strFlag);
GetDXUTState().SetOverrideQuitAfterFrame( nFrame );
}
continue;
}
StringCchCopy( strFlag, 256, L"noerrormsgboxes" ); nFlagLen = (int) wcslen(strFlag);
if( _wcsnicmp( strCmdLine, strFlag, nFlagLen ) == 0 )
{
GetDXUTState().SetShowMsgBoxOnError( false );
strCmdLine += nFlagLen;
continue;
}
StringCchCopy( strFlag, 256, L"automation" ); nFlagLen = (int) wcslen(strFlag);
if( _wcsnicmp( strCmdLine, strFlag, nFlagLen ) == 0 )
{
GetDXUTState().SetAutomation( true );
strCmdLine += nFlagLen;
continue;
}
// Unrecognized flag
StringCchCopy( strFlag, 256, strCmdLine );
WCHAR* strSpace = strFlag;
while (*strSpace && (*strSpace > L' '))
strSpace++;
*strSpace = 0;
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -