RenderTexture?

I would like to be able to render into a texture under DirectX9 i made a simple RenderTexture class however I am not sure on how to tackle rendering to a 2D texture under DirectX10.

My first puny attempt seems to fail when I create the render target view using CreateRenderTarget in OnCreateDevice10, the methods BeginCapture are used to start rendering to a texture a to restore render target, respectively.

Any help is much appreciated,

/// class member data
ID3D10Texture2D* md_pMap;
ID3D10RenderTargetView* md_pRTV;
/// render target view
ID3D10RenderTargetView* apOldRTVs[1];
ID3D10DepthStencilView* pOldDS;
D3D10_VIEWPORT OldVP;

HRESULT CRenderTexture::OnCreateDevice10()
{
HRESULT hr;
D3D10_TEXTURE2D_DESC dt;
dt.Width = 256;
dt.Height = 256;
dt.Format = DXGI_FORMAT_R16G16B16A16_FLOAT;
dt.BindFlags = D3D10_BIND_RENDER_TARGET;
hr = DXUTGetD3D10Device()->CreateTexture2D(&dt, NULL, &md_pMap);
D3D10_RENDER_TARGET_VIEW_DESC dv;
dv.Format = dt.Format;
dv.ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2D;
DXUTGetD3D10Device()->CreateRenderTargetView(md_pMap, &dv, &md_pRTV);
return hr;
}

void CRenderTexture::BeginCapture()
{
DXUTGetD3D10Device()->OMGetRenderTargets( 1, apOldRTVs, &pOldDS );
DXUTGetD3D10Device()->RSGetViewports( &cRT, &OldVP );
float ClearColor[4] = { 0.0f, 0.0f, 1.0f, 0.0f };
DXUTGetD3D10Device()->ClearRenderTargetView( md_pRTV, ClearColor);
DXUTGetD3D10Device()->OMSetRenderTargets(1, &md_pRTV, NULL);
}

void CRenderTexture::EndCapture()
{
DXUTGetD3D10Device()->RSSetViewports( 1, &OldVP );
DXUTGetD3D10Device()->OMSetRenderTargets( 1, apOldRTVs, pOldDS );
SAFE_RELEASE( apOldRTVs[0] );
SAFE_RELEASE( pOldDS );
}

I am using Visual Studio 2005 Professional and Vista RC1 with DirectX August 2006 SDK release on a NV40 GPU.

[2505 byte] By [shade] at [2008-2-7]
# 1

You should initialize all elements of the D3D10_TEXTURE2D_DESC and D3D10_RENDER_TARGET_VIEW_DESC. Direct3D 10 uses structure and not classes there. Therefore there are no default values.

For D3D10_TEXTURE2D_DESC you can use CD3D10_TEXTURE2D_DESC instead which is a class and have default values.

There is no class for D3D10_RENDER_TARGET_VIEW_DESC but you can pass a NULL pointer to CreateRenderTargetView. This will create a view with the default attributes based on the resource you provide.

RalfKornmann at 2007-8-31 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,Direct3D 10...