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

Author Topic: ViewPort not working correctly?  (Read 2396 times)

0 Members and 1 Guest are viewing this topic.

dragondgold

  • Newbie
  • *
  • Posts: 15
    • View Profile
    • Email
ViewPort not working correctly?
« on: May 11, 2013, 07:04:05 pm »
Hello, I am trying to display a full screen image using Views. This is my code:

       sf::RenderWindow mWindow(sf::VideoMode(800,600), "Prueba Animaciones");

        // Cargo la imagen y muestro un pedazo
        sf::Texture mBGTexture;
        sf::Sprite mBGSprite;
        if(!mBGTexture.loadFromFile("bg_big.png")) return EXIT_FAILURE;
        mBGSprite.setTexture(mBGTexture);

        imageWidth = mBGTexture.getSize().x;
        imageHeight = mBGTexture.getSize().y;

        sf::CircleShape mBall;
        mBall.setRadius(10.0);
        mBall.setFillColor(sf::Color::White);

        sf::View miniMap;
        miniMap.setSize(imageWidth, imageHeight);
        miniMap.setViewport(sf::FloatRect(0, 0, 1, 1));

        mWindow.setFramerateLimit(60);

        while(mWindow.isOpen()){
                mWindow.clear();
                mWindow.setView(miniMap);
                mWindow.draw(mBGSprite);
                mWindow.draw(mBall);

                mWindow.display();
        }

The result is this: http://db.tt/14sjmZol. As you can see it is not using the full screen and my image is cutted on right (this is the original image: http://db.tt/5Q6D3uN5). Why this happens? Isn't it suppose to show me the full image on the window ?

gostron

  • Jr. Member
  • **
  • Posts: 53
    • View Profile
Re: ViewPort not working correctly?
« Reply #1 on: May 11, 2013, 07:40:53 pm »
Hi,

First I'm wondering why you type
miniMap.setViewport(sf::FloatRect(0, 0, 1, 1));
since the default behavior of a View is taking all the window. Plus, calling
mWindow.setView(miniMap);
in the main loop is not essential, you can do it once.

My first reflex would have been to call
sf::View::reset()
or directly use the constructor

sf::View miniMap(0, 0, imageWidth, imageHeight);

Hope this helps you.

Vovosunt

  • Jr. Member
  • **
  • Posts: 53
    • View Profile
Re: ViewPort not working correctly?
« Reply #2 on: May 11, 2013, 08:39:13 pm »
What gostron said + the view is in the wrong position as far as I can see.
Add this after you create the view:
miniMap.setCenter(imageWidth/2, imageHeight/2);
or even better intialize the view like this:
sf::View miniMap(mBGTexture.getSize()/2,mBGTexture.getSize())

dragondgold

  • Newbie
  • *
  • Posts: 15
    • View Profile
    • Email
Re: ViewPort not working correctly?
« Reply #3 on: May 13, 2013, 04:21:12 pm »
I feel stupid :P The problem was the position thank you guys!!