• Advertisement
Sign in to follow this  

Blurred Sprite?

This topic is 3856 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

Hello people of GameDev.net I am trying to understand the basics of directx, and starting a gameengine or something.. now i got one little problem My sprites are blurred.. like this messagebox: Original sprite: in directx: Does anyone know a solution for this problem? btw, im using c#.net 2005 with DirectX SDK June 2007 If you need to know more information, just ask. :-) Kind regards, djnevs

Share this post


Link to post
Share on other sites
Advertisement
thought so..
that what i found on the net, doesnt realy work for me..
maybe there is some other solution?

i got this code:
device.SamplerState[0].MipFilter = TextureFilter.None;
device.SamplerState[0].MinFilter = TextureFilter.None;
device.SamplerState[0].MagFilter = TextureFilter.None;
device.SamplerState[0].MaxAnisotropy = int.MaxValue;
device.SamplerState[0].MipMapLevelOfDetailBias = 0;
device.SamplerState[0].SrgbTexture = true;


I placed this in the InitializeDevice section..
if i change the TextureFilter to Anisotropic or something, doesnt work eighter

Share this post


Link to post
Share on other sites
what technique are you using to draw the textures to the screen? ID3DXSprite? something else?

Share this post


Link to post
Share on other sites
It's hard to tell with that paricular sprite. Things to try:
  • Make sure your window client area is the size you think it is. I'm not sure about C#, but with C++ you specify a window size, not client area size. So if you create a window that's 800x600, your client area might be 782x594, which means if your backbuffer is 800x600, it'll be blurred when it's shrunk to the window size.
  • If your texture is close to a power of 2 in size (E.g. 250x120), it's possible that the texture is being loaded as a power of two (256x128), and getting blurred as a result.
  • As Dancin_Fool suggested, what texture filtering mode are you using?
  • If you're using transformed vertices, are you offsetting your vertices by half a pixel? (See Here for an explanation, skip to "Summary" at the bottom if you're in a hurry).

    Overall, we'll need to see some code to help you some more. It might also be worthwhile trying a more "simple" texture and see if you get a more distinctive pattern. Try a texture that alternates black and white texels in a checkerboard pattern. Stretching should be obvious then.

    Share this post


    Link to post
    Share on other sites
    this is my addsprite class:

    using System;
    using System.Collections.Generic;
    using System.Text;
    using Microsoft.DirectX;
    using Microsoft.DirectX.Direct3D;

    public class cSprite
    {
    private Sprite spr;
    private Texture sprTexture;

    public void Create(Device device, string file)
    {
    sprTexture = TextureLoader.FromFile(device, file);
    spr = new Sprite(device);

    }


    public void OnPaint(int x, int y, int width, int height)
    {
    spr.Begin(SpriteFlags.AlphaBlend);
    spr.Draw2D( sprTexture,
    System.Drawing.Rectangle.Empty,
    new System.Drawing.SizeF(width,height),
    new System.Drawing.PointF(x,y),
    System.Drawing.Color.White.ToArgb()
    );
    spr.End();
    }

    public void OnReset() { }

    public void Dispose()
    {
    spr.Flush();
    }
    }



    edit: changing backbuffer results same...

    Share this post


    Link to post
    Share on other sites
    Quote:
    Original post by djnevs
    look

    or isnt this what you mean?
    I meant having each alternate pixel of the texture a different colour, rather than a block of pixels the same colour. Where the first scanline of your texture might be:
    ########################........................
    I meant:
    #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.

    But your texture helps a bit too, it shows that there seems to be either a filtering or wrapping issue. As for exactly what it is, I'm not sure I'm afraid.

    Share this post


    Link to post
    Share on other sites
    You're on the right lines with your sampler state settings, but you need to set them after your spr.Begin(...) call.

    Share this post


    Link to post
    Share on other sites
    Quote:

    Original post by djnevs
    It's working :D


    How did you fix it?

    Share this post


    Link to post
    Share on other sites
    I edited my cSprite.cs:

    take a look

    using System;
    using System.Collections.Generic;
    using System.Text;
    using Microsoft.DirectX;
    using Microsoft.DirectX.Direct3D;

    public class cSprite
    {
    private Sprite spr;
    private Texture sprTexture;

    public void Create(Device device, string file)
    {
    sprTexture = TextureLoader.FromFile(device, file);
    spr = new Sprite(device);

    }


    public void OnPaint(Device device, int x, int y, int width, int height)
    {
    spr.Begin(SpriteFlags.AlphaBlend);
    device.SamplerState[0].MipFilter = TextureFilter.None;
    device.SamplerState[0].MinFilter = TextureFilter.None;
    device.SamplerState[0].MagFilter = TextureFilter.None;
    device.SamplerState[0].MaxAnisotropy = int.MaxValue;
    device.SamplerState[0].MipMapLevelOfDetailBias = 0;
    device.SamplerState[0].SrgbTexture = true;
    spr.Draw2D( sprTexture,
    System.Drawing.Rectangle.Empty,
    new System.Drawing.SizeF(width,height),
    new System.Drawing.PointF(x,y),
    System.Drawing.Color.White.ToArgb()
    );
    spr.End();
    }

    public void OnReset() { }

    public void Dispose()
    {
    spr.Flush();
    }
    }


    as you can see, as MrP already said,
    I got the SamplerState stuff right
    just needed to move it to the right position
    thats between
    spr.Begin and spr.End..

    1 thing you just need to do, is the device parameter in de OnPaint method.
    otherwise, it cant find device.blabla

    Share this post


    Link to post
    Share on other sites
    Glad I could help. I will just add two more pieces of information. The first, is that you can access the device associated with the Sprite object by using the Device member of the Direct3D.Sprite class.


    spr.Device.SamplerState[0].MipFilter = TextureFilter.None;
    spr.Device.SamplerState[0].MinFilter = TextureFilter.None;
    spr.Device.SamplerState[0].MagFilter = TextureFilter.None;
    spr.Device.SamplerState[0].MaxAnisotropy = int.MaxValue;
    spr.Device.SamplerState[0].MipMapLevelOfDetailBias = 0;
    spr.Device.SamplerState[0].SrgbTexture = true;





    Second, you may wish to reconsider how you are using the Direct3D.Sprite class.
    It appears that your cSprite class is used to represent an on-screen sprite, and therefore should not have an instance of the Direct3D.Sprite class.

    The reason for this is that the Direct3D Sprite class batches the draw calls between the begin() and end()/flush() methods in an attempt to achieve optimal performance.

    I would consider something like this, where you pass the Direct3D.Sprite object to your cSprite.onPaint method:


    d3dSprite.begin(SpriteFlags.AlphaBlend);

    foreach(cSprite sprite in spriteList)
    sprite.onPaint(d3dSprite); // ignoring position for the sake of the example

    d3dSprite.end();



    Share this post


    Link to post
    Share on other sites
    Sign in to follow this  

    • Advertisement