Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/140.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ DirectX 9引擎Z缓冲区不适用于D3DImage_C++_Wpf_Directx_Depth Buffer_D3dimage - Fatal编程技术网

C++ DirectX 9引擎Z缓冲区不适用于D3DImage

C++ DirectX 9引擎Z缓冲区不适用于D3DImage,c++,wpf,directx,depth-buffer,d3dimage,C++,Wpf,Directx,Depth Buffer,D3dimage,我正试图通过D3DImage将我的Direct9引擎集成到我的新WPF应用程序中。除了Z缓冲区外,其他一切都正常工作。如果AutoDepthStencil为FALSE,我可以渲染网格,但深度不起作用。激活AutoDepthStencil时,不会绘制任何内容。我到处找了好几天,没有找到任何可以帮助我的东西 这是演示参数 ZeroMemory( m_pp, sizeof(m_pp) ); m_pp->AutoDepthStencilFormat = D3DFMT_D16; m_pp->

我正试图通过D3DImage将我的Direct9引擎集成到我的新WPF应用程序中。除了Z缓冲区外,其他一切都正常工作。如果AutoDepthStencil为FALSE,我可以渲染网格,但深度不起作用。激活AutoDepthStencil时,不会绘制任何内容。我到处找了好几天,没有找到任何可以帮助我的东西

这是演示参数

ZeroMemory( m_pp, sizeof(m_pp) );

m_pp->AutoDepthStencilFormat = D3DFMT_D16;
m_pp->BackBufferCount            = 1;
m_pp->MultiSampleQuality         = 0;
m_pp->Windowed                   = Windowed;
m_pp->MultiSampleType            = D3DMULTISAMPLE_8_SAMPLES;
m_pp->EnableAutoDepthStencil     = FALSE;
m_pp->PresentationInterval       = D3DPRESENT_INTERVAL_ONE;
m_pp->Windowed                   = TRUE;
m_pp->BackBufferHeight           = 1;
m_pp->BackBufferWidth            = 1;
m_pp->SwapEffect                 = D3DSWAPEFFECT_DISCARD;
m_pp->BackBufferFormat           = D3DFMT_A8R8G8B8;
渲染器声明:

m_graphics->GetDeviceD3D()->SetRenderState(D3DRS_LIGHTING, TRUE);    // turn off the 3D lighting
m_graphics->GetDeviceD3D()->SetRenderState(D3DRS_AMBIENT, D3DCOLOR_XRGB(50,50,50));
m_graphics->GetDeviceD3D()->SetRenderState(D3DRS_SHADEMODE, D3DSHADE_GOURAUD); 
m_graphics->GetDeviceD3D()->SetRenderState(D3DRS_DIFFUSEMATERIALSOURCE, D3DMCS_MATERIAL);
m_graphics->GetDeviceD3D()->SetRenderState(D3DRS_SPECULARMATERIALSOURCE, D3DMCS_MATERIAL);
m_graphics->GetDeviceD3D()->SetRenderState(D3DRS_SPECULARENABLE, TRUE );
m_graphics->GetDeviceD3D()->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW);    // both sides of the triangles
m_graphics->GetDeviceD3D()->SetRenderState(D3DRS_ZENABLE, TRUE);    // turn on the z-buffer
m_graphics->GetDeviceD3D()->SetRenderState(D3DRS_NORMALIZENORMALS, TRUE);
m_graphics->GetDeviceD3D()->SetRenderState(D3DRS_ZFUNC, D3DCMP_LESS);
m_graphics->GetDeviceD3D()->SetRenderState(D3DRS_ZWRITEENABLE, TRUE);
m_graphics->GetDeviceD3D()->LightEnable( 0, TRUE );
重置:

m_graphics->GetDeviceD3D()->Clear(0, NULL, D3DCLEAR_TARGET , D3DCOLOR_ARGB(0, 0, 0, 0), 1.0f, 0);
m_graphics->GetDeviceD3D()->Clear(0, NULL, D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);
曲面和设备创建:

if (FAILED(m_pD3D9->CreateDeviceEx(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, m_hWnd,
    dwVertexProcessing,
    m_pp, NULL, GetDevicePtr())))
{
    return NULL;
}

// obtain the standard D3D device interface
if (FAILED(GetDeviceD3D()->QueryInterface(__uuidof(IDirect3DDevice9), reinterpret_cast<void **>(GetDevicePtr()))))
{
    return NULL;
}

// create and set the render target surface
// it should be lockable on XP and nonlockable on Vista

if (FAILED(GetDeviceD3D()->CreateRenderTarget(Width, Height, 
    D3DFMT_A8R8G8B8, D3DMULTISAMPLE_8_SAMPLES, 0, 
    false, // lockable
    GetSurfacePtr(), NULL)))
{
    return NULL;
}
GetDeviceD3D()->SetRenderTarget(0, m_surface);

将EnableAutoDepthStencil设置为TRUE时,确保CreateRenderTarget使用与演示参数中设置的宽度和高度相同的宽度和高度,以便更好地提供图片。遗憾的是,我需要10次重复才能完成此操作。你可以在gamedev网站上查看我的x-post:你有使用z缓冲区的所有步骤,我唯一能猜到的是单词/视图矩阵不正确。我添加了矩阵。我还尝试了D3DXMatrixPerspectiveFovRH和D3DXMatrixLookAtRH。我还尝试了msdn中D3DImage的一个新教程,您只需复制粘贴文件并继续执行步骤。本教程效果良好。但只要添加m_pp->EnableAutoDepthStencil=TRUE;m_pp->AutoDepthStencilFormat=D3DFMT_D16;m_graphics->GetDevice3D()->SetRenderState(D3DRS_ZENABLE,TRUE);没有呈现任何内容。。。非常感谢你的帮助!您是否收到任何错误消息?您尝试过不同的深度缓冲格式吗?非常感谢您的帮助!我更改了表示参数“宽度/高度”,并使用D3DFMT_D24S8作为模具格式,它成功了!
ZeroMemory( m_pp, sizeof(m_pp) );

m_pp->AutoDepthStencilFormat = D3DFMT_D16;
m_pp->BackBufferCount            = 1;
m_pp->MultiSampleQuality         = 0;
m_pp->Windowed                   = Windowed;
m_pp->MultiSampleType            = D3DMULTISAMPLE_8_SAMPLES;
m_pp->EnableAutoDepthStencil     = FALSE;
m_pp->PresentationInterval       = D3DPRESENT_INTERVAL_ONE;
m_pp->Windowed                   = TRUE;
m_pp->BackBufferHeight           = 1;
m_pp->BackBufferWidth            = 1;
m_pp->SwapEffect                 = D3DSWAPEFFECT_DISCARD;
m_pp->BackBufferFormat           = D3DFMT_A8R8G8B8;