Jump to content
  • Advertisement
Sign in to follow this  
akira32

How to save out a rendered scene to a texture

This topic is 4080 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
1) You create a texture
2) Get the surface of that texture
3) Set the Render target of the device to that texture
4) Render your scene

That's about it.
Here is some simple C# code from a Blur sample I wrote for mdxinfo
[source lang=cpp]
using (Surface originalSurface = device.GetRenderTarget(0))
using (Surface sceneSurface = sceneTexture.GetSurfaceLevel(0))
{
device.SetRenderTarget(0, sceneSurface);
device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, 0x002D32AA, 1.0f, 0);
try
{
//Just rendering the cube normally
RenderCube(camera);
}
finally
{
//Set the original render target
device.SetRenderTarget(0, originalSurface);
}
}



I hope this helps.

Share this post


Link to post
Share on other sites
this is what I have in C++.


CComPtr<ID3DXRenderToSurface> m_rtsHelper;
CComPtr<IDirect3DTexture9> m_renderTexture;
CComPtr<IDirect3DSurface9> m_renderSurface;
CComPtr<ID3DXSprite> m_d3dSpr;
int m_renderSize;




if(FAILED(D3DXCreateRenderToSurface(d3ddev, m_renderSize, m_renderSize, D3DFMT_X8R8G8B8, true, D3DFMT_D24X8, &m_rtsHelper)))
{
#ifdef _DEBUG
SHOWERROR(TEXT("Failed to create render surface."), __FILE__, __LINE__);
#endif
return;
}
if(FAILED(D3DXCreateTexture(d3ddev, m_renderSize, m_renderSize, 1, D3DUSAGE_RENDERTARGET, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &m_renderTexture)))
{
#ifdef _DEBUG
SHOWERROR(TEXT("Failed to create render texture."), __FILE__, __LINE__);
#endif
return;
}

if(FAILED(m_renderTexture->GetSurfaceLevel(0, &m_renderSurface)))
{
#ifdef _DEBUG
SHOWERROR(TEXT("Failed to get render surface level."), __FILE__, __LINE__);
#endif
return;
}
D3DXCreateSprite(d3ddev, &m_d3dSpr);




m_rtsHelper->BeginScene(m_renderSurface, NULL);
d3ddev->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);
......................
......................
......................
m_rtsHelper->EndScene(0);

m_d3dSpr->Begin(D3DXSPRITE_DONOTSAVESTATE);
m_d3dSpr->GetTransform(&sprScal);
m_d3dSpr->Draw(m_renderTexture, &rect, &sprCenter, &sprPosition, D3DCOLOR_XRGB(255, 255, 255));
m_d3dSpr->End();

Share this post


Link to post
Share on other sites
Yea just use D3DXSaveTextureToFile() goto:

http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/directx9_c_Dec_2005/D3DXSaveTextureToFile.asp

that will have all the info u need.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!