   Render to texture Reply Quote Edit
  Hi guys,I'm new to DirectX, and now i have to render some scene to a texture, and then i will have to work with these texture.I have try to write a function to render a simple Box to a texture. Then i will use this texture to render the box again, using the texture above to this new BoxThis is my code<CODE>void RenderTheBlocker(IDirect3DDevice9* pd3dDevice,float fElapsedTime,ID3DXMesh* mBox) {HRESULT hr; hr = D3DXCreateTexture( pd3dDevice,RENDERTOSURFACE_WIDTH,RENDERTOSURFACE_HEIGHT,1,D3DUSAGE_RENDERTARGET,D3DFMT_A8R8G8B8,D3DPOOL_DEFAULT,&g_pDynamicBlockerTexture ); // //g_pDynamicTexture  D3DSURFACE_DESC desc;g_pDynamicBlockerTexture->GetSurfaceLevel( 0, &m_pTextureSurface );m_pTextureSurface->GetDesc( &desc ); hr = D3DXCreateRenderToSurface( pd3dDevice,   desc.Width,   desc.Height,   desc.Format,   TRUE,   D3DFMT_D16,   &m_pRenderToSurface );  m_pRenderToSurface->BeginScene( m_pTextureSurface, NULL );pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER,  D3DCOLOR_COLORVALUE(0.0f,1.0f,0.0f,1.0f), 1.0f, 0);pd3dDevice->SetTransform( D3DTS_PROJECTION, g_LCamera.GetProjMatrix()); //g_matProjection_offscreenSurfacepd3dDevice->SetTransform( D3DTS_WORLD, g_LCamera.GetWorldMatrix());    pd3dDevice->SetTransform(D3DTS_VIEW,g_LCamera.GetViewMatrix());mBox->DrawSubset(0);m_pRenderToSurface->EndScene( 0 );   //Testpd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_COLORVALUE(0.0f,0.0f,1.0f,1.0f), 1.0f, 0 ); pd3dDevice->BeginScene();   pd3dDevice->SetTransform( D3DTS_PROJECTION, g_LCamera.GetProjMatrix());    pd3dDevice->SetTransform( D3DTS_WORLD, g_LCamera.GetWorldMatrix() );    pd3dDevice->SetTransform( D3DTS_VIEW,g_LCamera.GetViewMatrix());    pd3dDevice->SetTexture( 0, g_pDynamicBlockerTexture);    mBox->DrawSubset(0);pd3dDevice->EndScene();pd3dDevice->Present( NULL, NULL, NULL, NULL ); } </CODE>When i run this, it only appear a blue scene. No box at allCan anyone help me with this?   
  1. If you render the box mesh to the screen, rather than to a texture, does it render correctly?2. Do you set the viewport somewhere other than the posted code?3. Do you create the normal render buffer using D3DFMT_A8R8G8B8 also?   ;  I figured out my mistake when i created D3DXCreateRenderToSurface inside this function. Thanks anyway :)   