对于上篇的Direct3D的初始化,还有一些细节要记录一下,不然过几天又忘记了,健忘~~~~~
1. 在CreateDevice函数中要使用一个 D3DPRESENT_PARAMETERS结构,结构的字段含义如下(来自SDK)
typedef struct D3DPRESENT_PARAMETERS {
//后台缓冲区的大小,当全屏时大小要根据IDirect3D9::EnumAdapterModes,即等于你显卡支持的模式大小,
//非全屏时大小为CreateWindowEX中设置的程序窗口大小(故Windowed==true时,可以不用设置这两个值)
UINT BackBufferWidth, BackBufferHeight;
//The back buffer format,在窗口模式下一般设置D3DFMT_UNKNOW
D3DFORMAT BackBufferFormat;
//0 ~ D3DPRESENT_BACK_BUFFERS_MAX
UINT BackBufferCount;
//D3DMULTISAMPLE_TYPE结构,只有当SwapEffect == D3DSWAPEFFECT_DISCARD,多重采样才会有效
//当SwapEffect !=D3DSWAPEFFECT_DISCARD, MultiSampleType必须为D3DMULTISAMPLE_NONE
D3DMULTISAMPLE_TYPE MultiSampleType;
//Quality level,值为 0 ~ IDirect3D9::CheckDeviceMultiSampleType的返回值
DWORD MultiSampleQuality;
//if Windowed is TRUE and SwapEffect is set to D3DSWAPEFFECT_FLIP, the runtime will create
//one extra back buffer and copy whichever becomes the front buffer at presentation time.
//D3DSWAPEFFECT_COPY requires that BackBufferCount be set to 1.
//D3DSWAPEFFECT_DISCARD will be enforced in the debug runtime by filling any buffer with noise after it is presented.
D3DSWAPEFFECT SwapEffect;
//The device window determines the location and size of the back buffer on screen
HWND hDeviceWindow;
BOOL Windowed;
//If this value is TRUE, Direct3D 支持depth-stencil buffer
//当这个值为true时 AutoDepthStencilFormat必须为有效的depth-stencil format
BOOL EnableAutoDepthStencil;
//只有当EnableAutoDepthStencil时 才有效; 比如EnableAuto... = true, AutoDept...Format = D3DFMT_D24S8
D3DFORMAT AutoDepthStencilFormat;
//D3DPRESENTFLAG结构
DWORD Flags;
//窗口模式下这个必须为0.全屏模式下这个为IDirect3D9::EnumAdapterModes.的返回值
UINT FullScreen_RefreshRateInHz;
UINT PresentationInterval;
} D3DPRESENT_PARAMETERS, *LPD3DPRESENT_PARAMETERS;
备注:
1. 对于创建一般的窗口模式的D3D程序,只需要设置 D3DPRESENT_PARAMETERS的
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory( &d3dpp, sizeof( d3dpp ) );
d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = D3DFMT_UNKNOW; //窗口模式可以为unknown
2. 创建全屏模式的D3D程序,需要
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory( &d3dpp, sizeof( d3dpp ) );
d3dpp.Windowed = FALSE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8; //以下三项全屏模式必须要设置
d3dpp.BackBufferWidth = 1280; //若设置1279 * 1023将会CreateDevice失败
d3dpp.BackBufferHeight = 1024; //要根据显卡的模式大小设置
3. 如果想在运行中切换全屏和窗口模式,可以
OnLostDevice();
pDevice9->Reset(&d3dpp);
OnResetDevice();