窗口化與全屏設定的區別

    經過我的實驗,以及閱讀DX的SDK,我得出了以下的結論:

 

    D3DPRESENT_PARAMETERS d3dpp; 
    ZeroMemory( 
&d3dpp, sizeof(d3dpp) );
    d3dpp.Windowed 
= FALSE;

 

    光這樣,創建出來的不是全屏的,根據SDK裏面的說法,

D3DPRESENT_PARAMETERS::BackBufferWidth, D3DPRESENT_PARAMETERS::BackBufferHeight
    Width and height of the new swap chain's back buffers, in pixels. If Windowed is FALSE (the presentation is full-screen), these values must equal the width and height of one of the enumerated display modes found through IDirect3D9::EnumAdapterModes. If Windowed is TRUE and either of these values is zero, the corresponding dimension of the client area of the hDeviceWindow (or the focus window, if hDeviceWindow is NULL) is taken.D3DPRESENT_PARAMETERS::BackBufferFormat
    The back buffer format. For more information about formats, see D3DFORMAT. This value must be one of the render-target formats as validated by IDirect3D9::CheckDeviceType. You can use IDirect3DDevice9::GetDisplayMode to obtain the current format.     In fact, D3DFMT_UNKNOWN can be specified for the BackBufferFormat while in windowed mode. This tells the runtime to use the current display-mode format and eliminates the need to call IDirect3DDevice9::GetDisplayMode.    For windowed applications, the back buffer format no longer needs to match the display-mode format because color conversion can now be done by the hardware (if the hardware supports color conversion). The set of possible back buffer formats is constrained, but the runtime will allow any valid back buffer format to be presented to any desktop format. (There is the additional requirement that the device be operable in the desktop mode; devices typically do not operate in 8 bits per pixel modes.)    Full-screen applications cannot do color conversion.

    這三個參數在Windowed 爲FALSE的時候必須爲顯示器正確的值.不能使用默認值,這樣才能正確的全屏成功,否則在CreateDevice的時候就會失敗.

    代碼應該這麼寫:

 

    D3DDISPLAYMODE d3ddm;
    
//D3DADAPTER_DEFAULT表示默認顯卡
     g_pD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT,&d3ddm);

    D3DPRESENT_PARAMETERS d3dpp; 
    ZeroMemory( 
&d3dpp, sizeof(d3dpp) );
    d3dpp.Windowed 
= FALSE;
    d3dpp.SwapEffect 
= D3DSWAPEFFECT_DISCARD;
     d3dpp.BackBufferFormat 
= d3ddm.Format;
    d3dpp.BackBufferWidth 
= d3ddm.Width;
    d3dpp.BackBufferHeight 
= d3ddm.Height;

 

    最有意思的是D3DPRESENT_PARAMETERS::BackBufferWidth以及D3DPRESENT_PARAMETERS::BackBufferHeight,這兩個參數必須和顯示器一致,那麼如果當前顯示效果是1024*768,而你想遊戲是800*600,那麼你必須先設置一下當前的分辨率(目前我是這麼理解的).

    順便說一下D3DPRESENT_PARAMETERS::SwapEffect這個參數,這個決定了swap chain在Present發生的時候的行爲,是拷貝還是丟棄,一般使用D3DSWAPEFFECT_DISCARD,這樣Present發生的時候,顯示卡可以按照最優化的方式來處理front buffer,因爲程序明確表示front buffer裏面的數值甚至可以被丟棄,在Present之後不會有代碼使用它.這樣可以儘量加快處理速度.

    再說一下,上面是基於當前的理解,有不妥之處,往指正.

 

 


 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章