SFML community forums

Help => Graphics => Topic started by: overwave on June 08, 2015, 12:09:25 pm

Title: Wrap of a GLScissors
Post by: overwave on June 08, 2015, 12:09:25 pm
In simple GL i had Scissors to change a rectangle for drawing. Which analog exists in SFML?

Scheme is attached.
Title: Re: Wrap of a GLScissors
Post by: Laurent on June 08, 2015, 12:18:25 pm
Until it is implemented properly (https://github.com/SFML/SFML/issues/1), you can fake it with a sf::View whose size and viewport are both set to the clipping area.
Title: Re: Wrap of a GLScissors
Post by: overwave on June 08, 2015, 03:14:03 pm
Maybe I don't understand something, but I don't know hot to do this:


window->draw(sprite);
window->setView(sf::View(sf::FloatRect(posX, posY, wid, hei)));
window->draw(text);
window->setView(sf::View(sf::FloatRect(0, 0, 800, 600)));
Title: Re: Wrap of a GLScissors
Post by: Laurent on June 08, 2015, 03:31:31 pm
You set the view correctly, now you must do the same with its viewport. Have a look at the doc and tutorials if you don't know what I'm talking about ;)
Title: Re: Wrap of a GLScissors
Post by: overwave on June 08, 2015, 05:36:53 pm
But when I initialize sf::View I don't set the Viewport? Also, due to my low english I got documentation not so clear :(
Title: Re: Wrap of a GLScissors
Post by: SpeCter on June 08, 2015, 05:53:48 pm
You only set the View, size and position to be exact.
The viewport is more or less where it is supposed to be on screen.
So you have to call setViewport to do that. Keep in mind that the Viewport coordinates are relative(0-1)
Title: Re: Wrap of a GLScissors
Post by: overwave on June 08, 2015, 07:53:16 pm
      sf::View reduced(sf::FloatRect(posX, posY, wid, hei));
      reduced.setViewport(sf::FloatRect((float)posX / 800.f, (float)posY / 600.f, (float)wid / 800.f, (float)hei / 600.f));


<3

Solved