SFML Documentation

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::Font
Class for loading and manipulating character fonts.
Definition: Font.hpp:50
sf::Event
Defines a system event and its parameters.
Definition: Event.hpp:44
sf::Music
Streamed music played from an audio file.
Definition: Music.hpp:48
sf::Texture::loadFromFile
bool loadFromFile(const std::string &filename, const IntRect &area=IntRect())
Load the texture from a file on disk.
sf::Event::Closed
@ Closed
The window requested to be closed (no data)
Definition: Event.hpp:189
sf::Texture
Image living on the graphics card that can be used for drawing.
Definition: Texture.hpp:48
sf::Text
Graphical text that can be drawn to a render target.
Definition: Text.hpp:48
sf::RenderWindow
Window that can serve as a target for 2D drawing.
Definition: RenderWindow.hpp:44
sf::Window::pollEvent
bool pollEvent(Event &event)
Pop the event on top of the event queue, if any, and return it.
sf::RenderTarget::draw
void draw(const Drawable &drawable, const RenderStates &states=RenderStates::Default)
Draw a drawable object to the render target.
sf::Window::isOpen
bool isOpen() const
Tell whether or not the window is open.
sf::RenderTarget::clear
void clear(const Color &color=Color(0, 0, 0, 255))
Clear the entire target with a single color.
sf::Font::loadFromFile
bool loadFromFile(const std::string &filename)
Load the font from a file.
sf::Sprite
Drawable representation of a texture, with its own transformations, color, etc.
Definition: Sprite.hpp:47
sf::Music::openFromFile
bool openFromFile(const std::string &filename)
Open a music from an audio file.
sf::Event::type
EventType type
Type of the event.
Definition: Event.hpp:219
sf::VideoMode
VideoMode defines a video mode (width, height, bpp)
Definition: VideoMode.hpp:41
sf::SoundStream::play
void play()
Start or resume playing the audio stream.
sf::Window::display
void display()
Display on screen what has been rendered to the window so far.
sf::Window::close
void close()
Close the window and destroy all the attached resources.