Some texture packers rotate images 90 degrees clockwise or counter-clockwise for efficient packing. When loading textures, the OpenGL code would look something like this:
GLfloat coords[4][2];
if (info->r90) {
coords[0][0] = (info->x + info->width) / textureWidth;
coords[0][1] = info->y / textureHeight;
coords[1][0] = info->x / textureWidth;
coords[1][1] = info->y / textureHeight;
coords[2][0] = (info->x + info->width) / textureWidth;
coords[2][1] = (info->y + info->height) / textureHeight;
coords[3][0] = info->x / textureWidth;
coords[3][1] = (info->y + info->height) / textureHeight;
} else {
coords[0][0] = info->x / textureWidth;
coords[0][1] = info->y / textureHeight;
coords[1][0] = info->x / textureWidth;
coords[1][1] = (info->y + info->height) / textureHeight;
coords[2][0] = (info->x + info->width) / textureWidth;
coords[2][1] = info->y / textureHeight;
coords[3][0] = (info->x + info->width) / textureWidth;
coords[3][1] = (info->y + info->height) / textureHeight;
}
glBindBuffer(GL_ARRAY_BUFFER, info->texCoordBuffer);
glBufferData(GL_ARRAY_BUFFER, 4 * 2 * sizeof(GLfloat), coords, GL_STATIC_DRAW);
glEnableVertexAttribArray(spritesheet.attribTexCoord);
glVertexAttribPointer(spritesheet.attribTexCoord, 2, GL_FLOAT, GL_FALSE, 0, NULL);
With SFML, I want to do something like this:
sf::Sprite sprite;
sprite.setTexture(spritesheet);
sprite.setTextureRect(sf::IntRect(info->x, info->y, info->width, info->height), info->r90 ? sf::Clockwise90 : sf::NoRotation);
So SFML would check the second parameter which might inform it to set slightly different UV coords taking into account this rotation.
Alternate API could be
sprite.setTextureRectRotation(sf::Clockwise90)
.
Another alternative would simply be making updateTexCoords public instead of private.
I looked into SFML's code and it looks very clean and understandable. I would be happy to implement this feature. What I want to know is, are you interested in this feature? Should I make a pull request?