Hello everyone! For something I'm doing (giving a sprite perspective by skewing parts of the image), I need to map an image to a vertexArray (specifically the sf::Quad variety). I've read the tutorials, looked at pretty much all the questions that have been answered concerning vertexArrays. But I still don't even remotely understand what numbers I should plug into the vertex's texCoords variable.
For testing purposes, I'm trying to map this image to a square
but it comes out looking like this
my code is as follows
sf::Texture texture;
texture.loadFromFile("boxie.png");
sf::Vector2u size = texture.getSize();
sf::VertexArray lines(sf::Quads, 4);
lines[0].position = sf::Vector2f(0, 0);
lines[1].position = sf::Vector2f(0, 100);
lines[2].position = sf::Vector2f(100, 100);
lines[3].position = sf::Vector2f(100, 0);
lines[0].texCoords = sf::Vector2f(size.x/2,size.y/2);
lines[0].texCoords = sf::Vector2f(size.x/2,size.y);
lines[0].texCoords = sf::Vector2f(size.x,size.y);
lines[0].texCoords = sf::Vector2f(size.x,size.y/2);
I know that this must be something obvious that I'm missing. But I just can't figure out what numbers I should plug in to get the top left corner of the square to be the top left of the image, the bottom left to be the bottom left, etc. Does anyone know what I'm doing wrong? (and have some sort of explanation as to WHY that's the case?
Ultimately, I hope to have the upper-torso from the front,back, and side in a single file, then use the texCoords to select the appropriate part of the image for the direction the entity is moving (and adjust the shape of the quad to give perspective during certain parts of the animation). But I'm just completely stuck when it comes to the texCoords.
Thanks for reading!