SFML community forums

Help => Graphics => Topic started by: DasOhmoff San on July 14, 2019, 11:19:42 pm

Title: View does not seem to be working?
Post by: DasOhmoff San on July 14, 2019, 11:19:42 pm
Hello, I am trying to find out how exactly View is working and I cannot seem to figure it out.
I looked at this page: https://www.sfml-dev.org/tutorials/2.5/graphics-view.php

And wrote some test code:
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>

int main()
{
    sf::RenderWindow window(sf::VideoMode(1280, 720), "test");
    sf::Event event;

    sf::View view;
    view.setViewport(sf::FloatRect(0.f, 0.f, 0.5f, 1.f));
    window.setView(view);

    sf::RectangleShape rs; rs.setSize({1280, 720});

    while(window.isOpen())
    {
        while(window.pollEvent(event))
            if(event.type == sf::Event::Closed)
                window.close();

        window.clear();
        window.draw(rs);
        window.display();
    }

    return 0;
}
 

The output:
(https://i.ibb.co/X2n6nXG/grafik.png)

What I expected:
(https://i.ibb.co/d7WsYQR/grafik.png)

Similar to this in the doc:
(https://www.sfml-dev.org/tutorials/2.5/images/graphics-view-split-screen.png)

Can someone please explain what is happening?
Title: Re: View does not seem to be working?
Post by: Hapax on July 15, 2019, 11:17:40 am
What size is the view?
Title: Re: View does not seem to be working?
Post by: DasOhmoff San on July 15, 2019, 12:37:50 pm
Oh, of course, sorry, stupid error.
Thank you!
Title: Re: View does not seem to be working?
Post by: Hapax on July 15, 2019, 09:59:43 pm
You're welcome. :)