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

Author Topic: sf::Texture and sf::RenderTexture.getTexture  (Read 5138 times)

0 Members and 1 Guest are viewing this topic.

Mina66

  • Newbie
  • *
  • Posts: 29
    • View Profile
    • Email
sf::Texture and sf::RenderTexture.getTexture
« on: September 13, 2013, 05:14:39 am »
Hello
There is such a code


    sf::Sprite sprite_1;
    sf::Texture texture;
    texture.loadFromFile("d:\\1.png");
    sprite_1.setTexture(texture);

    sf::RenderTexture renderTexture;
    renderTexture.create(96, 96);
    renderTexture.clear(sf::Color(255, 255, 255, 0));
    renderTexture.draw(sprite_1);
    renderTexture.display();

    sf::Sprite sprite_2;
    sprite_2.setTexture(renderTexture.getTexture());
    sprite_2.setPosition(97.f, 0.f);

....

   Window.clear(sf::Color(128, 128, 128));
   Window.draw(sprite_1);
   Window.draw(sprite_2);
   Window.display();

 

Please explain why little difference between pictures. (the shadow)




Sorry for the English.

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: sf::Texture and sf::RenderTexture.getTexture
« Reply #1 on: September 13, 2013, 05:29:06 am »
My guess is the difference in the two clear() commands is the cause.  Try specifying an alpha value in the second one, or simply giving them the exact same color arguments, and see if that makes it obvious what's happening.

Mina66

  • Newbie
  • *
  • Posts: 29
    • View Profile
    • Email
Re: sf::Texture and sf::RenderTexture.getTexture
« Reply #2 on: September 13, 2013, 05:42:29 am »
changed, there is a difference


    renderTexture.clear(sf::Color(128, 128, 128, 0));

....

   Window.clear(sf::Color(128, 128, 128, 0));

 

« Last Edit: September 13, 2013, 05:45:02 am by Mina66 »

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: sf::Texture and sf::RenderTexture.getTexture
« Reply #3 on: September 13, 2013, 06:38:20 am »
Well I have one other guess: try setSmooth with true and false.

If that doesn't work we'll have to hope someone smarter than me shows up.

Siile

  • Newbie
  • *
  • Posts: 15
    • View Profile
    • Email
Re: sf::Texture and sf::RenderTexture.getTexture
« Reply #4 on: September 13, 2013, 07:08:43 am »
Instead of transparent white have you tried using transparent black?

renderTexture.clear(sf::Color(0, 0, 0, 0));

Mina66

  • Newbie
  • *
  • Posts: 29
    • View Profile
    • Email
Re: sf::Texture and sf::RenderTexture.getTexture
« Reply #5 on: September 13, 2013, 07:31:38 am »
Well I have one other guess: try setSmooth with true and false.

If that doesn't work we'll have to hope someone smarter than me shows up.

changed, there is a difference

    renderTexture.setSmooth(true);
    renderTexture.clear(sf::Color(128, 128, 128, 0));

....

   Window.clear(sf::Color(128, 128, 128, 0));

 


Mina66

  • Newbie
  • *
  • Posts: 29
    • View Profile
    • Email
Re: sf::Texture and sf::RenderTexture.getTexture
« Reply #6 on: September 13, 2013, 07:32:59 am »
Instead of transparent white have you tried using transparent black?

renderTexture.clear(sf::Color(0, 0, 0, 0));

changed, there is a difference


    renderTexture.clear(sf::Color(0, 0, 0, 0));

....

   Window.clear(sf::Color(128, 128, 128, 0));

 


Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: sf::Texture and sf::RenderTexture.getTexture
« Reply #7 on: September 13, 2013, 07:37:18 am »
There problem here is that alpha (transparency) is applied twice when you first draw to a render-texture. You can play with clear values, the result will never be the same.

The only way to have the same result is not to apply alpha when you draw to the render-texture:

renderTexture.clear(sf::Color(0, 0, 0, 0));
renderTexture.draw(sprite_1, sf::BlendNone);
renderTexture.display();
Laurent Gomila - SFML developer

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: sf::Texture and sf::RenderTexture.getTexture
« Reply #8 on: September 13, 2013, 07:42:46 am »
Oh wow, that explains so much.

Does RenderWindow do this too?

Mina66

  • Newbie
  • *
  • Posts: 29
    • View Profile
    • Email
Re: sf::Texture and sf::RenderTexture.getTexture
« Reply #9 on: September 13, 2013, 08:05:11 am »
Thanks a lot, Laurent  :)

here is the result


Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: sf::Texture and sf::RenderTexture.getTexture
« Reply #10 on: September 13, 2013, 08:18:21 am »
Quote
Does RenderWindow do this too?
Does it do what?
Laurent Gomila - SFML developer

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: sf::Texture and sf::RenderTexture.getTexture
« Reply #11 on: September 13, 2013, 08:20:48 am »
Apply alpha twice when you first draw to it.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: sf::Texture and sf::RenderTexture.getTexture
« Reply #12 on: September 13, 2013, 08:52:19 am »
Quote
when you first draw to it
... and then draw it to what? RenderWindow is usually the final target ;)

In this case, alpha is applied twice because the sprite is drawn twice: once to the render-texture, and then the render-texture is drawn to the render-window.
Laurent Gomila - SFML developer

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: sf::Texture and sf::RenderTexture.getTexture
« Reply #13 on: September 13, 2013, 09:00:13 am »
Ah, that's what you meant.  Okay, I think I got it now.

 

anything