窗口化与全屏设定的区别

    经过我的实验,以及阅读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之后不会有代码使用它.这样可以尽量加快处理速度.

    再说一下,上面是基于当前的理解,有不妥之处,往指正.

 

 


 

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