SFML community forums

Help => Graphics => Topic started by: nonexistent on March 09, 2010, 10:36:33 pm

Title: Black outline when rendering sprite
Post by: nonexistent on March 09, 2010, 10:36:33 pm
Hi, I'm getting a black outline on a sprite when rendering in SFML.  The original grass image looks like:

(http://www.contrib.andrew.cmu.edu/~gchin/misc/sfml/grass.png)

and rendered in SFML looks like:

(http://www.contrib.andrew.cmu.edu/~gchin/misc/sfml/sfml-grass.png)

The sprite is loaded into an Image, stuck in a Sprite, and rendered with RenderWindow's Draw().  I haven't calling any resizing or scaling functions on the sprite.

I'm guessing this is some sort of side effect of the alpha blending in the sprite blend mode.  Any ideas to minimize this unwanted outline?
Title: Black outline when rendering sprite
Post by: Laurent on March 09, 2010, 11:14:58 pm
You can try this:
Code: [Select]
image.SetSmooth(false);
Title: Black outline when rendering sprite
Post by: nonexistent on March 10, 2010, 02:36:08 am
Calling SetSmooth(false) on the image resulted in no graphical difference unfortunately  :(  None of the sprite Blend Modes aside from Alpha seem to allow transparency, so that's no good either.
Title: Black outline when rendering sprite
Post by: Laurent on March 10, 2010, 08:26:52 am
Is the first image that you posted the original one? If not, can you upload it?
Title: Black outline when rendering sprite
Post by: nonexistent on March 10, 2010, 08:59:57 am
Yes, that is the exact image I am loading from file.  Thanks for the quick replies so far!
Title: Black outline when rendering sprite
Post by: Laurent on March 10, 2010, 09:12:50 am
I've tested the image and can't see any outline.

Quote
I haven't calling any resizing or scaling functions on the sprite

What about your window, is it resized after creation?
Do you use a view?
Title: Black outline when rendering sprite
Post by: nonexistent on March 12, 2010, 03:40:29 am
Hmm, very interesting.  I made a mistake posting the original image, that's not the one I am loading in my file.  I extended the image size to the closest powers of 2 to make it 256x64.  The loaded 256x64 image displays the black outline problem, but loading the original 224x43 image renders correctly.

Does SFML do something special internally w/ power of 2 textures?  I've been manually image editing all my textures to be powers of 2 to account for older graphics cards.
Title: Black outline when rendering sprite
Post by: Laurent on March 12, 2010, 07:55:04 am
Quote
Does SFML do something special internally w/ power of 2 textures?

No, it should make no difference.

Quote
I've been manually image editing all my textures to be powers of 2 to account for older graphics cards.

You don't have to do that, this is automatically handled by SFML.

Can you upload the 256x64 image that causes the problem?
Title: Black outline when rendering sprite
Post by: nonexistent on March 12, 2010, 08:10:20 pm
Here is the 256x64 image
(http://www.contrib.andrew.cmu.edu/~gchin/misc/sfml/grass-pow2.png)

It is the same as the original except padded w/ additional transparent pixels.
Title: Black outline when rendering sprite
Post by: Trass3r on March 13, 2010, 04:46:42 am
I've had the same problem for quite a while. Disabling smoothing indeed solves the outline problem but it makes the graphics look more pixelated (cause they are from an old game) :(

with smoothing (standard):
(http://img717.imageshack.us/img717/1813/withsmooth.th.png) (http://img717.imageshack.us/img717/1813/withsmooth.png)

disabled smoothing:
(http://img171.imageshack.us/img171/3585/withoutsmooth.th.png) (http://img171.imageshack.us/img171/3585/withoutsmooth.png)
Title: Black outline when rendering sprite
Post by: Laurent on March 13, 2010, 10:36:35 am
I see.

This is the kind of problems that you can expect with SFML 1 (unfortunately), but this is already fixed in SFML 2.
Title: Black outline when rendering sprite
Post by: Trass3r on March 13, 2010, 11:58:38 am
No. I'm using (D)SFML2  :wink:
Title: Black outline when rendering sprite
Post by: Laurent on March 13, 2010, 04:23:32 pm
Quote from: "Trass3r"
No. I'm using (D)SFML2  :wink:

Ah... you should have said it before ;)
Can you send me your tileset?
Title: Black outline when rendering sprite
Post by: Laurent on March 13, 2010, 04:56:02 pm
I have no problem with your tiles. Make sure that your coordinates are properly aligned with the pixels of the window (no decimal coordinates).
Title: Black outline when rendering sprite
Post by: Sivak on March 18, 2010, 12:15:25 am
Hey all.  Sorry to jump in, but I've gotten graphics to display and I wondered if there's a way to have EVERY image loaded with setsmooth to false?  It fixed 2 problems I had with what I was going for displaying.
Title: Black outline when rendering sprite
Post by: Laurent on March 18, 2010, 08:10:07 am
No. But you can easily wrap it into your own loading function or manager.
Title: I have a problem like this.
Post by: gontai on April 20, 2010, 10:42:40 am
First of all, sorry to my ugly English.

When I use "SFML-1.5", SetSmoth(true), it is fine to rendering. But "SFML-1.6" and "SFML-2.0" are Black outline like this (Win32 sample Project).

Look at the rotated Image.

<SFML-2.0>
(http://i42.tinypic.com/3466y5s.png)

<SFML-1.6>
(http://i39.tinypic.com/i6ysub.png)

<SFML-1.5>
(http://i42.tinypic.com/2s8jk9h.png)



"SFML-1.6" and "SFML-2.0" are Ok that "SetSmooth(false)". But I wanna smooth Image.

Why this happen?  :roll:
Title: Black outline when rendering sprite
Post by: Laurent on April 20, 2010, 01:10:14 pm
It should be ok now in SFML 2.