It doesn't work or I do something wrong.
The whole problem is because I'm rendering a physics simulation that have its own coordinates.
And I want to render specified rect of physics simulation to specified rect on window (not on whole window)
// some useful inlines that are missing in SFML
inline Vector2f size(const FloatRect& rect)
{
return Vector2f(rect.width, rect.height);
}
inline Vector2f pos(const FloatRect& rect)
{
return Vector2f(rect.left, rect.top);
}
inline Vector2f localCenter(const FloatRect& rect)
{
return size(rect) * 0.5f;
}
inline Vector2f globalCenter(const FloatRect& rect)
{
return pos(rect) + localCenter(rect);
}
void WorldRender::draw(RenderTarget &target, RenderStates states) const
{
//states.transform *= getTransform(); // i don't need Transformable transform because i use the same transform in view
// vp is source region of simulation
// view set
View oldV = target.getView();
View newV;
newV.setRotation(getRotation());
newV.setSize(size(vp));
newV.setCenter(globalCenter(vp));
newV.setViewport(FloatRect(getPosition(), Vector2f(size(vp).x * getScale().x, size(vp).y * getScale().y)));
target.setView(newV);
// only for example
CircleShape cs(50);
cs.setPosition(0, 0);
cs.setFillColor(Color::Black);
target.draw(cs, states);
//...
target.setView(oldV); // restore old view
}
And in this case NOTHING renders. Even simple circle (cs in my code).
But out of this function everything works properly.