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

Author Topic: Masking in SFML 2  (Read 4272 times)

0 Members and 1 Guest are viewing this topic.

posva

  • Full Member
  • ***
  • Posts: 118
  • Feed me pls
    • View Profile
    • Posva Dev Blog
Masking in SFML 2
« on: July 28, 2011, 03:18:24 pm »
Hi, i'm wondering how to mask in SFML 2. I know that someone added a topic to the wiki for SFML 1.6 but i suppose that now that we have RenderImages we can do it with BlendModes, i cannot achieve it though...
I have being trying for a few hours now and stills doesn't work properly. I tried with many techniques but nothing...
The last one i tried was to have the sprite (lready masked) drawn to a black rectangle and then draw that rectangle with blend Add into a transparent surface but it doesn't work it about the same img.
Here is my code so far:
Code: [Select]

mask_img.Create(640,480);
    effects_img.Create(640, 480);
    light_img.Create(640, 480);
    inter_img.Create(640, 480);
mask_img.Clear(sf::Color(0,0,0,255));
    effects_img.Clear(sf::Color(0,0,0,0));
    light_img.Clear(sf::Color(0,0,0,255));

{...}

light_img.Draw(BloodHit::sprBlood[0]);
    spr_mask.SetBlendMode(sf::Blend::Multiply);
    light_img.Draw(spr_mask);
    light_img.Display();
    spr_inter.SetImage(light_img.GetImage());
    spr_inter.SetBlendMode(sf::Blend::Add);
   
    inter_img.Clear(sf::Color(0,0,0,0));

    //inter_img.Draw(sf::Shape::Rectangle(420, 340, 8, 8, sf::Color::White));
    inter_img.Draw(spr_inter);
    inter_img.Display();


This is why I think the substract blendmode should be added xD, to make masking easier. ( I already read some topics about adding BlendModes)

Thanks

section_two

  • Newbie
  • *
  • Posts: 19
    • View Profile
Masking in SFML 2
« Reply #1 on: August 01, 2011, 09:04:50 pm »
sf::Image Class

void    CreateMaskFromColor (const Color &color, Uint8 alpha=0)
    Create a transparency mask from a specified colorkey.

posva

  • Full Member
  • ***
  • Posts: 118
  • Feed me pls
    • View Profile
    • Posva Dev Blog
Masking in SFML 2
« Reply #2 on: August 02, 2011, 01:02:25 am »
Quote from: "section_two"
sf::Image Class

void    CreateMaskFromColor (const Color &color, Uint8 alpha=0)
    Create a transparency mask from a specified colorkey.


This is for Images ^^ I use RenderImage and i cannot apply that to a const sf:Image. try it ^^

section_two

  • Newbie
  • *
  • Posts: 19
    • View Profile
Masking in SFML 2
« Reply #3 on: August 02, 2011, 05:54:52 am »
sf::Image myImage(myRenderImage.GetImage());

or

myRenderImage.Create(100,50);
const sf::Uint8* ptr = myRenderImage.GetImage().GetPixelsPtr();
sf::Image myImage;
myImage.LoadFromPixels(100,50,ptr);

I did't test this.

posva

  • Full Member
  • ***
  • Posts: 118
  • Feed me pls
    • View Profile
    • Posva Dev Blog
Masking in SFML 2
« Reply #4 on: August 02, 2011, 11:20:35 am »
Quote from: "section_two"
sf::Image myImage(myRenderImage.GetImage());

or

myRenderImage.Create(100,50);
const sf::Uint8* ptr = myRenderImage.GetImage().GetPixelsPtr();
sf::Image myImage;
myImage.LoadFromPixels(100,50,ptr);

I did't test this.


I know these ways, but they are really slow since you're creating a new Image and copying the content of an other image into it. What i do is done even more that 3 times in a step and must be fast enough, this is why i want to use blendmodes