Files
sfml-example/main.cpp

51 lines
1.0 KiB
C++

#include <SFML/Audio.hpp>
#include <SFML/Graphics.hpp>
int main() {
// Create the main window
auto mode = sf::VideoMode({2048, 2048});
auto window = sf::RenderWindow(mode, "SFML window");
// Load a sprite to display
sf::Texture texture;
if (!texture.loadFromFile("cute_image.jpg")) {
exit(1);
}
sf::Sprite sprite(texture);
// Create a graphical text to display
auto font = sf::Font();
font.loadFromFile("arial.tff");
sf::Text text("Hello SFML", font, 50); // ✅
// Load a music to play
sf::Music music;
music.openFromFile("nice_music.ogg");
// Play the music
music.play();
// Start the game loop
while (window.isOpen()) {
// Process events
sf::Event event;
while (window.pollEvent(event)) {
if (event.type == sf::Event::Closed) {
window.close();
}
// Clear screen
window.clear();
// Draw the sprite
window.draw(sprite);
// Draw the string
window.draw(text);
// Update the window
window.display();
}
}
}