Sign in to follow this  

How to save out a rendered scene to a texture

This topic is 3832 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

How to save out a rendered scene to a texture? Could someone put the code?

Share this post


Link to post
Share on other sites
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

This topic is 3832 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this