SFML community forums

Help => Graphics => Topic started by: AClockWorkLemon on October 02, 2011, 06:06:50 am

Title: [solved] Issue with blurring
Post by: AClockWorkLemon on October 02, 2011, 06:06:50 am
Heya, first post here so sorry if i make a few mistakes.
I'm pretty new to SFML, but things seem to me (mostly) working out as-so-far. That said, i've run into an issue with drawing sprites onto the screen. The sprite is being drawn in the correct position, however it would seem to be slightly blurred. I'm guessing that this has something to do with the fact sprites are positioned with floats, but i'm not sure.
Here's a comparison between the Source image and the Output (I've scaled them up a bit so it's easy to see)

SOURCE
(http://i52.tinypic.com/21dn47s.png)
OUTPUT
(http://i51.tinypic.com/51sjsy.png)

If it's of any help, this is the snippet of code which renders it. If you need more code, feel free to ask :3
Code: [Select]

def Render(self, App, pos=(0, 0)):
self.SetPosition(self.x+pos[0], self.y+pos[1])
App.Draw(self)
Title: [solved] Issue with blurring
Post by: thePyro_13 on October 02, 2011, 12:16:38 pm
You should set image.SetSmooth(false) to disable the blurry effect.

If they're still blurry then you may need to round your sprite positions to the nearest integer.
Title: [solved] Issue with blurring
Post by: AClockWorkLemon on October 02, 2011, 01:20:41 pm
SetSmooth didn't seem to do much, neither did wrapping the locations in int().
Seems kinda weird. If it helps, this is the full graphics code:
Code: [Select]


from PySFML import sf

class Image(sf.Sprite):
def __init__(self, loc):
self.img = GetImage(loc)
self.img.SetSmooth(False)
sf.Sprite.__init__(self, self.img)

#Positions for drawing (relative to parent object)
self.x = 0
self.y = 0

def Render(self, App, pos=(0, 0)):
self.SetPosition(int(self.x+pos[0]), int(self.y+pos[1]))
App.Draw(self)

imageCache = {}
def GetImage(loc):
try: #Will only run if already loaded
return imageCache[loc]
except KeyError:
Image = sf.Image()
if not Image.LoadFromFile(loc):
return None
imageCache[loc] = Image
return Image


Also, if you spot some stupid newb mistakes, please point them out :3
I'm still learning :D

EDIT
I had a thought that it might be a bad PNG encode or something, so i saved a TGA, but it had the same result. Also, it would seem that no matter how it's placed, the smoothing is always exactly the same. --Possibly an error in the reading of the file?-- Nope, it's definately smoothing of some kind creeping in there

EDIT 2
Did a few more tests, i have no idea what is causing this.
I saved the image using Image.SaveToFile both directly after loading, and when it's used in the Sprite, both saved an un-edited version (no blurring)
What the hell is going on? Could it be something to do with the python binding? I'd prefer not to have to use C/++ for this, as it's a bit advanced for my current skill level.
Title: [solved] Issue with blurring
Post by: AClockWorkLemon on October 05, 2011, 09:13:09 am
Sorry to bump, but this is posing quite an issue.

If the solution is to upgrade to SFML v2, would someone be able to point me in the direction of Binaries for SFML and the python binding? Admittedly i gave up quite quickly, but the whole build process just had me confused. If you can give some good tips for compiling, that's always helpful as well...
Title: [solved] Issue with blurring
Post by: Laurent on October 05, 2011, 09:35:17 am
Quote
would someone be able to point me in the direction of Binaries for SFML and the python binding?

You should post a new thread in the Python forum, only the python binding(s) maintainer(s) can help you with this issue.
Title: [solved] Issue with blurring
Post by: AClockWorkLemon on October 05, 2011, 11:11:24 am
Quote from: "Laurent"
Quote
would someone be able to point me in the direction of Binaries for SFML and the python binding?

You should post a new thread in the Python forum, only the python binding(s) maintainer(s) can help you with this issue.


Ok, thanks. Is there any way of resolving this w/o upgrading to 2.0 by any chance?
Title: [solved] Issue with blurring
Post by: Laurent on October 05, 2011, 12:04:12 pm
Maybe.

Could you post a complete and minimal source code that reproduces this problem?
Title: [solved] Issue with blurring
Post by: AClockWorkLemon on October 05, 2011, 02:01:32 pm
The code below produces exactly this output reliably:

(http://i56.tinypic.com/2hnqgeu.png)

Code: [Select]

from PySFML import sf

App = sf.RenderWindow(sf.VideoMode(200, 200, 32), "Image Blur Reproduction")
App.SetFramerateLimit(30)

img = sf.Image()
if not img.LoadFromFile("Ship.png"):
print "Error: Could not load image"
spr = sf.Sprite(img)
spr.SetPosition(80, 92)

bg = sf.Color(194, 194, 194)
while App.IsOpened():
App.Clear(bg)

e = sf.Event()
while App.GetEvent(e):
if e.Type == sf.Event.Closed:
App.Close()

App.Draw(spr)

App.Display()


This is the original image (Ship.png)
(http://i51.tinypic.com/24p9mp5.png)

The background colour and positioning have no effect, i added them to make it a bit easier to see.
Title: [solved] Issue with blurring
Post by: Laurent on October 05, 2011, 02:16:48 pm
Yep... but this one is normal since you don't disable smoothing on the image ;)
Title: [solved] Issue with blurring
Post by: AClockWorkLemon on October 05, 2011, 02:20:27 pm
Oops, forgot to add it in xD
Added it in this time, same results...

Code: [Select]

from PySFML import sf

App = sf.RenderWindow(sf.VideoMode(200, 200, 32), "Image Blur Reproduction")
App.SetFramerateLimit(30)

img = sf.Image()
img.SetSmooth(False)
if not img.LoadFromFile("Ship.png"):
print "Error: Could not load image"
spr = sf.Sprite(img)
spr.SetPosition(80, 92)

bg = sf.Color(194, 194, 194)
while App.IsOpened():
App.Clear(bg)

e = sf.Event()
while App.GetEvent(e):
if e.Type == sf.Event.Closed:
App.Close()

App.Draw(spr)

App.Display()
Title: [solved] Issue with blurring
Post by: Laurent on October 05, 2011, 02:27:08 pm
Well, the image is obviously smoothed so it might be a bug in the SetSmooth function of the Python binding.
Title: [solved] Issue with blurring
Post by: AClockWorkLemon on October 05, 2011, 02:56:43 pm
Ok, thanks. i'll take a look, see if i can fix it.