gpt-3.5-turbo-0301· openai
Suzhen/CodeChat
donne un exemple de soquet en sfml?
- User
donne un exemple de soquet en sfml?
- Assistant
Voici un exemple de soquet en SFML qui crée une fenêtre, définit un fond d'écran bleu et ajoute un texte blanc centré :
#include <SFML/Graphics.hpp> int main() { sf::RenderWindow window(sf::VideoMode(800, 600), "My Soquet"); // Créer un rectangle pour le fond d'écran sf::RectangleShape bg(sf::Vector2f(800, 600)); bg.setFillColor(sf::Color::Blue); // Créer un texte centré à l'écran sf::Font font; font.loadFromFile("arial.ttf"); // Charger la police de caractères sf::Text text("Hello, world!", font, 36); text.setFillColor(sf::Color::White); text.setPosition(window.getSize().x / 2 - text.getLocalBounds().width / 2, window.getSize().y / 2 - text.getLocalBounds().height / 2); // Boucle principale while (window.isOpen()) { sf::Event event; while (window.pollEvent(event)) { if (event.type == sf::Event::Closed) window.close(); } // Actualiser la fenêtre window.clear(); window.draw(bg); window.draw(text); window.display(); } return 0; }