I am not sure but I think it's a problem with windows 10 borderless windows
The problem is when I draw the circle its always drawn with a little offset from where it should be.
top-left corner
bottom-right corner
In the top of the window the shape is drawn above the mouse, in the bottom the shape is drawn under the mouse and so for each side of the window
#include "SFML/Graphics.hpp"
#include <stdio.h>
int main(int argc, char **argv){
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML Application");
window.setFramerateLimit(60);
sf::RenderTexture renderTexture;
renderTexture.create(800,600);
renderTexture.setSmooth(true);
renderTexture.clear(sf::Color(255,255,255,255));
renderTexture.display();
int wpoint=10;
sf::CircleShape point(wpoint,50);
point.setFillColor(sf::Color(255, 0, 0, 128));
while(1){
sf::Event event;
while (window.pollEvent(event)){
if (event.type==sf::Event::MouseMoved && sf::Mouse::isButtonPressed(sf::Mouse::Left)){
//printf("%d\n",sf::Mouse::isButtonPressed(sf::Mouse::Left));
//point.setPosition(event.mouseMove.x-(wpoint/2),event.mouseMove.y-(wpoint/2));
//point.setPosition(event.mouseMove.x,event.mouseMove.y);
//auto pos=sf::Mouse::getPosition();
auto poswindow=window.getPosition();
printf("%d,%d\n",poswindow.x,poswindow.y); //This prints -8,0 when I position the window on the left-top corner (0,0)!!
//auto pos=sf::Mouse::getPosition(window);
auto pos=window.mapPixelToCoords(sf::Mouse::getPosition(window));
point.setPosition(pos.x,pos.y);
renderTexture.draw(point, sf::BlendAlpha);
}
if (event.type==sf::Event::Closed
|| event.type==sf::Event::KeyPressed && event.key.code==sf::Keyboard::Escape)
return 0;
}
sf::Sprite canvas(renderTexture.getTexture());
// draw
window.clear();
window.draw(canvas);
window.display();
}
return 0;
}
It doesn't matter, I read somewhere that it's a thing that only happens with some Intel drivers, I just hope that the users don't have it or I will be in troubles. It's weird because I have been working with the Winapi for a long time and the mouse coordinates have always been correct.
If this is something that affects a lot of people one solution might be to add an empty window filling the ClientRect and adding the context to it, am I right?