#include <iostream>
#include <SFML/Graphics.hpp>
int main()
{
int desktopwidth = sf::VideoMode::getDesktopMode().width;
int desktopheight = sf::VideoMode::getDesktopMode().height;
sf::ContextSettings settings;settings.antialiasingLevel = 8;
sf::RenderWindow window(sf::VideoMode(desktopwidth, desktopheight), "Texture Transforming!", sf::Style::Fullscreen, settings);
while (window.isOpen())
{
sf::Image image;
if (!(image.loadFromFile("texture.jpg")))
std::cout << "Cannot load image"; //Load Image
sf::Texture texture;
texture.loadFromImage(image); //Load Texture from image
sf::Sprite sprite;
sprite.setTexture(texture);
sprite.setTextureRect({ 0, 0, desktopwidth, desktopheight });
window.clear();
window.draw(sprite);
window.display();
}
return 0;
}
我想做的是当屏幕比图像大时,将纹理拉伸(stretch)到屏幕的全尺寸。使用 setTextureRect 我所取得的一切都是将最后一个像素拉伸(stretch)到新的大小,这对于我正在尝试做的事情来说并不是一个很好的外观,因为图像调整大小已被删除,有没有人知道调整图像大小或转换纹理的工作大小/尺度?
最佳答案
sf::Sprite::setTextureRect()
定义作为 Sprite 可见的纹理部分。它没有定义实际显示尺寸。
为此,您可能需要使用 sf::Sprite::setScale()
,它允许您定义缩放比例。例如,调用 sprite.setScale(2, 2);
将使显示的 Sprite 的宽度/高度增加一倍。
如果您想缩小/放大整个场景,您可能需要查看 sf::View
。
关于c++ - SFML 纹理变换(放大),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52643524/