SFML community forums

Help => Graphics => Topic started by: aVoX on December 13, 2013, 04:07:07 pm

Title: Question about origin (once it's top left, once bottom left)
Post by: aVoX 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:
(http://s18.postimg.org/wapszh7eh/w00t.png)
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.
Title: Re: Question about origin (once it's top left, once bottom left)
Post by: eXpl0it3r 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. ;)
Title: Re: Question about origin (once it's top left, once bottom left)
Post by: aVoX on December 13, 2013, 04:43:08 pm
Thanks eXpl+it3r, my bad (https://www.zoklet.net/images/smilies/others/facepalm.gif)