Jump to content
  • Advertisement
Sign in to follow this  
ChristOwnsMe

RenderTarget2D not saving

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

Hello. I am rendering a scene to a render target and trying to save it to a file, but the picture that is created is always blank(as in it is 0k, not even black pixels are created), I don't know what else to do. The rendering works perfectly so I know things are actually getting rendered, it is just not saving to an image. Here is my code.



RenderTarget2D RenderTarget = new RenderTarget2D(CRenderManager.Singleton.GetGD(), 128, 128, false, SurfaceFormat.Color, DepthFormat.Depth24, 0, RenderTargetUsage.PreserveContents);
CRenderManager.Singleton.GetGD().SetRenderTarget(RenderTarget);

CRenderManager.Singleton.GetEffect().World = Matrix.CreateTranslation(-pos.getVector3df()) ;
CRenderManager.Singleton.GetEffect().VertexColorEnabled = false;
foreach (EffectPass pass in CRenderManager.Singleton.GetEffect().CurrentTechnique.Passes)
{
pass.Apply();
CRenderManager.Singleton.GetGD().Indices = patch.GetIB();
CRenderManager.Singleton.GetGD().SetVertexBuffer(patch.GetVB());
CRenderManager.Singleton.GetGD().DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, patch.GetVB().VertexCount, 0, patch.GetIB().IndexCount);
}
CRenderManager.Singleton.GetGD().SetRenderTarget(null);
RenderTarget.SaveAsPng(File.OpenWrite("RENDER.png"), RenderTarget.Width, RenderTarget.Height);


Any ideas? Edited by ShadowMan777

Share this post


Link to post
Share on other sites
Advertisement
That was it. Thank you so much. I didn't even think about it because I wasn't creating a stream object so I didn't think about closing it.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!