I tried and failed.
#include <iostream>
#include <SFML\Graphics.hpp>
int main()
{
sf::VideoMode VMode(720, 576, 32);
sf::RenderWindow Window(VMode, "sfml", sf::Style::Close);
//Window.setFramerateLimit(60);
Window.setVerticalSyncEnabled(true);
sf::Texture texture;
texture.loadFromFile("image.png");
sf::Sprite sprite;
sprite.setTexture(texture);
sf::RenderTexture r_texture;
r_texture.create(480, 48);
r_texture.clear(sf::Color(100, 100, 100));
sf::View view;
view.reset(sf::FloatRect(0, 0, 480, 48));
r_texture.setView(view);
r_texture.draw(sprite);
r_texture.display();
sf::Sprite sprite_1;
sprite_1.setTexture(r_texture.getTexture());
while(Window.isOpen())
{
sf::Event Event;
while(Window.pollEvent(Event))
{
switch(Event.type)
{
case sf::Event::Closed:
Window.close();
break;
case sf::Event::KeyPressed:
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))
Window.close();
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Left))
{
view.move(1, 0);
}
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Right))
{
view.move(-1, 0);
}
break;
default:
break;
}
}
Window.clear(sf::Color(128, 128, 128));
Window.draw(sprite_1);
Window.display();
}
return 0;
}