Пример #1
0
//-----------------------------------------------------------------------------
// Name: CMyD3DApplication()
// Desc: Constructor
//-----------------------------------------------------------------------------
CMyD3DApplication::CMyD3DApplication()
{
    // Override base class members
    m_strWindowTitle     = _T("OptimizedMesh: Optimizing Meshes in D3D");
    m_bUseDepthBuffer    = TRUE;
    m_bShowCursorWhenFullscreen = TRUE;

    // Initialize member variables
    m_bShowVertexCacheOptimized = TRUE;  
    m_bShowStripReordered = FALSE; 
    m_bShowSingleStrip = TRUE;
    m_bShowStrips = FALSE;
    m_bShowSingleStrip = FALSE;
    m_bForce32ByteFVF = TRUE;

    m_dwMemoryOptions = D3DXMESH_MANAGED;

    m_pFont              = new CD3DFont( _T("Arial"), 12, D3DFONT_BOLD );
    
    _tcscpy( m_strInitialDir, DXUtil_GetDXSDKMediaPath() );
    _tcscpy( m_strMeshFilename, _T("knot.x") );

    m_cObjectsPerSide = 1;

    // initialize mesh data structures
    m_dwNumMaterials = 0;
    m_pMeshTextures = NULL;
    m_pMeshMaterials = NULL;
}
Пример #2
0
//-----------------------------------------------------------------------------
// Name: OnReadFile()
// Desc: Reads a file contain a collection of DirectInput force feedback 
//       effects.  It creates each of effect read in and stores it 
//       in the linked list, g_EffectsList.
//-----------------------------------------------------------------------------
HRESULT OnReadFile( HWND hDlg )
{
    HRESULT hr;

    static TCHAR strFileName[MAX_PATH] = TEXT("");
    static TCHAR strPath[MAX_PATH] = TEXT("");

    // Setup the OPENFILENAME structure
    OPENFILENAME ofn = { sizeof(OPENFILENAME), hDlg, NULL,
                         TEXT("FEdit Files\0*.ffe\0All Files\0*.*\0\0"), NULL,
                         0, 1, strFileName, MAX_PATH, NULL, 0, strPath,
                         TEXT("Open FEdit File"),
                         OFN_FILEMUSTEXIST|OFN_HIDEREADONLY, 0, 0,
                         TEXT(".ffe"), 0, NULL, NULL };

    // Get the default media path (something like C:\DXSDK\SAMPLES\MULTIMEDIA\DINPUT\MEDIA)
    if( '\0' == strPath[0] )
        _tcscpy( strPath, DXUtil_GetDXSDKMediaPath() );

    // Display the OpenFileName dialog. Then, try to load the specified file
    if( FALSE == GetOpenFileName( &ofn ) )
        return S_OK;

    EmptyEffectList();

    // Enumerate the effects in the file selected, and create them in the callback
    if( FAILED( hr = g_pFFDevice->EnumEffectsInFile( strFileName, 
                                                     EnumAndCreateEffectsCallback, 
                                                     NULL, DIFEF_MODIFYIFNEEDED ) ) )
        return hr;

    // Remember the path for next time
    _tcscpy( strPath, strFileName );
    TCHAR* strLastSlash = _tcsrchr( strPath, '\\' );
    strLastSlash[0] = '\0';

    // If list of effects is empty, then we haven't been able to create any effects
    if( g_EffectsList.pNext == &g_EffectsList )
    {
        // Pop up a box informing the user
        MessageBox( hDlg, _T("Unable to create any effects."),
                          _T("ReadFFE"), MB_ICONEXCLAMATION | MB_OK );
        EnableWindow( GetDlgItem( hDlg, IDC_PLAY_EFFECTS ), FALSE );
    }
    else
    {
        // We have effects so enable the 'play effects' button
        EnableWindow( GetDlgItem( hDlg, IDC_PLAY_EFFECTS ), TRUE );
    }

    return S_OK;
}
Пример #3
0
//-----------------------------------------------------------------------------
// Name: OnInitDialog()
// Desc: Initializes the dialogs (sets up UI controls, etc.)
//-----------------------------------------------------------------------------
HRESULT OnInitDialog( HWND hDlg )
{
    HRESULT hr; 
  
    // Load the icon
    HICON hIcon = LoadIcon( g_hInst, MAKEINTRESOURCE( IDR_MAINFRAME ) );

    // Set the icon for this dialog.
    SendMessage( hDlg, WM_SETICON, ICON_BIG,   (LPARAM) hIcon );  // Set big icon
    SendMessage( hDlg, WM_SETICON, ICON_SMALL, (LPARAM) hIcon );  // Set small icon

    g_pMusicManager = new CMusicManager();

    if( FAILED( hr = g_pMusicManager->Initialize( hDlg ) ) )
        return DXTRACE_ERR( TEXT("Initialize"), hr );

	// Create a 3D Audiopath. This creates a synth port that feeds a 3d buffer.
	// We can then play all segments into this buffer and directly control its
	// 3D parameters.
	IDirectMusicPerformance8* pPerformance = g_pMusicManager->GetPerformance();
	if( FAILED( hr = pPerformance->CreateStandardAudioPath( DMUS_APATH_DYNAMIC_3D, 128, 
                                                            TRUE, &g_p3DAudiopath ) ) )
        return DXTRACE_ERR( TEXT("CreateStandardAudioPath"), hr );

    // Set the default media path (something like C:\MSSDK\SAMPLES\MULTIMEDIA\MEDIA)
    // to be used as the search directory for finding DirectMusic content.
    if( FAILED( hr = g_pMusicManager->SetSearchDirectory( DXUtil_GetDXSDKMediaPath() ) ) )
        return DXTRACE_ERR( TEXT("SetSearchDirectory"), hr );

    TCHAR strFileNames[4][MAX_PATH] = { TEXT("Audiopath1.sgt"),	// Lullaby theme
		                                TEXT("Audiopath2.sgt"),	// Snoring
		                                TEXT("Audiopath3.wav"),	// Muttering in sleep
		                                TEXT("Audiopath4.sgt")  // Rude awakening
	                                  };

    // Create the segments from a file
	for (DWORD dwIndex = 0;dwIndex < 4; dwIndex++)
	{
        if( FAILED( hr = g_pMusicManager->CreateSegmentFromFile( &g_pMusicSegments[dwIndex], 
                                                                strFileNames[dwIndex] ) ) )
            return DXTRACE_ERR( TEXT("CreateSegmentFromFile"), hr );
    }


    // Get the listener from the in the Audiopath.
    IDirectSound3DListener* pDSListener = NULL;
    if( FAILED( hr = g_p3DAudiopath->GetObjectInPath( 0, DMUS_PATH_PRIMARY_BUFFER, 0,
                                                      GUID_NULL, 0, IID_IDirectSound3DListener, 
                                                      (LPVOID*) &pDSListener ) ) )
        return DXTRACE_ERR( TEXT("GetObjectInPath"), hr );

    // Set a new rolloff factor (1.0f is default)
    if( FAILED( hr = pDSListener->SetRolloffFactor( 0.25f, DS3D_IMMEDIATE ) ) )
        return DXTRACE_ERR( TEXT("SetRolloffFactor"), hr );       

    // Release the listener since we are done with it.
    SAFE_RELEASE( pDSListener );

    // Setup the sliders
    HWND hSlider;
    hSlider = GetDlgItem( hDlg, IDC_XPOS );
    SendMessage( hSlider, TBM_SETRANGEMAX, TRUE,   20L );
    SendMessage( hSlider, TBM_SETRANGEMIN, TRUE,  -20L );
    SendMessage( hSlider, TBM_SETPOS,      TRUE,    0L );

    hSlider = GetDlgItem( hDlg, IDC_YPOS );
    SendMessage( hSlider, TBM_SETRANGEMAX, TRUE,   20L );
    SendMessage( hSlider, TBM_SETRANGEMIN, TRUE,  -20L );
    SendMessage( hSlider, TBM_SETPOS,      TRUE,    0L );

    hSlider = GetDlgItem( hDlg, IDC_ZPOS );
    SendMessage( hSlider, TBM_SETRANGEMAX, TRUE,   20L );
    SendMessage( hSlider, TBM_SETRANGEMIN, TRUE,  -20L );
    SendMessage( hSlider, TBM_SETPOS,      TRUE,    0L );

	SetDlgItemInt( hDlg, IDC_XDISPLAY, 0, TRUE );
	SetDlgItemInt( hDlg, IDC_YDISPLAY, 0, TRUE );
	SetDlgItemInt( hDlg, IDC_ZDISPLAY, 0, TRUE );
	SetPosition( 0, 0, 0 );

    return S_OK;
}
Пример #4
0
CPushPinBitmapSet::CPushPinBitmapSet(HRESULT *phr, CSource *pFilter)
      : CSourceStream(NAME("Push Source BitmapSet"), phr, pFilter, L"Out"),
        m_FramesWritten(0),
        m_bZeroMemory(0),
        m_iFrameNumber(0),
        m_rtFrameLength(FPS_2), // Display 2 bitmap frames per second
        m_iCurrentBitmap(0),
        m_bFilesLoaded(FALSE)
{
    int nFilesLoaded=0;

    // Initialize member data arrays
    ZeroMemory(&m_cbBitmapInfo, NUM_FILES * sizeof(DWORD));
    ZeroMemory(&m_pBmi,   NUM_FILES * sizeof(BITMAPINFO *));
    ZeroMemory(&m_hFile,  NUM_FILES * sizeof(HANDLE));
    ZeroMemory(&m_pFile,  NUM_FILES * sizeof(BYTE *));
    ZeroMemory(&m_pImage, NUM_FILES * sizeof(BYTE *));

    // The main point of this sample is to demonstrate how to take a DIB
    // in host memory and insert it into a video stream. 
    // We read a set of bitmaps from files and copy one bitmap
    // into every frame that we send downstream.

    // In the filter graph, we connect this filter to the AVI Mux, which creates 
    // the AVI file with the video frames we pass to it. In this case, 
    // the end result is a rotating set of images rendered as a video stream.    

    // Read the current directory and SDK media directory into local strings
    TCHAR szCurrentDir[MAX_PATH], szMediaDir[MAX_PATH];
    GetCurrentDirectory(MAX_PATH-1, szCurrentDir);
    lstrcpyn(szMediaDir, DXUtil_GetDXSDKMediaPath(), MAX_PATH-1);

    for (int i=0; i < NUM_FILES; i++)
    {
        TCHAR szFileCurrent[MAX_PATH], szFileMedia[MAX_PATH];

        // Assume that the bitmap in the application's directory
        wsprintf(szFileCurrent, TEXT("%s\\BitmapSet%d.bmp\0"), szCurrentDir, i);

        m_hFile[i] = CreateFile(szFileCurrent, GENERIC_READ, 0, NULL, OPEN_EXISTING,
                                FILE_ATTRIBUTE_NORMAL, NULL);

        if (m_hFile[i] == INVALID_HANDLE_VALUE)
        {
            // File was not in the application's current directory,
            // so look in the DirectX SDK media path instead.  The path contained
            // in szMediaDir will already have a trailing backslash '\'.
            wsprintf(szFileMedia, TEXT("%sBitmapSet%d.bmp\0"), szMediaDir, i);

            m_hFile[i] = CreateFile(szFileMedia, GENERIC_READ, 0, NULL, OPEN_EXISTING, 
                                    FILE_ATTRIBUTE_NORMAL, NULL);

            if (m_hFile[i] == INVALID_HANDLE_VALUE)
            {
                TCHAR szMsg[2*MAX_PATH + 100];

                wsprintf(szMsg, TEXT("Could not open bitmap source file (#%d of %d) in the application directory:\r\n\r\n\t[%s]\n\n")
                         TEXT("or in the DirectX SDK Media folder:\r\n\r\n\t[%s]\n\n")
                         TEXT("Please copy this file either to the application's folder\r\n")
                         TEXT("or to the DirectX SDK Media folder, then recreate this filter.\r\n")
                         TEXT("Otherwise, you will not be able to render the output pin.\0"),
                         i+1, NUM_FILES, szFileCurrent, szFileMedia);

                OutputDebugString(szMsg);
                MessageBox(NULL, szMsg, TEXT("PushSource filter error"), MB_ICONERROR | MB_OK);
                *phr = HRESULT_FROM_WIN32(GetLastError());
                return;
            }
        }

        DWORD dwFileSize = GetFileSize(m_hFile[i], NULL);
        if (dwFileSize == INVALID_FILE_SIZE)
        {
            DbgLog((LOG_TRACE, 1, TEXT("Invalid file size")));
            *phr = HRESULT_FROM_WIN32(GetLastError());
            return;
        }

        m_pFile[i] = new BYTE[dwFileSize];
        if(!m_pFile[i])
        {
            OutputDebugString(TEXT("Could not allocate m_pImage\n"));
            *phr = E_OUTOFMEMORY;
            return;
        }

        DWORD nBytesRead = 0;
        if(!ReadFile(m_hFile[i], m_pFile[i], dwFileSize, &nBytesRead, NULL))
        {
            *phr = HRESULT_FROM_WIN32(GetLastError());
            OutputDebugString(TEXT("ReadFile failed\n"));
            return;
        }

        // WARNING - This code does not verify the file is a valid bitmap file.
        // In your own filter, you would check this or else generate the bitmaps 
        // yourself in memory.

        int cbFileHeader = sizeof(BITMAPFILEHEADER);

        // Store the size of the BITMAPINFO 
        BITMAPFILEHEADER *pBm = (BITMAPFILEHEADER*)m_pFile[i];
        m_cbBitmapInfo[i] = pBm->bfOffBits - cbFileHeader;

        // Store a pointer to the BITMAPINFO
        m_pBmi[i] = (BITMAPINFO*)(m_pFile[i] + cbFileHeader);

        // Store a pointer to the starting address of the pixel bits
        m_pImage[i] = m_pFile[i] + cbFileHeader + m_cbBitmapInfo[i];

        // Close and invalidate the file handle, since we have copied its bitmap data
        CloseHandle(m_hFile[i]);
        m_hFile[i] = INVALID_HANDLE_VALUE;

        // Count this is a successful file load.  If not all files load
        // properly, then the filter will not operate correctly.
        nFilesLoaded++;
    }

    // Make sure that ALL files were properly loaded
    if (nFilesLoaded != NUM_FILES)
        *phr = E_FAIL;
    else
        m_bFilesLoaded = TRUE;
}
Пример #5
0
VOID CAppForm::InitializeUIControls()
{
    
    // Get ptrs to the combo box controls for texture stage state UI
    m_pTex0ColorArg1 = (CComboBox*)GetDlgItem( IDC_TEX0_COLORARG1 );
    m_pTex0ColorOp   = (CComboBox*)GetDlgItem( IDC_TEX0_COLOROP );
    m_pTex0ColorArg2 = (CComboBox*)GetDlgItem( IDC_TEX0_COLORARG2 );
    m_pTex0AlphaArg1 = (CComboBox*)GetDlgItem( IDC_TEX0_ALPHAARG1 );
    m_pTex0AlphaOp   = (CComboBox*)GetDlgItem( IDC_TEX0_ALPHAOP );
    m_pTex0AlphaArg2 = (CComboBox*)GetDlgItem( IDC_TEX0_ALPHAARG2 );
    m_pTex1ColorArg1 = (CComboBox*)GetDlgItem( IDC_TEX1_COLORARG1 );
    m_pTex1ColorOp   = (CComboBox*)GetDlgItem( IDC_TEX1_COLOROP );
    m_pTex1ColorArg2 = (CComboBox*)GetDlgItem( IDC_TEX1_COLORARG2 );
    m_pTex1AlphaArg1 = (CComboBox*)GetDlgItem( IDC_TEX1_ALPHAARG1 );
    m_pTex1AlphaOp   = (CComboBox*)GetDlgItem( IDC_TEX1_ALPHAOP );
    m_pTex1AlphaArg2 = (CComboBox*)GetDlgItem( IDC_TEX1_ALPHAARG2 );
    m_pTex2ColorArg1 = (CComboBox*)GetDlgItem( IDC_TEX2_COLORARG1 );
    m_pTex2ColorOp   = (CComboBox*)GetDlgItem( IDC_TEX2_COLOROP );
    m_pTex2ColorArg2 = (CComboBox*)GetDlgItem( IDC_TEX2_COLORARG2 );
    m_pTex2AlphaArg1 = (CComboBox*)GetDlgItem( IDC_TEX2_ALPHAARG1 );
    m_pTex2AlphaOp   = (CComboBox*)GetDlgItem( IDC_TEX2_ALPHAOP );
    m_pTex2AlphaArg2 = (CComboBox*)GetDlgItem( IDC_TEX2_ALPHAARG2 );

    GetDlgItem( IDC_TEX0_NAME )->SetWindowText( _T("env2.bmp") );
    GetDlgItem( IDC_TEX1_NAME )->SetWindowText( _T("spotlite.bmp") );
    GetDlgItem( IDC_TEX2_NAME )->SetWindowText( _T("env3.bmp") );
    OnChangeTex();

    GetDlgItem( IDC_BLEND_FACTOR )->SetWindowText( _T("80808080") );
    OnChangeBlendFactor();

    GetDlgItem( IDC_DIFFUSE_COLOR )->SetWindowText( _T("ff0000ff") );
    OnChangeDiffuseColor();

    for( TCHAR** pstrTexOps = g_astrTextureOps; *pstrTexOps; pstrTexOps++ )
    {
        m_pTex0ColorOp->AddString( *pstrTexOps );
        m_pTex0AlphaOp->AddString( *pstrTexOps );
        m_pTex1ColorOp->AddString( *pstrTexOps );
        m_pTex1AlphaOp->AddString( *pstrTexOps );
        m_pTex2ColorOp->AddString( *pstrTexOps );
        m_pTex2AlphaOp->AddString( *pstrTexOps );
    }

    for( TCHAR** pstrArgs1 = g_astrTextureArgs1; *pstrArgs1; pstrArgs1++ )
    {
        m_pTex0ColorArg1->AddString( *pstrArgs1 );
        m_pTex0AlphaArg1->AddString( *pstrArgs1 );
        m_pTex1ColorArg1->AddString( *pstrArgs1 );
        m_pTex1AlphaArg1->AddString( *pstrArgs1 );
        m_pTex2ColorArg1->AddString( *pstrArgs1 );
        m_pTex2AlphaArg1->AddString( *pstrArgs1 );
    }

    for( TCHAR** pstrArgs2 = g_astrTextureArgs2; *pstrArgs2; pstrArgs2++ )
    {
        m_pTex0ColorArg2->AddString( *pstrArgs2 );
        m_pTex0AlphaArg2->AddString( *pstrArgs2 );
        m_pTex1ColorArg2->AddString( *pstrArgs2 );
        m_pTex1AlphaArg2->AddString( *pstrArgs2 );
        m_pTex2ColorArg2->AddString( *pstrArgs2 );
        m_pTex2AlphaArg2->AddString( *pstrArgs2 );
    }

    for( TCHAR** pstrPresets = g_astrPresetEffects; *pstrPresets; pstrPresets++ )
    {
        ((CComboBox*)GetDlgItem( IDC_PRESET_EFFECTS ))->AddString( *pstrPresets );
    }
    OnChangePresetEffects();

    // Store the initial media directory (for loading textures)
    strcpy( m_strInitialDir, DXUtil_GetDXSDKMediaPath() );
}