SFML community forums

Bindings - other languages => DotNet => Topic started by: kaikimi on September 21, 2010, 05:41:26 pm

Title: blurry png and bmp sprite
Post by: kaikimi on September 21, 2010, 05:41:26 pm
I'm trying to learn SFML and I've made a small program that just displays a sprite. It seems the sprite is rather blurry though. The result is the same if i use a bmp or png.

here's a screenshot
(http://i798.photobucket.com/albums/yy270/ProjectFrostfire/blurryproggy.png)

here's my source
Program.cs
Code: [Select]
using System;
using SFML;
using SFML.Window;
using SFML.Graphics;

namespace SFMLTest
{
    class Program
    {
        public Player MyPlayer;

        static void OnClose(object Sender, EventArgs e)
        {
            RenderWindow Window = (RenderWindow)Sender;
            Window.Close();
        }

        static void Main(string[] args)
        {
            RenderWindow Window = new RenderWindow(new VideoMode(384,256),"Hello world!");
           
            Window.Closed += new EventHandler(OnClose);
            Window.KeyPressed += new EventHandler<KeyEventArgs>(OnKeyPressed);

            while(Window.IsOpened())
            {
                Window.DispatchEvents();
                Window.Clear();
               
                Player MyPlayer = new Player();
                Player.Initialize(MyPlayer);

                Sprite ImageToDraw = MyPlayer.Draw(MyPlayer);

                Window.Draw(ImageToDraw);

                Window.Display();
            }
        }

        static void OnKeyPressed(object Sender, KeyEventArgs e)
        {
            RenderWindow Window = (RenderWindow)Sender;
            if (e.Code == KeyCode.Escape)
                Window.Close();
        }
    }
}


Player.cs
Code: [Select]
using System;
using SFML;
using SFML.Window;
using SFML.Graphics;

namespace SFMLTest
{
    class Player
    {
        public int X,Y;
        public string ImagePath;

        public Player()
        {
        }

        public static void Initialize(Player Player)
        {
            Player.X = 100;
            Player.Y = 100;
            Player.ImagePath = "Images/TestImage.png";
        }

        public Sprite Draw(Player Player)
        {
            Sprite PlayerImage = new Sprite(new Image(Player.ImagePath));
            PlayerImage.Position = new Vector2(Player.X,Player.Y);
            return PlayerImage;
        }
    }
}
Title: blurry png and bmp sprite
Post by: Laurent on September 21, 2010, 08:15:23 pm
Call SetSmooth(false) on your image to disable linear filtering.
Title: blurry png and bmp sprite
Post by: kaikimi on September 21, 2010, 08:23:28 pm
Thanks, I didn't realize there was a property for that.
Title: blurry png and bmp sprite
Post by: blueeyedlion on June 28, 2011, 12:12:06 am
I am having a similar problem, but with fonts.  What do I do?
Title: blurry png and bmp sprite
Post by: Laurent on July 02, 2011, 10:24:19 pm
It's not a problem, fonts look very bad when smoothing is turned off so it's always on.
Title: blurry png and bmp sprite
Post by: blueeyedlion on July 04, 2011, 09:27:41 pm
maybe with the bigger fonts, but this one is very small and it looks funny when some of the pixels are grey.
Title: blurry png and bmp sprite
Post by: Ceylo on July 04, 2011, 10:17:41 pm
Dunno whether something has been done to prevent this on SFML's side now but... some time ago I remember that text looked blurred because I wasn't drawing it on integer coordinates. Make sure you're not asking SFML to draw your text on half pixels.