Jump to content
  • Advertisement
Sign in to follow this  

Weird behaviour reading RenderTarget surface?

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

I am trying to read some data from a render target, but get very funky/incorrect results. This is what I do: Surface previousRenderTarget = device.GetRenderTarget(0); Format frmt = device.GetRenderTarget(0).Description.Format; Surface renderTargetSurface = device.CreateRenderTarget(w,h,frmt,MultiSampleType.None, 0, true); this.device.SetRenderTarget(0, renderTargetSurface); device.Clear(ClearFlags.Target, Color.Black, 1.0f, 0); Mesh box = Mesh.Box(device, 32,32,32); box.DrawSubset(0); device.SetRenderTarget(0,previousRenderTarget); int[] data = (int[])renderTargetSurface.LockRectangle(typeof(int),0,w*h); When I look at values in data they are not what I expect. But if I do SurfaceLoad.Save on the surface it seems to be alright. Same thing if I create a GDI bitmap, bitblit from the texture and read from that (horribly slow...). Is there any special trick that I should do to instead? What I want to accomplish is get an array corresponding to the rendered image. On a related topic, is there any trick to approximate the rendered depth values, with color for instance? I would really like to read depth values but cannot depend on HW supporting lockable depth formats. Maybe some trick where the output color fades with distance? Sort of like fog....

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!