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

Author Topic: Question about origin (once it's top left, once bottom left)  (Read 1639 times)

0 Members and 1 Guest are viewing this topic.

aVoX

  • Newbie
  • *
  • Posts: 2
    • View Profile
Question about origin (once it's top left, once bottom left)
« on: December 13, 2013, 04:07:07 pm »
Hello everybody!

My situation is as follows: I have 2 different RenderTextures. A circle is drawn onto texture A at the coordinates 100, 100. Then I draw texture A onto texture B using BlendMultiply. After doing that, I draw a rectangle onto texture B at the coordinates 100, 100. Finally, I render the resulting texture to a RenderWindow.
The code slightly looks like this (note that "stencil" is what I called texture A, and "frame" is texture B):
    sf::CircleShape circle( 10 );
    circle.setPosition( 100.0f, 100.0f );
    circle.setFillColor( sf::Color::White );

    sf::RenderTexture stencil;
    stencil.create( 1024, 768 );
    stencil.clear( sf::Color( sf::Color::Black ) );

    stencil.draw( circle );

    sf::RenderTexture frame;
    frame.create( 1024, 768 );
    frame.clear( sf::Color( 0, 128, 128 ) );

    frame.draw( sf::Sprite( stencil.getTexture() ), sf::RenderStates( sf::BlendMultiply ) );

    sf::RectangleShape rect( sf::Vector2f(20, 20) );
    rect.setPosition( 100.0f, 100.0f );
    rect.setFillColor( sf::Color::Green );

    frame.draw( rect, sf::RenderStates( sf::BlendAdd ) );

    renderWindow.draw( sf::Sprite( frame.getTexture() ) );
    renderWindow.display();
 

The circle is where expected - at the coordinates 100, 100 from the top left corner, but for some reason, the rectangle ends up at 100, 100 from the bottom left corner.
Here is the result:

I'd expect both primitives to overlap each other, since SFML's default origin is always located at 0, 0 and I never call a setOrigin function in my actual code.
Is this desired behavior? Is there any other way than doing a negative scaling, in order to line up texture B's origin to 0, 0?

Thanks in advance,
aVoX.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Question about origin (once it's top left, once bottom left)
« Reply #1 on: December 13, 2013, 04:29:46 pm »
Read the tutorial and documentation again. A render texture works like a window, you'll always have to call display after you've drawn the scene. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

aVoX

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Question about origin (once it's top left, once bottom left)
« Reply #2 on: December 13, 2013, 04:43:08 pm »
Thanks eXpl+it3r, my bad