   Render Scene to a Texture
  Hi guys.  I am trying to render my scene to a texture and then save that texture as a bmp on my hard drive.  I have tried to use a very conventional method to do this.The following is my basic initialization processdev->GetBackBuffer(0,0,D3DBACKBUFFER_TYPE_MONO,&surfBackBuffer);dev->GetRenderTarget(0,&surfBackBuffer);D3DSURFACE_DESC desc;surfBackBuffer->GetDesc(&desc);dev->GetRenderTarget(0,&surfBackBuffer);D3DXCreateTexture(dev,731,595,D3DX_DEFAULT,D3DUSAGE_RENDERTARGET, desc.Format,D3DPOOL_DEFAULT,&txtRenderTarget);txtRenderTarget->GetSurfaceLevel(0,&srfRenderTarget);This is my render loopdev->GetRenderTarget(0,&surfBackBuffer);dev->SetRenderTarget(0,srfRenderTarget);dev->Clear(0,NULL,D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_COLORVALUE(0,0,0,0),1.0f,0);dev->BeginScene();...dev->EndScene();dev->SetRenderTarget(0,surfBackBuffer);dev->Present(NULL,NULL,NULL,NULL);D3DXSaveTextureToFileA("c:\\test.bmp",D3DXIFF_BMP,txtRenderTarget,NULL)What I get is a empty black 731x595 rectangle... any ideas what I am doing wrong?  Thanks!   
  Can your machine create textures that are non-powers-of-2 in size?If not, you're likely getting a 1024x1024 texture which is likely not your backbuffer size.Note: you don't check return values for errors.;  This code will not work because in order to save a surface to file, surface must have been created with CreateOffscreenPlainSurface, and you are using CreateTexture. In addition, offscreen plain surface cannot be used as a render target so you can't render to a texture and then proceed to save it to a file.What I do to take a screenshot is create an offscreen plain surface, then call GetFrontBufferData to copy current screen image into the surface, then lock it and set alpha channel to 1.0 (because it will be 0 by default), and then crop if necessary by creating yet another offscreen plain surface and using UpdateSurface to copy rectangles without stretching.If you don't want to display anything on the screen, I guess you would have to first render to a dynamic render target (texture created with both dynamic and rendertarget usage flags, and make sure it's conservatively pow2 sized), then create an offscreen plain surface of whatever size you need (they are not restricted to pow2), and use StretchRect or UpdateTexture or UpdateSurface or Lock/Copy/Unlock methods (all 3 may not work so you will have to figure out which one does) to transfer data from your render target into the offscreen plain surface. Then you can save the offscreen surface to file.   ;Quote:Original post by ValManThis code will not work because in order to save a surface to file, surface must have been created with CreateOffscreenPlainSurface, and you are using CreateTexture.This isn't correct.  D3DX will create an intermediate surface if necessary in order to copy your device memory surface to it in order for D3DX to save it out.  But you might as well make your surface more friendly to D3DX for saving anyway.Also, you don't need to use a texture if all you want to do is render to a surface before saving it out.  You only need to render to a texture if you intend on using the rendering with texturing.  A plain render target (such as the back buffer) is sufficient.  You can use D3DX to save the back buffer directly, just make sure you do it before you call Present so that you still have access to the back buffer.I think the real problem with this code is what was already identified: there's no error checking.  Run your application with the debug runtime selected and look in the debug output window for messages alerting you to failures you didn't check.   ;  Actually,  my goal is to render my scene to a texture do do some post processing effects however as a test to ensure that my texture was being saved correctly,  I wanted to visually see it.  I think the logic I right but obviously I am missing something as I see nothing but a black scene.   ;Quote:Original post by bfogertyActually,  my goal is to render my scene to a texture do do some post processing effects however as a test to ensure that my texture was being saved correctly,  I wanted to visually see it.  I think the logic I right but obviously I am missing something as I see nothing but a black scene.If you just want to visualize a texture, use PIX.  Start a new experiment, set it to capture a frame when F12 is pressed, and capture a frame.  Then find your render-target texture in the list of resources, and it will let you view it in the bottom right corner.  You can then debug the pixel shader for individual texels, if you'd like.