When an ElasticSprite has perspective mode enabled, the texture seems to be offset by some amount, cutting off the right and bottom sides of the image, and even pulling in pixels from beyond the left and top edges. The problem does not occur in bilinear mode.
Furthermore, the degree to which the sprite gets cut off varies depending on the textureRect's position: the farther it is from the texture's top-left corner, the more severe. At offset {0, 0}, there's no cutoff at all. I've included some testing code, and three different images that demonstrate this. (Uncomment the appropriate init code to test each image.)
static bool init = false;
static sw::ElasticSprite sprite;
static bool bilinear = true;
static sf::Texture tex;
if (!init) {
// // No padding
// tex.loadFromFile("/home/hadrosoft/Desktop/test_image.png");
// tex.setSmooth(true);
// sprite.setTexture(tex, true);
// // Small padding
// tex.loadFromFile("/home/hadrosoft/Desktop/test_image_padded_small.png");
// tex.setSmooth(true);
// sprite.setTexture(tex);
// sprite.setTextureRect({220, 177, 508, 508});
// Big padding
tex.loadFromFile("/home/hadrosoft/Desktop/test_image_padded_large.png");
tex.setSmooth(true);
sprite.setTexture(tex);
sprite.setTextureRect({2664, 1956, 508, 508});
sprite.setPosition({100, 100});
sprite.setUseShader(true);
if (bilinear) {
sprite.activateBilinearInterpolation();
}
else {
sprite.activatePerspectiveInterpolation();
}
init = true;
}
static sf::Vector2f vtx[4] = {{0, 0}, {0, 0}, {0, 0}, {0, 0}};
static int vi = 0;
static const float inc = 2.0f;
/* The following keyboard input stuff is just pseudocode for simplicity;
sub in your favorite keyboard handler, or just modify the vertex offsets
in vtx[] manually.
This isn't even strictly necessary, since the bug shows no matter what
the vertex offsets are. */
if (input.key_new_press(" ")) {
++vi;
if (vi == 4) { vi = 0; }
std::cout << "Now modifying vertex #" << vi << std::endl;
}
if (input.key_is_pressed("Up")) {
vtx[vi].y -= inc;
}
else if (input.key_is_pressed("Down")) {
vtx[vi].y += inc;
}
if (input.key_is_pressed("Left")) {
vtx[vi].x -= inc;
}
else if (input.key_is_pressed("Right")) {
vtx[vi].x += inc;
}
if (input.key_new_press("P")) {
bilinear = !bilinear;
if (bilinear) {
sprite.activateBilinearInterpolation();
}
else {
sprite.activatePerspectiveInterpolation();
}
std::cout << "Interpolation: " << ((bilinear) ? "Bilinear" : "Perspective") << std::endl;;
}
for (int x = 0; x < 4; ++x) {
sprite.setVertexOffset(x, {vtx[x].x, vtx[x].y});
}
window.clear(sf::Color(192, 192, 192, 255));
window.draw(sprite);