Sign in to follow this  

Weird behaviour reading RenderTarget surface?

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

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