Jump to content
  • Advertisement
Sign in to follow this  
VoSSer

My RenderTarget2D becomes distorted for some reason?

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

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!