Ok, I'm very new to graphics programming (but not new to coding). I'm trying to load a simple image in XNA which I can do fine. It is a simple round circle which I made in photoshop. The problem is the edges show up rough when I draw it on the screen even with the exact size. The anti-aliasing is missing. I'm sure I'm missing something very simple:


        // TODO: Add your drawing code here
        spriteBatch.Draw(circle, new Rectangle(10, 10, 10, 10), Color.White);           

Couldn't post picture because I'm a first time poster. But my smooth png circle has rough edges. So I found that if I added:

spriteBatch.Begin(SpriteSortMode.FrontToBack, BlendState.NonPremultiplied);

I can get a smooth image when the image is the same size as the original png. But if I want to scale that image up or down then the rough edges return. How do I get XNA to smoothly resize my simple round image to a smaller size without getting the rough edges?

  • 2
    \$\begingroup\$ You can upload the pictures to a site like Photobucket, then post the URLs in your question. \$\endgroup\$ – Marton Oct 25 '12 at 6:51
  • \$\begingroup\$ How are you loading your texture? The default content pipeline settings enable premultiplied alpha. So turning it off with BlendState.NonPremultiplied is probably a bad idea (and using premultiplied alpha is good anyway). I suspect your problem lies elsewhere. \$\endgroup\$ – Andrew Russell Oct 25 '12 at 8:27

Have a read of this article on texture aliasing (and the ones it links). It explains exactly why you are having this issue.

While there are many techniques for rendering an anti-aliased circle, the simplest one for your situation is to turn on mipmaps for your texture.

To do so, make sure your texture is in an XNA Content Project. Select it and press F4. You should see the following window:

Generate Mipmaps

Expand the "Content Processor" node and set "Generate Mipmaps" to true. You don't need to make any changes to your code to make mipmaps work.

(Note that "Premultiuply Alpha" is set to true by default. You should leave this set and use BlendState.Alpha, which is the default for SpriteBatch.Begin. Leave texture filtering as the default of "linear" as well.)

| improve this answer | |
  • 1
    \$\begingroup\$ +1 For posting an actual solution, not just saying that my idea is absolutely wrong :-) \$\endgroup\$ – Marton Oct 25 '12 at 10:46
  • \$\begingroup\$ What if I'm not using the content pipeline (eg. Monogame)? \$\endgroup\$ – ashes999 Nov 30 '12 at 11:26
  • \$\begingroup\$ @ashes999 The technique itself (mipmapping) is still valid. But I have no idea how to set it up in MonoGame (or if it's even supported yet - you might need to do some manual OpenGL/DirectX trickery). Ask in a fresh question, perhaps? \$\endgroup\$ – Andrew Russell Nov 30 '12 at 11:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.