SFML community forums

Help => General => Topic started by: rogeriodec on April 24, 2018, 09:41:52 pm

Title: Views vs window confusion
Post by: rogeriodec on April 24, 2018, 09:41:52 pm
I have this single code...

#include <SFML/Graphics.hpp>

#define windowWidth  600
#define windowHeight 300

int main()
{
   sf::RenderWindow window(sf::VideoMode(windowWidth, windowHeight), "SFML Views");

   sf::View view(sf::FloatRect(0,0, windowWidth, windowHeight));
   view.zoom(2);
   window.setView(view);


   sf::RectangleShape back (sf::Vector2f(windowWidth, windowHeight));
   back.setFillColor(sf::Color::White);

   sf::RectangleShape rect (sf::Vector2f(200, 100));
   rect.setFillColor(sf::Color::Red);
   rect.setPosition(windowWidth - rect.getSize().x, windowHeight - rect.getSize().y); // position in the lower right corner

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

        window.clear();
        window.draw(back);
        window.draw(rect);
        window.display();
    }

    return 0;
}


...which might position the red rectangle in the lower right corner of the window.

(https://i.imgur.com/8KJV64q.jpg)

However, when I zoom the view in (as in the code), it obviously moves along with the entire window.
I have some doubts:

   
Title: Re: Views vs window confusion
Post by: eXpl0it3r on April 24, 2018, 11:02:24 pm
So what's your final goal?

Did you read and understand the view tutorial (https://www.sfml-dev.org/tutorials/2.4/graphics-view.php)?
Title: Re: Views vs window confusion
Post by: rogeriodec on April 25, 2018, 08:51:56 pm
Yes, I read. But since I'm a beginner in sfml, I still have not got the whole logic of the thing. And not always this tutorial is so understandable for beginners.
I've also watched several tutorial videos on youtube that are expanding my understanding of sfml.
But sometimes a simple, but less laconic answer can help.
In any case, I had the opportunity to have this support in StackOverflow and now I know how to solve it.  8)