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

Author Topic: setViewport squashing textures  (Read 1474 times)

0 Members and 1 Guest are viewing this topic.

Tesseract

  • Newbie
  • *
  • Posts: 2
    • View Profile
setViewport squashing textures
« on: December 19, 2017, 11:14:36 pm »
Hi, so, I'm new to SFML and I am trying to make a shmup, which requires i basically have a game running in one viewport with UI elements around it, sort of like this https://tess.s-ul.eu/Dav4Za2h
but instead, i get this https://tess.s-ul.eu/PLS87rnf

i don't know why the textures get scaled when i resize the view. i am resizing it as follows:

World::World(sf::RenderWindow& window)
: _window(window)
, _game_view(window.getDefaultView())
, _bg_view(window.getDefaultView())
, _game_bounds(0.f, 0.f, _game_view.getSize().x, _game_view.getSize().y) // x, y, width, height
, _spawn_position(_game_view.getSize().x / 2.f, _game_bounds.height - _game_view.getSize().y / 2.f)
, _scroll_speed(-50.f)
, _maiden(nullptr)

{
        load_tex();
        build_scene();

        _game_view.setCenter(_spawn_position);
        _game_view.setViewport(sf::FloatRect(0.35f, 0.02f, 0.35f, 0.96f));
        _window.setView(_game_view);
}

how do i set it so that only a certain area is shown without resizing the textures? thanks a bunch!

Arcade

  • Full Member
  • ***
  • Posts: 230
    • View Profile
Re: setViewport squashing textures
« Reply #1 on: December 20, 2017, 12:02:08 am »
If a view is larger than the viewport, then everything has to get squeezed to a smaller size in order to fit. You are setting your view size to be the same as the default view (the size of the whole screen), but then making the viewport smaller. You need the size of the view and the viewport to match if you don't want any scalling to happen.

Tesseract

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: setViewport squashing textures
« Reply #2 on: December 20, 2017, 12:35:34 am »
thank you very much! i resolved it like this
        float view_x = _window.getDefaultView().getSize().x * 0.40f;
        float view_y = _window.getDefaultView().getSize().y * 0.98f;
        _world_view.setSize(view_x, view_y);
        _world_view.setViewport(sf::FloatRect(0.30f, 0.01f, 0.40f, 0.98f));

 

anything