Second version. With using SFML. And it works correctly