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 image bottom-right corner image

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

This is my code:

#include "SFML/Graphics.hpp"
#include <stdio.h>
int main(int argc, char **argv){
        sf::RenderWindow window(sf::VideoMode(800, 600), "SFML Application");

        sf::RenderTexture renderTexture;

        int wpoint=10;
        sf::CircleShape point(wpoint,50);
        point.setFillColor(sf::Color(255, 0, 0, 128));

                sf::Event event;
                while (window.pollEvent(event)){
                        if (event.type==sf::Event::MouseMoved && sf::Mouse::isButtonPressed(sf::Mouse::Left)){
                                //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));
                                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
        return 0;

One thing I noticed is when I tried to draw the circle on (10,10) it was painted under the title bar.

I read somewhere that it's probably 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.


Do you have the same problem if you try to draw directly to the RenderWindow (window.draw(point, sf::BlendAlpha)), instead of drawing to a RenderTexture and then to a sprite? Because doing so is essentially doubling the buffer size for the draw unnecessarily. I would recommend you simply draw to the window for performance reasons.

I think the fact you're passing through a RenderTexture could also cause problems if you don't set the sprite's textureRect properly, or don't position the RenderTexture in the window.

Finally, keep in mind that any sf::Shape has its origin set by default to (0, 0). While this doesn't explain how the offset changes depending on where you are, it could be worthwhile, if I understand your goal properly, to set the origin to the center of the circle. You can use point.setOrigin(point.getRadius(), point.getRadius()) to do that.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .