Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: blurry png and bmp sprite  (Read 5235 times)

0 Members and 1 Guest are viewing this topic.

kaikimi

  • Newbie
  • *
  • Posts: 5
    • View Profile
blurry png and bmp sprite
« 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


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;
        }
    }
}

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
blurry png and bmp sprite
« Reply #1 on: September 21, 2010, 08:15:23 pm »
Call SetSmooth(false) on your image to disable linear filtering.
Laurent Gomila - SFML developer

kaikimi

  • Newbie
  • *
  • Posts: 5
    • View Profile
blurry png and bmp sprite
« Reply #2 on: September 21, 2010, 08:23:28 pm »
Thanks, I didn't realize there was a property for that.

blueeyedlion

  • Jr. Member
  • **
  • Posts: 61
    • View Profile
blurry png and bmp sprite
« Reply #3 on: June 28, 2011, 12:12:06 am »
I am having a similar problem, but with fonts.  What do I do?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
blurry png and bmp sprite
« Reply #4 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.
Laurent Gomila - SFML developer

blueeyedlion

  • Jr. Member
  • **
  • Posts: 61
    • View Profile
blurry png and bmp sprite
« Reply #5 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.

Ceylo

  • Hero Member
  • *****
  • Posts: 2325
    • View Profile
    • http://sfemovie.yalir.org/
    • Email
blurry png and bmp sprite
« Reply #6 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.
Want to play movies in your SFML application? Check out sfeMovie!

 

anything