|
使用DX9自带的例子02 "Vertices" 显示顶点并渲染的那一个
修改了InitD3D( HWND hWnd ) 使其支持全屏
D3DPRESENT_PARAMETERS d3dpp;
HRESULT InitD3D( HWND hWnd )
{
// Create the D3D object.
if( NULL == ( g_pD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) )
return E_FAIL;
// Set up the structure used to create the D3DDevice
D3DDISPLAYMODE d3ddm; //D3D显示模式
if(FAILED(g_pD3D -> GetAdapterDisplayMode(D3DADAPTER_DEFAULT,&d3ddm)))
return -1;
ZeroMemory( &d3dpp, sizeof(d3dpp) );
d3dpp.Windowed=FALSE;
d3dpp.hDeviceWindow=hWnd; //窗口句柄
d3dpp.SwapEffect=D3DSWAPEFFECT_FLIP; //设定换页效果为翻页
d3dpp.BackBufferCount=2; //有2个后台缓存
d3dpp.BackBufferWidth=800; //屏幕宽为800像素
d3dpp.BackBufferHeight=600; //屏幕长为600像素
//使用当前设定的此显示模式下的刷新率
d3dpp.FullScreen_RefreshRateInHz=D3DPRESENT_RATE_DEFAULT; //立即显示刷新后的图像
d3dpp.BackBufferFormat=d3ddm.Format; //色彩深度为桌面的色彩深度
//开启自动深度缓存,即自动按正确的遮盖关系显示图像
d3dpp.EnableAutoDepthStencil=TRUE;
d3dpp.AutoDepthStencilFormat=D3DFMT_D16; //16位自动深度缓存
// Create the D3DDevice
if( FAILED( g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp, &g_pd3dDevice ) ) )
{
return E_FAIL;
}
// Device state would normally be set here
return S_OK;
}
修改了Render() 使其能恢复表面
VOID Render()
{
g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,255), 1.0f, 0 );
if( SUCCEEDED( g_pd3dDevice->BeginScene() ) )
{
g_pd3dDevice->SetStreamSource( 0, g_pVB, 0, sizeof(CUSTOMVERTEX) );
g_pd3dDevice->SetFVF( D3DFVF_CUSTOMVERTEX );
g_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLELIST, 0, 1 );
g_pd3dDevice->EndScene();
}
// Present the backbuffer contents to the display
// g_pd3dDevice-> resent( NULL, NULL, NULL, NULL ); // 原来的翻转
if (g_pd3dDevice->Present(NULL,NULL,NULL,NULL)==D3DERR_DEVICELOST)
{ //如果已经可以用Reset()恢复设备...
if (g_pd3dDevice->TestCooperativeLevel()==D3DERR_DEVICENOTRESET)
{
g_pd3dDevice->Reset(&d3dpp);
}
}
}
然后在这种情况下, 注释掉所有的InitVB()里面的代码则运行正常,可恢复表面,反之不能恢复表面,连全屏都无法切入..
这到底是什么原因呢~~
如果换用其他如读入纹理或加材质给模型,此方法都可以正常,但为什么一创建顶点缓冲就不行呢? [em4] [em4] [em4]
代码Tut02_Vertices在这里: |
|