Sign in to follow this  
CastorX

Render2TextureXNA

Recommended Posts

CastorX    132
Hy! I want to do some image processing with HLSL on a texture. Now I have my shader, input, output textures, the screen quad vb, and all the necessary vertex declarations. Now comes the render to texture part but I simply cannot understand how to do it. I've made it a few times in d3d9, but in XNA it seem to be more complicated with it's ResolveTexture2D and RenderTarget2D stuff. Can anyone post a few word for me or send links or code to make it clearer? THX!

Share this post


Link to post
Share on other sites
MJP    19786
You can just ignore ResolveTexture2D, it's only for resolving the backbuffer. All you need to do is:

-Create a RenderTarget2D during initialization
-When you want to render to it, set it onto the device with GraphicsDevice.SetRenderTarget()
-When you're done rendering to it, un-bind it from the GraphicsDevice by setting a different render target
-When you want to sample it as a texture, just call RenderTarget2D.GetTexture()

Share this post


Link to post
Share on other sites
CastorX    132
OK! Thank you!
There is one more thing:

I get the error message:
"The render target must not be set on the device when calling GetTexture."

When I try to:
sprites.Draw(tTargetTexture0.GetTexture(), new Rectangle(0, 128, tTargetTexture0.GetTexture().Width, tTargetTexture0.GetTexture().Height), Color.White);

I do not really understand this error message. I did not set tTargetTexture0 as the render target... however I tried that too: it throws the same error.

Share this post


Link to post
Share on other sites
phil_t    8084
I think you'll also get this error (confusingly) if you've never rendered to tTargetTexture0 before. So you have to at least have set it as the render target once (and then reset the render target to null before using tTargetTexture0's texture).

Share this post


Link to post
Share on other sites

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