Skip to main content
replaced http://gamedev.stackexchange.com/ with https://gamedev.stackexchange.com/
Source Link

My Problem is similar to XNA 4.0 - Why does using a RenderTarget2d cause transparency on models?XNA 4.0 - Why does using a RenderTarget2d cause transparency on models?.

I want to render my scene to a Texture2D and then draw the texture. If I set no RenderTarget at all (render directly to the back buffer), everything looks fine.

I draw my models/textures with:

graphics.GraphicsDevice.Clear(Color.Black);
spriteBatch.Begin(SpriteSortMode.FrontToBack, BlendState.Opaque, SamplerState.AnisotropicClamp, DepthStencilState.Default, RasterizerState.CullCounterClockwise);

[...Drawing methods for models etc. are called here...]

spriteBatch.End();

If I change that code to:

RenderTarget2D target = new RenderTarget2D(this.GraphicsDevice,this.GraphicsDevice.PresentationParameters.BackBufferWidth,this.GraphicsDevice.PresentationParameters.BackBufferHeight);
this.GraphicsDevice.SetRenderTarget(target);

graphics.GraphicsDevice.Clear(Color.Black);

spriteBatch.Begin(SpriteSortMode.FrontToBack, BlendState.Opaque, SamplerState.AnisotropicClamp, DepthStencilState.Default, RasterizerState.CullCounterClockwise);

[...Drawing methods for models etc. are called here...]

spriteBatch.End();
this.GraphicsDevice.SetRenderTarget(null);

And render the texture / save it as an image-file, some objects get transparent and the drawing order changes sort of randomly.

My Problem is similar to XNA 4.0 - Why does using a RenderTarget2d cause transparency on models?.

I want to render my scene to a Texture2D and then draw the texture. If I set no RenderTarget at all (render directly to the back buffer), everything looks fine.

I draw my models/textures with:

graphics.GraphicsDevice.Clear(Color.Black);
spriteBatch.Begin(SpriteSortMode.FrontToBack, BlendState.Opaque, SamplerState.AnisotropicClamp, DepthStencilState.Default, RasterizerState.CullCounterClockwise);

[...Drawing methods for models etc. are called here...]

spriteBatch.End();

If I change that code to:

RenderTarget2D target = new RenderTarget2D(this.GraphicsDevice,this.GraphicsDevice.PresentationParameters.BackBufferWidth,this.GraphicsDevice.PresentationParameters.BackBufferHeight);
this.GraphicsDevice.SetRenderTarget(target);

graphics.GraphicsDevice.Clear(Color.Black);

spriteBatch.Begin(SpriteSortMode.FrontToBack, BlendState.Opaque, SamplerState.AnisotropicClamp, DepthStencilState.Default, RasterizerState.CullCounterClockwise);

[...Drawing methods for models etc. are called here...]

spriteBatch.End();
this.GraphicsDevice.SetRenderTarget(null);

And render the texture / save it as an image-file, some objects get transparent and the drawing order changes sort of randomly.

My Problem is similar to XNA 4.0 - Why does using a RenderTarget2d cause transparency on models?.

I want to render my scene to a Texture2D and then draw the texture. If I set no RenderTarget at all (render directly to the back buffer), everything looks fine.

I draw my models/textures with:

graphics.GraphicsDevice.Clear(Color.Black);
spriteBatch.Begin(SpriteSortMode.FrontToBack, BlendState.Opaque, SamplerState.AnisotropicClamp, DepthStencilState.Default, RasterizerState.CullCounterClockwise);

[...Drawing methods for models etc. are called here...]

spriteBatch.End();

If I change that code to:

RenderTarget2D target = new RenderTarget2D(this.GraphicsDevice,this.GraphicsDevice.PresentationParameters.BackBufferWidth,this.GraphicsDevice.PresentationParameters.BackBufferHeight);
this.GraphicsDevice.SetRenderTarget(target);

graphics.GraphicsDevice.Clear(Color.Black);

spriteBatch.Begin(SpriteSortMode.FrontToBack, BlendState.Opaque, SamplerState.AnisotropicClamp, DepthStencilState.Default, RasterizerState.CullCounterClockwise);

[...Drawing methods for models etc. are called here...]

spriteBatch.End();
this.GraphicsDevice.SetRenderTarget(null);

And render the texture / save it as an image-file, some objects get transparent and the drawing order changes sort of randomly.

Source Link

XNA 4.0 - Strange Behavior when using RenderTarget2D

My Problem is similar to XNA 4.0 - Why does using a RenderTarget2d cause transparency on models?.

I want to render my scene to a Texture2D and then draw the texture. If I set no RenderTarget at all (render directly to the back buffer), everything looks fine.

I draw my models/textures with:

graphics.GraphicsDevice.Clear(Color.Black);
spriteBatch.Begin(SpriteSortMode.FrontToBack, BlendState.Opaque, SamplerState.AnisotropicClamp, DepthStencilState.Default, RasterizerState.CullCounterClockwise);

[...Drawing methods for models etc. are called here...]

spriteBatch.End();

If I change that code to:

RenderTarget2D target = new RenderTarget2D(this.GraphicsDevice,this.GraphicsDevice.PresentationParameters.BackBufferWidth,this.GraphicsDevice.PresentationParameters.BackBufferHeight);
this.GraphicsDevice.SetRenderTarget(target);

graphics.GraphicsDevice.Clear(Color.Black);

spriteBatch.Begin(SpriteSortMode.FrontToBack, BlendState.Opaque, SamplerState.AnisotropicClamp, DepthStencilState.Default, RasterizerState.CullCounterClockwise);

[...Drawing methods for models etc. are called here...]

spriteBatch.End();
this.GraphicsDevice.SetRenderTarget(null);

And render the texture / save it as an image-file, some objects get transparent and the drawing order changes sort of randomly.