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

Author Topic: Blending of drawables with alpha on RenderImage (SFML2)  (Read 3036 times)

0 Members and 1 Guest are viewing this topic.

Tank

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1486
    • View Profile
    • Blog
    • Email
Blending of drawables with alpha on RenderImage (SFML2)
« on: October 28, 2009, 03:32:29 pm »
Hey,

I've just discovered a problem I can't solve. I'm drawing some sf::Strings onto an sf::RenderImage that got initialized with black full transparent pixels.

Now pixels of the strings having an alpha values are -- because it's alpha blending ;) -- blended with the RGBA = 0, 0, 0, 0 pixels of the sf::RenderImage, resulting in not displaying those pixels at all.

Is there any solution available? I want the sf::RenderImage to be transparent except stuff that I draw on it.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Blending of drawables with alpha on RenderImage (SFML2)
« Reply #1 on: October 28, 2009, 03:42:37 pm »
Actually they should be displayed. The blending equations gives this:
Code: [Select]
a = src.alpha * src.alpha + dst.alpha * (1 - src.alpha)
So the output alpha should be the square of src.alpha (*), not 0.

(*) this is still an error, but the only solution that I found involves using a function which is only available in OpenGL >= 1.4.
Laurent Gomila - SFML developer

Tank

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1486
    • View Profile
    • Blog
    • Email
Blending of drawables with alpha on RenderImage (SFML2)
« Reply #2 on: October 28, 2009, 04:04:34 pm »
Okay true, I just didn't see them because they were mixed with those black pixels. When I changed the RenderImage's background to RGBA = 255, 0, 255, 0, I was able to see that.

What I want is to apply a drawable to the RenderImage when the underlying pixel alpha value is 0. Is this anyhow possible?

I could use sf::Blend::None, but then alpha pixels of the source images are not drawn corretly. Any ideas? ;)

Edit:
Using sf::Blend::None for the sprite displaying the RenderImage solved my problem.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Blending of drawables with alpha on RenderImage (SFML2)
« Reply #3 on: October 28, 2009, 04:11:05 pm »
Quote
What I want is to apply a drawable to the RenderImage when the underlying pixel alpha value is 0. Is this anyhow possible?

So far, no. But it has nothing to do with the underlying pixels, the issue is related to how the source alpha is treated.

Quote
I could use sf::Blend::None, but then alpha pixels of the source images are not drawn corretly

Really? Using Blend::None should do a raw copy of the source pixels and completely overwrite the original image.

Quote
Edit:
Using sf::Blend::None for the sprite displaying the RenderImage solved my problem.

Ok, good :)
Forget my previous question.
Laurent Gomila - SFML developer

 

anything