Untitled

 avatar
unknown
plain_text
6 months ago
945 B
2
Indexable
#include <SFML/Graphics.hpp>

int main() {
    // Create a window
    sf::RenderWindow window(sf::VideoMode(800, 600), "Image Display");

    // Load an image from a file (make sure the image path is correct)
    sf::Texture texture;
    if (!texture.loadFromFile("image.png")) {
        std::cerr << "Error loading image" << std::endl;
        return -1;
    }

    // Create a sprite using the loaded texture
    sf::Sprite sprite(texture);

    // Run the program as long as the window is open
    while (window.isOpen()) {
        // Handle events
        sf::Event event;
        while (window.pollEvent(event)) {
            if (event.type == sf::Event::Closed)
                window.close();
        }

        // Clear the window
        window.clear();

        // Draw the sprite
        window.draw(sprite);

        // Display the window content
        window.display();
    }

    return 0;
}
Editor is loading...
Leave a Comment