#include <SFML/Graphics.hpp>
#include <cmath>
int main(int, char const**)
{
int screenWidth = 1024;
int screenHeight = 768;
sf::RenderWindow window(sf::VideoMode(screenWidth, screenHeight), "SFML window");
window.setVerticalSyncEnabled(true);
int width = screenWidth/2;
int height = screenHeight/2;
unsigned long size = width * height * 4;
sf::Uint8* pixels = new sf::Uint8[size];
for (int i = 0; i < size; i+=4) {
pixels[i+0] = (i%128)+127;
pixels[i+1] = 255;
pixels[i+2] = 128;
pixels[i+3] = 255;
}
sf::Texture texture;
if (!texture.create(width, height))
{
return EXIT_FAILURE;
}
texture.update(pixels);
sf::Sprite sprite;
sprite.setTexture(texture);
sprite.setOrigin(width/2, height/2);
int angle = 0;
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed) {
window.close();
}
if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape) {
window.close();
}
}
angle++;
if ( angle > 359) {
angle = 0;
}
float rad = angle * 3.141592654f / 180.f;
float cos = std::cos(rad);
float sin = std::sin(rad);
sf::Transform rotationy(cos, 0, sin,
0, 1, 0,
-sin, 0, cos);
window.clear();
window.draw(sprite, rotationy);
window.display();
}
return EXIT_SUCCESS;
}