   [D3D11] Creating depth-stencil view
  Hello I'm new to D3D11, I'm trying to create a render target view and a depth-stencil view. I've done some reading but there's not many examples on the net besides msdn and the sdk uses DXUT :( I decided not to use it since the rest of my app is object-oriented. This is what I've come up with so far, can someone steer me in the right direction if i'm doing something wrong? ThanksD3D_FEATURE_LEVEL recommendedFeatureLevel = D3D_FEATURE_LEVEL_10_0;ID3D11Texture2D* backBuffer = NULL;ID3D11Texture2D* depthStencil = NULL;D3D11_TEXTURE2D_DESC backBufferDesc;D3D11_TEXTURE2D_DESC depthStencilDesc;D3D11_DEPTH_STENCIL_VIEW_DESC depthStencilViewDesc;Zero_Memory(backBufferDesc);Zero_Memory(depthStencilDesc);Zero_Memory(depthStencilViewDesc);// Create swap chain descriptionp_SwapChainDesc.BufferCount = 1;p_SwapChainDesc.BufferDesc.Width = p_Window->GetClientWidth();p_SwapChainDesc.BufferDesc.Height = p_Window->GetClientHeight();p_SwapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;p_SwapChainDesc.BufferDesc.RefreshRate.Numerator = 60;p_SwapChainDesc.BufferDesc.RefreshRate.Denominator = 1;p_SwapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;p_SwapChainDesc.OutputWindow = p_Window->GetHandle();p_SwapChainDesc.SampleDesc.Count = 1;p_SwapChainDesc.SampleDesc.Quality = 0;p_SwapChainDesc.Windowed = TRUE;// Get recommended feature levelD3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION, NULL, &recommendedFeatureLevel, NULL);if (p_FeatureLevel < recommendedFeatureLevel) p_FeatureLevel = recommendedFeatureLevel;// Create deviceD3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, &p_FeatureLevel, 1, D3D11_SDK_VERSION, &p_SwapChainDesc, &p_SwapChain, &p_Device, NULL, &p_ImmediateContext);// Get back-bufferp_SwapChain->GetBuffer(0, __uuidof(*backBuffer), (LPVOID*)&backBuffer);// Get back-buffer surface descriptionbackBuffer->GetDesc(&backBufferDesc);// Create render target viewp_Device->CreateRenderTargetView(backBuffer, NULL, &p_RenderTargetView);// Create depth-stencil surface descriptiondepthStencilDesc.Width = backBufferDesc.Width;depthStencilDesc.Height = backBufferDesc.Height;depthStencilDesc.MipLevels = 1;depthStencilDesc.ArraySize = 1;depthStencilDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;depthStencilDesc.SampleDesc.Count = 1;depthStencilDesc.SampleDesc.Quality = 0;depthStencilDesc.Usage = D3D11_USAGE_DEFAULT;depthStencilDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL;depthStencilDesc.CPUAccessFlags = 0;depthStencilDesc.MiscFlags = 0;// Create depth-stencilp_Device->CreateTexture2D(&depthStencilDesc, NULL, &depthStencil);// TODO: Set depth-stencil?// Create depth-stencil view descriptiondepthStencilViewDesc.Format = depthStencilDesc.Format;if (depthStencilDesc.SampleDesc.Count > 1) depthStencilViewDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DMS;else depthStencilViewDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;depthStencilViewDesc.Texture2D.MipSlice = 0;// Create depth-stencil viewp_Device->CreateDepthStencilView(depthStencil, &depthStencilViewDesc, &p_DepthStencilView);// TODO: Set depth-stencil view state?// Set render target view and depth-stencil viewp_ImmediateContext->OMSetRenderTargets(1, &p_RenderTargetView, p_DepthStencilView);// Create viewportp_Viewport.Width = (FLOAT)p_Window->GetClientWidth();p_Viewport.Height = (FLOAT)p_Window->GetClientHeight();p_Viewport.MinDepth = 0.0f;p_Viewport.MaxDepth = 1.0f;p_Viewport.TopLeftX = 0;p_Viewport.TopLeftY = 0;// Set viewportp_ImmediateContext->RSSetViewports(1, &p_Viewport);// CleanupZero_Memory(depthStencilViewDesc);Zero_Memory(depthStencilDesc);Zero_Memory(backBufferDesc);Release_Object(depthStencil);Release_Object(backBuffer);[Edited by - majek on April 20, 2010 9:12:26 PM]
  bump, anyone? :)   ;  Just off the top of my head there's something wrong with the way you try to get the backbuffer buffer from the swapchain.// Get back-bufferp_SwapChain->GetBuffer(0, __uuidof(*backBuffer), (LPVOID*)&backBuffer);// Should bep_SwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&backBuffer);plus I don't normally supply the view creation with a depth/stencil desc.p_Device->CreateDepthStencilView(depthStencil, &depthStencilViewDesc /*<-- pass NULL instead*/, &p_DepthStencilView);   ;  What error do you get, and where?Check the HRESULT return code from all functions and tell us where it fails.Something like:#include <DXErr.h>// Link DXErr.lib...HRESULT hResult = pDevice->CreateTexture2D(...);if(FAILED(hResult)) {  MessageBox(NULL, DXGetErrorDescription(hResult), NULL, MB_OK);};  Thanks for the replies, I don't get any errors in the create code I just thought there was something missing. As for the render code I'm only using ClearRenderTargetView and ClearDepthStencilView to clear the screen, and they are voids so I can't check for errors. I guess I won't know until I actually use the depth-stencil view.   