My RenderTarget2D becomes distorted for some reason?

Started by
0 comments, last by VoSSer 12 years, 2 months ago
Hi.
Experimenting a bit with RenderTarget2D in XNA 4 and I seem to be doing something wrong, but I cant figure out what.

Starting off with this:
SpriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, null, null,null);
RenderTarget2D target = new RenderTarget2D(GraphicsDevice, 512,512);
GraphicsDevice.SetRenderTarget(target);
GraphicsDevice.Clear(Color.Green);


I then try to draw a planet texture that is 512x512 pixel:
SpriteBatch.Draw(RedPlanet512, new Vector2(256,256), null, Color.White, 0f, _origin, 1f, SpriteEffects.None, 1f);

Then just to clarify the problem i draw three red circle textures each 64x64 pixels.
SpriteBatch.Draw(RedCircle64, new Vector2(0, 0), Color.White);
SpriteBatch.Draw(RedCircle64, new Vector2(256, 256), Color.White);
SpriteBatch.Draw(RedCircle64, new Vector2(512, 512), Color.White);


When i try to draw this to the screen the resulting RenderTarget2D texture is compressed in a weird way, even thought the green backgrouns is the right size.. I thought it might be me drawing it incorrectly so i used target.SaveAsPng(stream, target.Width, target.Height); to see what the target actually looks like.. and I dont understand why it is compressed like it is.. See the attached picture.

Any help would be greatly appreciated
Advertisement
Solved it.
I called the methods in the wrong order.
This works without distortion:
RenderTarget2D target = new RenderTarget2D(GraphicsDevice, 512,512);
GraphicsDevice.SetRenderTarget(target);
SpriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, null, null,null);
GraphicsDevice.Clear(Color.Green);


Moved the Begin() statement to after the point where i set the rendertarget. Assuming the weird compression was because the batch uses my monitors 16:10 format by default and because I dident set the render target untill after the begin this was causing problems.

This topic is closed to new replies.

Advertisement