Bonjour,
J'utilise la SFML en C++ dans le cadre d'un projet.
J'ai un problème, quand je set la position de la fenêtre puis get celle-ci, les valeurs du Vector2i ne sont pas les mêmes :
Voici ce que j'effectue :
_window est de type sf::RenderWindow *
_windowPos est de type sf::Vector2i
_window = new sf::RenderWindow(sf::VideoMode(1280, 720), "Void Clash Launcher", sf::Style::None);
if (_window == NULL)
throw std::runtime_error("Unable to instantiate sf::RenderWindow");
_windowPos.x = _videoMode->width / 2 - 1280 / 2;
_windowPos.y = _videoMode->height / 2 - 720 / 2;
std::cout << "Set pos : " << _windowPos.x << "; " << _windowPos.y << std::endl;
_window->setPosition(_windowPos);
std::cout << "Window pos : " << _window->getPosition().x << "; " << _window->getPosition().y << std::endl;
La sortie standart:
Set pos : 320; 180
Window pos : 640; 360
Simple est la question : Pourquoi après avoir set la position de la fenêtre son getter ne retourne pas la valeur correspondante ?
Je suis justement sous linux et utilise sf::Style::None avec ma fenetre.
Voici un code complet minimal comme demandé :
#include <iostream>
#include <stdexcept>
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
int main(void)
{
sf::VideoMode *_videoMode;
sf::RenderWindow *_window;
sf::Vector2i _windowPos;
_videoMode = new sf::VideoMode;
*_videoMode = _videoMode->getDesktopMode();
_window = new sf::RenderWindow(sf::VideoMode(1280, 720), "Void Clash Launcher", sf::Style::None);
_windowPos.x = _videoMode->width / 2 - 1280 / 2;
_windowPos.y = _videoMode->height / 2 - 720 / 2;
_window->setPosition(_windowPos);
std::cout << "Pos set : " << _windowPos.x << "; " << _windowPos.y << std::endl;
std::cout << "Real pos : " << _window->getPosition().x << "; " << _window->getPosition().y << std::endl;
_window->close();
}
Et alors la il y a plusieurs résultats possibles :
Pos set : 320; 180
Real pos : 640; 360
et
Pos set : 320; 180
Real pos : 0; 112
PS: Oui pour le new mauvais reflexe de C avec malloc, merci.