LPDIRECT3DTEXTURE9 pTexture = NULL; hr = pDevice->CreateTexture( 512, // texture width 512, // texture height 1, // number of mip levels D3DUSAGE_RENDERTARGET, // usage flags D3DFMT_D24S8, // texture format D3DPOOL_DEFAULT, // memory pool &pTexture, // texture pointer NULL); // reserved parameter LPDIRECT3DSURFACE9 pSurface = NULL; hr = pTexture->GetSurfaceLevel(0, &pSurface); hr = pDevice->SetRenderTarget(0, pSurface); hr = pDevice->SetDepthStencilSurface(pSurface);
LPDIRECT3DSURFACE9 pBackBuffer = NULL; hr = pDevice->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &pBackBuffer); hr = pDevice->SetRenderTarget(0, pBackBuffer); hr = pDevice->SetDepthStencilSurface(pBackBuffer);In this example, we obtain the back buffer surface via the GetBackBuffer method and set it as both the render target and depth-stencil surface. This can be useful when rendering to the screen or window directly. The SetDepthStencilSurface method is part of the DirectX graphics library, which is included in the DirectX SDK package for C++.