Thanks for your answer. I wrote it too complicated. I need a function to set texture coordinates for any vertices/shape like in any sfml shape.
Here's how i did for rectangle:
int main()
{
sf::Texture texture;
texture.loadFromFile("test.png");
sf::RenderWindow window(sf::VideoMode(900, 800), "Test");
sf::Vertex* a = new sf::Vertex[4];
a[0].position = sf::Vector2f(1, 1);
a[1].position = sf::Vector2f(100, 1);
a[2].position = sf::Vector2f(100, 100);
a[3].position = sf::Vector2f(1, 100);
sf::Vector2u size = texture.getSize();
a[0].texCoords = sf::Vector2f(0, 0);
a[1].texCoords = sf::Vector2f(size.x - 1.0f, 0);
a[2].texCoords = sf::Vector2f(size.x - 1, size.y - 1);
a[3].texCoords = sf::Vector2f(0, size.y - 1.0f);
window.draw(a, 4, sf::PrimitiveType::TrianglesFan, &texture);
window.display();
delete[] a;
while (window.isOpen())
{
}
}
But when i add more vertices and make it convex the texture doesn't display correctly. I understand why it can't work and would like to know how it's done in sfml-shape.