[英]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;
}
What I want to do is stretch the texture to the full size of the screen when the screen is bigger than the image. 我要做的是在屏幕大于图像时将纹理拉伸到屏幕的整个尺寸。 Using setTextureRect all I have achieved is stretching out the last pixel to the new size which isn't a great look for what i am trying to do, as image resize was removed, does anyone know of a work around to resize images or transform texture size/scales?
使用setTextureRect我所获得的全部就是将最后一个像素拉伸到新的大小,这对我要执行的操作来说不是一个好主意,因为图像调整大小被删除了,有人知道如何调整图像大小或变换纹理吗?大小/尺度?
sf::Sprite::setTextureRect()
defines the part of the texture that's visible as the sprite. sf::Sprite::setTextureRect()
定义纹理的一部分,它可以作为精灵显示。 It doesn't define the actual display size. 它没有定义实际的显示尺寸。
For this purpose you might want to use sf::Sprite::setScale()
, which allows you to define a scaling ratio. 为此,您可能需要使用
sf::Sprite::setScale()
,它允许您定义缩放比例。 For example, calling sprite.setScale(2, 2);
例如,调用
sprite.setScale(2, 2);
will make the displayed sprite twice as wide/high. 将使显示的精灵宽度/高度的两倍。
If you want to downscale/upscale your whole scene, you might want looking into sf::View
though. 如果要缩小/放大整个场景,则可能需要查看
sf::View
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.