SFML community forums

Help => Window => Topic started by: Paul on July 06, 2020, 11:26:17 pm

Title: [SOLVED] sf::Mouse::getPosition(window) return desktop values in specific case
Post by: Paul on July 06, 2020, 11:26:17 pm
I have problem with this. On my PC (W10, AMD RX 480) when resolution isn't in supported fullscreen modes and window is fullscreen then sf::Mouse::getPosition(window) return desktop values. If it's windowed it works normally.

For example, when is created window with parameters 1366 x 768 and fullscreen it doesn't work.

Supported video modes:
VideoMode: 1920 1080
VideoMode: 1680 1050
VideoMode: 1600 900
VideoMode: 1280 1024
VideoMode: 1280 720
VideoMode: 1024 768
VideoMode: 800 600
VideoMode: 720 400
VideoMode: 640 480

// Game.h
class Game
{
public:
        sf::RenderWindow window;
};
 


// Game.cpp
Game::Game()
{
        std::vector<sf::VideoMode> supportedVideoModes;
        supportedVideoModes = sf::VideoMode::getFullscreenModes();
        for (auto it : supportedVideoModes)
        {
                std::cout << "VideoMode: " << it.width << " " << it.height << std::endl;
        }

        window.create(sf::VideoMode(1366, 768), "SFML", true ? sf::Style::Fullscreen : sf::Style::Close);
}


Game::Update()
{
        std::cout << sf::Mouse::getPosition(window).x << ", " << sf::Mouse::getPosition(window).y << std::endl;
}
Title: Re: sf::Mouse::getPosition(window) return desktop values in specific case
Post by: eXpl0it3r on July 06, 2020, 11:42:12 pm
And why are you trying to use a fullscreen mode that's no supported by your system?
The system is probably just picking the closest fitting supported screen size, but it might be that SFML doesn't register it.
Either way, you should only use valid fullscreen modes.
Title: Re: sf::Mouse::getPosition(window) return desktop values in specific case
Post by: Paul on July 06, 2020, 11:59:42 pm
Because games normally offer full range of resolutions supported by graphics card and monitor in fullscreen mode, not only those supported by the system. Not all applications are running only in some borderless window if they can't run native fullscreen. Plus I wanted debug more scenarios.

I can stay with native or add support for borderless, but it's bit weird.

Title: Re: sf::Mouse::getPosition(window) return desktop values in specific case
Post by: eXpl0it3r on July 07, 2020, 12:07:32 am
So are you saying that you can change your resolution of Windows 10 to use 1366 x 768?

Not all applications are running only in some borderless window if they can't run native fullscreen.
SFML doesn't handle borderless window mode in fullscreen mode.
If you request fullscreen mode, you get fullscreen mode. If you want a borderless window you'll have to create the window with sf::Style::None and ensure the correct scaling/letterboxing yourself.
Title: Re: sf::Mouse::getPosition(window) return desktop values in specific case
Post by: Paul on July 07, 2020, 01:29:24 am
With current system and gpu drivers I can't.

Ok, thanks.

I get it most likely, what I can do is create static sf::View with given resolution like 1366 x 768 and use window.mapPixelToCoords to recalculate sf::Mouse::getPosition() otherwise it will return values tied to window size, which will be bigger in case of fullscreen.