Anti-aliased sprites (and how I don't want them).

I'm trying to display 2d images on screen using the Sprite class in Managed DirectX (C#) but unfortunately they always come out blurred.  As far as I can tell, I'm using the correct sizes for the source and destination rectangles (and I've experimented by varying the sizes; e.g. the increase dimensions by 1 pixel to sort out sizing problems) and my texture is loaded using either point filtering or no filtering.
The sprite never comes out as sharp or as bright as it should be.  I've tried numerous example pieces of code (including the simple2d example with the SDK) and they all give the same result.  Can anyone give any advice  


For reference, I'm using this code to load the image:

piccy = D3D.TextureLoader.FromFile(m_device, image, 256, 256, 1, D3D.Usage.None, D3D.Format.R8G8B8, D3D.Pool.Managed, D3D.Filter.None, D3D.Filter.None, (int)(0x00000000));


And this code to try and display it:

sprite.Draw(piccy, new Vector3(0.0f, 0.0f, 0), new Vector3(0, 0, 0), (int)0xFFFFFF);

or

sprite.Draw2D(piccy, new Rectangle(0, 0, 256, 256), new SizeF(256, 256), new Point(0, 0), Color.White);

or even

sprite.Draw2D(piccy, Rectangle.Empty, SizeF.Empty, new Point(0, 0), Color.White);

All give the same result.



Answer this question

Anti-aliased sprites (and how I don't want them).

  • Vytas

    Thanks for the reply, it helped a lot :)

    I ended up replacing the D3DXSprite with a triangle strip, and now the graphics come out crystal clear.
    I'm guessing there's some fundamental flaws with the D3DXSprite system, which is a shame as it's really easy to use.
    Does anyone know if Microsoft will get round to addressing these problems in the next DX release

  • simon mcinnes

    As far as I know sprite just does what you have done. You just have to get the texture coordinates right (as you would have had to in your triangle strip). Yours is a common problem though and happy to see you solve it.

  • debeerBiz

    I have found that the problem is also caused by render states set by the Sprite object. You can avoid the filtering by setting the texture filter states to point filtering after calling ID3DXSprite::Begin(). It was not at all clear from the documentation that if you want to modify render states you need to do it after calling the Begin method.

    Hope this helps.

    Russell Klenk
    XS-Technology
    http://www.xsdev.net
    russ [at] xsdev [dot] net


  • StevenR2

    Not sure what you mean by blurry, but the usual 2d issue is that the pixels are not lined up with the screen pixels. See if this helps http://msdn.microsoft.com/library/ url=/library/en-us/directx9_c/Directly_Mapping_Texels_to_Pixels.asp frame=true

    If not send a link to a picture so we can help debug.

  • Stut

    It works perfectly, thanks! :)
  • Anti-aliased sprites (and how I don't want them).