Hi, here's my code:
#include <SFML/Graphics.hpp>
using namespace std;
const unsigned WINDOW_DEFAULT_WIDTH = 800;
const unsigned WINDOW_DEFAULT_HEIGHT = 600;
int main()
{
sf::Texture tex;
tex.loadFromFile("tex.png");
sf::VertexArray quad1(sf::Quads, 4);
quad1[0].position = sf::Vector2f(150, 110);
quad1[3].position = sf::Vector2f(150, 210);
quad1[0].texCoords = sf::Vector2f(0, 0);
quad1[1].texCoords = sf::Vector2f(255, 0);
quad1[2].texCoords = sf::Vector2f(255, 255);
quad1[3].texCoords = sf::Vector2f(0, 255);
sf::RenderWindow app(sf::VideoMode(WINDOW_DEFAULT_WIDTH, WINDOW_DEFAULT_HEIGHT),
"Qt Creator SFML template");
sf::Clock time;
while(app.isOpen())
{
/* clear screen */
app.clear({20, 20, 20});
/* handle events */
for(sf::Event ev; app.pollEvent(ev);)
{
/* handle close button */
if(ev.type == sf::Event::Closed)
app.close();
}
quad1[1].position = sf::Vector2f(250, 110 - time.getElapsedTime().asSeconds());
quad1[2].position = sf::Vector2f(250, 210 + time.getElapsedTime().asSeconds());
app.draw(quad1, &tex);
/* dipslay frame */
app.display();
}
return 0;
}
The texture that I use:
And what I got after running my code:
Why texture looks like that?