Question

I'm new to XNA and am wondering if there is some builtin workflow for restoring the graphics stack to a given state. For example, I noticed after a sprite render to my 3D scene, the 3D portion stopped working after calling SpriteBatch.begin() and had I had to fix it by

  GraphicsDevice.BlendState = BlendState.Opaque;
  GraphicsDevice.DepthStencilState = DepthStencilState.Default;
  GraphicsDevice.SamplerStates[0] = SamplerState.LinearWrap;

Is there something like a glPushAttrib()/glPopAttrib() to wrap this instead of just knowing what states the sprite engine changes?

My current issue is I'm playing with render targets and after creating one, I find my 3D portion seems messed up after calling SetRenderTarget().

For example, if I were to call the following two functions, from what I understand of the documentation, setting the graphics device to null should reset everything.

  GraphicsDevice.SetRenderTarget(target);
  GraphicsDevice.SetRenderTarget(null);

Commenting out the first line above keeps the 3D render correct, so I'm assuming some state much change on that call. Are these state changes documented somewhere by call or is there a way to save the state explicitly and restore it when finished doing some operation?

Was it helpful?

Solution

There is some documentation on render targets,

http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.graphics.rendertarget%28v=xnagamestudio.20%29.aspx

To reset the Render Target back to the backbuffer, use

GraphicsDevice.SetRenderTarget(0, null);

Also (My random idea I had, not sure about it)

You could (maybe) add this to spritebatch,

SpriteBatch.Begin(SpriteSortMode.FrontToBack, BlendState.Opaque, SamplerState.LinearWrap, DepthStencilState.Default, null);

Havent done much with render targets, but I belive that does the same thing. And then next time to reset, just call spriteBatch with no arguments (or whatever you want for that spritebatch)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top