SFML 2.5.1

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

SFML

# Welcome

Welcome to the official SFML documentation. Here you will find a detailed view of all the SFML classes and functions.
If you are looking for tutorials, you can visit the official website at www.sfml-dev.org.

# Short example

Here is a short example, to show you how simple it is to use SFML:

#include <SFML/Audio.hpp>
#include <SFML/Graphics.hpp>
int main()
{
// Create the main window
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");
// Load a sprite to display
sf::Texture texture;
if (!texture.loadFromFile("cute_image.jpg"))
return EXIT_FAILURE;
sf::Sprite sprite(texture);
// Create a graphical text to display
sf::Font font;
if (!font.loadFromFile("arial.ttf"))
return EXIT_FAILURE;
sf::Text text("Hello SFML", font, 50);
// Load a music to play
sf::Music music;
if (!music.openFromFile("nice_music.ogg"))
return EXIT_FAILURE;
// Play the music
music.play();
// Start the game loop
while (window.isOpen())
{
// Process events
sf::Event event;
while (window.pollEvent(event))
{
// Close window: exit
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();
}
return EXIT_SUCCESS;
}
sf::Event
Defines a system event and its parameters.
Definition: Event.hpp:45
sf::Event::type
EventType type
Type of the event.
Definition: Event.hpp:219
sf::Event::Closed
@ Closed
The window requested to be closed (no data)
Definition: Event.hpp:189
sf::Font
Class for loading and manipulating character fonts.
Definition: Font.hpp:51
sf::Font::loadFromFile
bool loadFromFile(const std::string &filename)
Load the font from a file.
sf::Music
Streamed music played from an audio file.
Definition: Music.hpp:49
sf::Music::openFromFile
bool openFromFile(const std::string &filename)
Open a music from an audio file.
sf::RenderWindow
Window that can serve as a target for 2D drawing.
Definition: RenderWindow.hpp:45
sf::SoundStream::play
void play()
Start or resume playing the audio stream.
sf::Sprite
Drawable representation of a texture, with its own transformations, color, etc.
Definition: Sprite.hpp:48
sf::Text
Graphical text that can be drawn to a render target.
Definition: Text.hpp:49
sf::Texture
Image living on the graphics card that can be used for drawing.
Definition: Texture.hpp:49
sf::Texture::loadFromFile
bool loadFromFile(const std::string &filename, const IntRect &area=IntRect())
Load the texture from a file on disk.
sf::VideoMode
VideoMode defines a video mode (width, height, bpp)
Definition: VideoMode.hpp:42