Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


XNA, I have problems with anti-aliasing


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 Cadu   Members   -  Reputation: 110

Like
0Likes
Like

Posted 04 November 2012 - 01:30 PM

I was trying make a font system, and I can't fix anti-aliasing, unicode is working.

Posted Image

Here is my code:
[source lang="csharp"]protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Microsoft.Xna.Framework.Color.CornflowerBlue); Font font = new Font("Arial Unicode MS", 32, FontStyle.Bold, GraphicsUnit.Pixel); Bitmap bitmap = new Bitmap(500, 500, System.Drawing.Imaging.PixelFormat.Format32bppArgb); Graphics g = Graphics.FromImage(bitmap); g.TextRenderingHint = TextRenderingHint.AntiAliasGridFit; g.DrawString("anti aliasing, テスト。", font, new SolidBrush(System.Drawing.Color.White), 0, 0, StringFormat.GenericDefault); bitmap.Save("buffer"); float offset = font.SizeInPoints / font.FontFamily.GetEmHeight(font.Style) * font.FontFamily.GetCellAscent(font.Style); Texture2D texture; using (FileStream fileStream = new FileStream("buffer", FileMode.Open)) { texture = Texture2D.FromStream(GraphicsDevice, fileStream); } spriteBatch.Begin(); spriteBatch.Draw(texture, new Microsoft.Xna.Framework.Rectangle(0, 0, texture.Width, texture.Height), Microsoft.Xna.Framework.Color.Black); spriteBatch.Draw(texture, new Microsoft.Xna.Framework.Rectangle(0, 50, texture.Width, texture.Height), Microsoft.Xna.Framework.Color.Red); spriteBatch.Draw(texture, new Microsoft.Xna.Framework.Rectangle(0, 100, texture.Width, texture.Height), Microsoft.Xna.Framework.Color.GreenYellow); spriteBatch.Draw(texture, new Microsoft.Xna.Framework.Rectangle(0, 150, texture.Width, texture.Height), Microsoft.Xna.Framework.Color.Green); spriteBatch.End(); base.Draw(gameTime); }[/source]

Sponsor:

#2 phil_t   Crossbones+   -  Reputation: 4091

Like
3Likes
Like

Posted 04 November 2012 - 02:12 PM

SpriteBatch uses pre-multiplied alpha by default, but textures loaded through Texture2D.FromStream don't have pre-multiplied alpha (unlike ones loaded through the content pipeline).

That may be the cause of your issue. So one fix is to use the SpriteBatch.Begin overload that takes a BlendState, and use BlendState.NonPremultiplied.

#3 Cadu   Members   -  Reputation: 110

Like
0Likes
Like

Posted 04 November 2012 - 03:58 PM

Like that:
[source lang="csharp"]spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied);[/source]

or just

[source lang="csharp"]spriteBatch.Begin(SpriteSortMode.Texture, BlendState.NonPremultiplied);[/source]

Let me know if that is correct?

Edited by Cadu, 04 November 2012 - 04:01 PM.


#4 phil_t   Crossbones+   -  Reputation: 4091

Like
2Likes
Like

Posted 04 November 2012 - 05:20 PM

You were using the overload of Begin that took no parameters before - that uses SpriteSortMode.Deferred internally (look at the documentation). So use SpriteSortMode.Deferred.

Edited by phil_t, 04 November 2012 - 05:20 PM.


#5 Cadu   Members   -  Reputation: 110

Like
0Likes
Like

Posted 04 November 2012 - 05:58 PM

Well. it works for now :)

Thank you for help, +1 rep.

#6 Cadu   Members   -  Reputation: 110

Like
0Likes
Like

Posted 10 November 2012 - 04:55 PM

Well, I have been working on it. Other problem is that I can't make textbox input in Chinese or Japaese, any idea? (All font are working.)




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS