Skip to content

Instantly share code, notes, and snippets.

@FRex
Created September 29, 2017 00:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FRex/b04a5de124d2ce82a2a859bc345ae1a1 to your computer and use it in GitHub Desktop.
Save FRex/b04a5de124d2ce82a2a859bc345ae1a1 to your computer and use it in GitHub Desktop.
#include <SFML/Graphics.hpp>
static void loadXorTextureInto(sf::Texture& tex)
{
sf::Image img;
img.create(256u, 256u);
for(unsigned x = 0u; x < img.getSize().x; ++x)
for(unsigned y = 0u; y < img.getSize().y; ++y)
img.setPixel(x, y, sf::Color(x ^ y, x ^ y, x ^ y));
tex.loadFromImage(img);
}
int main(int argc, char ** argv)
{
sf::Texture tex;
loadXorTextureInto(tex);
sf::Sprite spr(tex);
spr.move(sf::Vector2f(150.f, 0.f));
sf::RectangleShape sha;
sha.setSize(sf::Vector2f(100.f, 100.f));
sha.setFillColor(sf::Color::Yellow);
sf::Vertex ver[5u];
sf::RenderWindow app(sf::VideoMode(640u, 480u), "Fullscreen");
while(app.isOpen())
{
sf::Event eve;
while(app.pollEvent(eve))
if(eve.type == sf::Event::Closed)
app.close();
app.clear(sf::Color(0x7f0000ff));
app.draw(ver, 5u, sf::Points, &tex); //one
app.draw(ver, 4u, sf::Points); //two
app.draw(spr); //tri
app.display();
}//while app is open
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment