SFML community forums
Bindings - other languages => DotNet => Topic started 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
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
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;
}
}
}
-
Call SetSmooth(false) on your image to disable linear filtering.
-
Thanks, I didn't realize there was a property for that.
-
I am having a similar problem, but with fonts. What do I do?
-
It's not a problem, fonts look very bad when smoothing is turned off so it's always on.
-
maybe with the bigger fonts, but this one is very small and it looks funny when some of the pixels are grey.
-
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.