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

Author Topic: View does not seem to be working?  (Read 1224 times)

0 Members and 1 Guest are viewing this topic.

DasOhmoff San

  • Guest
View does not seem to be working?
« 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:


What I expected:


Similar to this in the doc:


Can someone please explain what is happening?

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: View does not seem to be working?
« Reply #1 on: July 15, 2019, 11:17:40 am »
What size is the view?
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

DasOhmoff San

  • Guest
Re: View does not seem to be working?
« Reply #2 on: July 15, 2019, 12:37:50 pm »
Oh, of course, sorry, stupid error.
Thank you!

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: View does not seem to be working?
« Reply #3 on: July 15, 2019, 09:59:43 pm »
You're welcome. :)
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*