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

Author Topic: [SOLVED] sf::Mouse::getPosition(window) return desktop values in specific case  (Read 4558 times)

0 Members and 1 Guest are viewing this topic.

Paul

  • Jr. Member
  • **
  • Posts: 78
    • View Profile
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;
}
« Last Edit: July 07, 2020, 01:30:51 am by Paul »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
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.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Paul

  • Jr. Member
  • **
  • Posts: 78
    • View Profile
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.


eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
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.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Paul

  • Jr. Member
  • **
  • Posts: 78
    • View Profile
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.

 

anything