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

Author Topic: sf::View, sf::Style related Screen-Warp  (Read 2243 times)

0 Members and 1 Guest are viewing this topic.

Devero

  • Newbie
  • *
  • Posts: 11
    • View Profile
sf::View, sf::Style related Screen-Warp
« on: December 06, 2011, 07:38:59 pm »
In working on my Asteroids project, I began using sf::Views and sf::Style::Fullscreen.

My monitor's native resolution is 1366 x 768 (16:9), so I was typically using sf::Style::Fullscreen to have the game run fullscreen and this all worked fine; however, as soon as I started using Views it began warping the game.

Ie. all of the planets became egg-shaped (The entire game was stretched across the X axis to fill the monitor)
 
I'm curious how to fix this, either changing the definition of sf::View or changing how the RenderWindow is initialized... Any help would be greatly appreciated.

Here is the related code:
Code: [Select]

//In main.cpp
{
sf::Vector2f Center(5000, 5000);
sf::Vector2f HalfSize(512, 384);
sf::View View(Center, HalfSize);

    sf::RenderWindow App;
    App.Create(sf::VideoMode::GetDesktopMode(0), "Onyx [Alpha]", sf::Style::Fullscreen);
    {
    App.SetView(View);

    if (App.GetInput().IsKeyDown(sf::Key::Add))      View.Zoom(1.1f);
    if (App.GetInput().IsKeyDown(sf::Key::Subtract)) View.Zoom(0.9f);

    View.SetCenter(pl.RenderPlayerX, pl.RenderPlayerY);

        App.SetView(App.GetDefaultView());   //Sets View to be correct for drawing the HUD

        App.Draw(SHealth);
        App.Draw(STempTop);
        App.Draw(HealthText);
        App.Draw(EnergyText);      //Draws the HUD
        App.Draw(FuelText);
        App.Draw(CurrencyText);

    App.SetView(View);
    App.Display();
    }
return EXIT_SUCCESS;
}


Here is a picture of the warped game:

Groogy

  • Hero Member
  • *****
  • Posts: 1469
    • MSN Messenger - groogy@groogy.se
    • View Profile
    • http://www.groogy.se
    • Email
sf::View, sf::Style related Screen-Warp
« Reply #1 on: December 06, 2011, 07:46:29 pm »
The aspect ratio seem to have changed. If you just set the view to what the window is then it should look normal. (Or as long as you keep the same aspect ratio while going down or up in sizes.)
Developer and Maker of rbSFML and Programmer at Paradox Development Studio

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
sf::View, sf::Style related Screen-Warp
« Reply #2 on: December 06, 2011, 08:12:05 pm »
To be more precise, the width of your view should be 683. You'll then have a perfect 2:1 mapping between the view and the window on both axes, and thus no stretch effect.
Laurent Gomila - SFML developer

Devero

  • Newbie
  • *
  • Posts: 11
    • View Profile
sf::View, sf::Style related Screen-Warp
« Reply #3 on: December 06, 2011, 08:32:17 pm »
Awesome, that works great!

Now the only question is, if I want this to work across different computer resolutions, is there a way to manually access the GetDesktopMode X and Y?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
sf::View, sf::Style related Screen-Warp
« Reply #4 on: December 06, 2011, 08:44:33 pm »
Desktop resolution can be retrieved with sf::VideoMode::GetDesktopMode().

But what you need here is rather the size of the window (window.GetWidth(), window.GetHeight()).
Laurent Gomila - SFML developer

Devero

  • Newbie
  • *
  • Posts: 11
    • View Profile
sf::View, sf::Style related Screen-Warp
« Reply #5 on: December 06, 2011, 09:14:38 pm »
Thank you so much!