[英]SFML Texture Transforming (Enlarging)
#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;
}
我要做的是在屏幕大於圖像時將紋理拉伸到屏幕的整個尺寸。 使用setTextureRect我所獲得的全部就是將最后一個像素拉伸到新的大小,這對我要執行的操作來說不是一個好主意,因為圖像調整大小被刪除了,有人知道如何調整圖像大小或變換紋理嗎?大小/尺度?
sf::Sprite::setTextureRect()
定義紋理的一部分,它可以作為精靈顯示。 它沒有定義實際的顯示尺寸。
為此,您可能需要使用sf::Sprite::setScale()
,它允許您定義縮放比例。 例如,調用sprite.setScale(2, 2);
將使顯示的精靈寬度/高度的兩倍。
如果要縮小/放大整個場景,則可能需要查看sf::View
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.