SFML community forums

Help => Graphics => Topic started by: Devero on December 06, 2011, 07:38:59 pm

Title: sf::View, sf::Style related Screen-Warp
Post by: Devero 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:
(https://lh3.googleusercontent.com/-3FooiRW0-Qg/Tt5fsaIfJ-I/AAAAAAAAAG8/joCcSAfONoI/s800/Screenshot%252520at%2525202011-12-04%25252012%25253A53%25253A13.png)
Title: sf::View, sf::Style related Screen-Warp
Post by: Groogy 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.)
Title: sf::View, sf::Style related Screen-Warp
Post by: Laurent 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.
Title: sf::View, sf::Style related Screen-Warp
Post by: Devero 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?
Title: sf::View, sf::Style related Screen-Warp
Post by: Laurent 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()).
Title: sf::View, sf::Style related Screen-Warp
Post by: Devero on December 06, 2011, 09:14:38 pm
Thank you so much!