Jump to content
  • Advertisement
Sign in to follow this  
ironwill96

Blurry/Fuzzy Text Using Sprites [SOLVED]

This topic is 3712 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, I am using sprites to try to render text because I need to be able to rotate them etc. I moved this out of the other post about fuzzy text because it was confusing the original poster's issues and mine are not necessarily directly related. Here is the code where I actually render the sprites.
Microsoft.DirectX.Direct3D.Font font = new Microsoft.DirectX.Direct3D.Font(device, l.LayerFont.Height, 0, FontWeight.Normal, 0, false, CharacterSet.Default, Precision.Default, FontQuality.AntiAliased, PitchAndFamily.DefaultPitch, l.LayerFont.FontFamily.Name);                       

                        
Microsoft.DirectX.Direct3D.Sprite mySprite = new Sprite(device);

mySprite.Transform = Matrix.Transformation2D(new Microsoft.DirectX.Vector2(0, 0), 0.0f, new Microsoft.DirectX.Vector2(1, 1), new Microsoft.DirectX.Vector2((float)l.BmpObject.Width/2, (float)l.BmpObject.Height/2), l.RotationAngle, new Microsoft.DirectX.Vector2(l.XPosition - .5f, l.YPosition - .5f));

mySprite.Begin(SpriteFlags.AlphaBlend);
font.DrawText(mySprite, l.LayerText, new Rectangle(0, 0, l.BmpObject.Width, l.BmpObject.Height), DrawTextFormat.Center, Color.Black);
mySprite.End();    




And here is the code where I setup my device:
public void InitializeGraphics()
        {
            PresentParameters pp = new PresentParameters();
            pp.Windowed = true;
            pp.SwapEffect = SwapEffect.Discard;
            pp.EnableAutoDepthStencil = true;
            pp.AutoDepthStencilFormat = DepthFormat.D16;
            pp.DeviceWindowHandle = this.Handle;
            device = new Device(0, DeviceType.Hardware, this,
            CreateFlags.HardwareVertexProcessing, pp);
            //this.LoadTexturesAndMaterials();
            device.DeviceReset += new EventHandler(this.OnDeviceReset);
            OnDeviceReset(device, null);
            initialized = true;
           
        }

private void CameraPositioning()
        {
            if(this.mapMain != null)            
            {                                
                device.Transform.Projection = Matrix.OrthoLH(this.mapMain.getDXWidth(), this.mapMain.getDXHeight(), 1f, 550f);                
                device.Transform.View = Matrix.LookAtLH(new Microsoft.DirectX.Vector3(0, 0, 450), new Microsoft.DirectX.Vector3(0, 0, 0), new Microsoft.DirectX.Vector3(0, -1, 0));              
                                
                device.RenderState.Lighting = false; 
                
                device.RenderState.CullMode = Cull.None;
                
            }
            
        }


The camera positioning method you can see uses getDXWidth and getDXHeight to grab the size of the custom control that we are using to render DirectX to (we are not rendering to a form). The "l" object is a custom layer object I have for my drawings that stores a lot of meta-data. As you can see it has a rotation angle float built in as well as its x and y positions as they are translated. It also has a bitmap object that represents the size of the rectangle needed to draw the sprite that i'm using to grab the width and height. My font is pretty fuzzy as you can see in the pictures below and gets worse as soon as I rotate it. It does seem like i'm getting a texel alignment issue of some sort, but I can't figure out where I would pass the -.5 offset to the X and Y as this article suggests to do: http://msdn.microsoft.com/en-us/library/bb219690.aspx I tried putting it in my translation matrix but that obviously didn't make any difference and the font.DrawText only takes ints for the rectangle the sprite is put on. Here are two pictures to illustrate the issue: Test Image before rotation (note still slightly blurry): Test image after some rotation (note how much more blurry it is): Thanks, Nathan EDIT: Solution (see last post) was to change the backbuffer size to match the client render window. This is done when setting up your present parameters when you are creating the device (e.g. pp.BackBufferWidth = yourRenderWindowWidth) [Edited by - ironwill96 on July 22, 2008 7:25:59 PM]

Share this post


Link to post
Share on other sites
Advertisement
It looks like a filtering issue. You should be able to turn off the texture filtering before rendering the font.

Share this post


Link to post
Share on other sites
I don't have any filtering explicitly turned on? I tried turning on a min / max anistropy filter but that didn't help any either. I also ran a test to show the 6 variations of Font Quality using this code:



Microsoft.DirectX.Direct3D.Font font = new Microsoft.DirectX.Direct3D.Font(device, l.LayerFont.Height, 0, FontWeight.Normal, 0, false, CharacterSet.Default, Precision.Default, FontQuality.AntiAliased, PitchAndFamily.DefaultPitch, l.LayerFont.FontFamily.Name);
Microsoft.DirectX.Direct3D.Font font2 = new Microsoft.DirectX.Direct3D.Font(device, l.LayerFont.Height, 0, FontWeight.Normal, 0, false, CharacterSet.Default, Precision.Default, FontQuality.ClearType, PitchAndFamily.DefaultPitch, l.LayerFont.FontFamily.Name);
Microsoft.DirectX.Direct3D.Font font3 = new Microsoft.DirectX.Direct3D.Font(device, l.LayerFont.Height, 0, FontWeight.Normal, 0, false, CharacterSet.Default, Precision.Default, FontQuality.ClearTypeNatural, PitchAndFamily.DefaultPitch, l.LayerFont.FontFamily.Name);
Microsoft.DirectX.Direct3D.Font font4 = new Microsoft.DirectX.Direct3D.Font(device, l.LayerFont.Height, 0, FontWeight.Normal, 0, false, CharacterSet.Default, Precision.Default, FontQuality.NonAntiAliased, PitchAndFamily.DefaultPitch, l.LayerFont.FontFamily.Name);
Microsoft.DirectX.Direct3D.Font font5 = new Microsoft.DirectX.Direct3D.Font(device, l.LayerFont.Height, 0, FontWeight.Normal, 0, false, CharacterSet.Default, Precision.Default, FontQuality.Proof, PitchAndFamily.DefaultPitch, l.LayerFont.FontFamily.Name);
Microsoft.DirectX.Direct3D.Font font6 = new Microsoft.DirectX.Direct3D.Font(device, l.LayerFont.Height, 0, FontWeight.Normal, 0, false, CharacterSet.Default, Precision.Default, FontQuality.Default, PitchAndFamily.DefaultPitch, l.LayerFont.FontFamily.Name);



Here is the resulting image rotated (looks similar when not rotated just a little less blurry all around):

Share this post


Link to post
Share on other sites
Quote:
Original post by ironwill96
I don't have any filtering explicitly turned on?

Turn all filtering explicitly (use point filtering)

Quote:
Original post by ironwill96
I tried turning on a min / max anistropy filter but that didn't help any either.

Anisotropic filtering won't help you at all. It's used for 3D rotations and parallax issues, which isn't your case.

Quote:
Original post by ironwill96
Here is the resulting image rotated (looks similar when not rotated just a little less blurry all around):

Again, disable filtering. Also expect some blurriness when rotating. But should look fine near perfect without rotation.

Good luck
Dark Sylinc

PS: Ensure your (i.e. NVIDIA) driver settings are set to High Quality.

Share this post


Link to post
Share on other sites
Figured it out thanks to the other post about these issues. I did not have my backbuffer size set to match my client render area! This made all the difference and now I have crisp text!

[Edited by - ironwill96 on July 22, 2008 7:38:59 PM]

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!