Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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:

        GraphicsDevice.Clear(Color.Black);

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

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?

share|improve this question
2  
You can upload the pictures to a site like Photobucket, then post the URLs in your question. –  Marton Oct 25 '12 at 6:51
    
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. –  Andrew Russell Oct 25 '12 at 8:27
add comment

1 Answer

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.)

share|improve this answer
    
+1 For posting an actual solution, not just saying that my idea is absolutely wrong :-) –  Marton Oct 25 '12 at 10:46
    
What if I'm not using the content pipeline (eg. Monogame)? –  ashes999 Nov 30 '12 at 11:26
    
@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? –  Andrew Russell Nov 30 '12 at 11:39
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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