SFML Documentation

Welcome

Welcome to the official SFML documentation for C. Here you will find a detailed view of all the SFML functions, as well as source files.
If you are looking for tutorials, you can visit the official website at sfml.sourceforge.net.

Short example

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

 #include <SFML/Audio.h>
 #include <SFML/Graphics.h>
 
 int main()
 {
     sfVideoMode Mode = {800, 600, 32};
     sfRenderWindow* App;
     sfImage* Image;
     sfSprite* Sprite;
     sfString* Text;
     sfMusic* Music;
     int Running = 1;
     sfEvent Event;

     /* Create the main window */
     App = sfRenderWindow_Create(Mode, "SFML window");
     if (!App)
         return EXIT_FAILURE;

     /* Load a sprite to display */
     Image = sfImage_CreateFromFile("cute_image.jpg");
     if (!Image)
         return EXIT_FAILURE;
     Sprite = sfSprite_Create();
     sfSprite_SetImage(Sprite, Image);
 
     /* Create a graphical string to display */
     Text = sfString_Create();
     if (!Text)
         return EXIT_FAILURE;
     sfString_SetText(Text, "Hello SFML");
     sfString_SetFont(Text, "arial.ttf");
     sfString_SetSize(Text, 50);
 
     /* Load a music to play */
     Music = sfMusic_CreateFromFile("nice_music.ogg");
     if (!Music)
         return EXIT_FAILURE;

     /* Play the music */
     sfMusic_Play(Music);
 
     /* Start the game loop */
     while (Running)
     {
         /* Process events */
         while (sfRenderWindow_GetEvent(App, &Event))
         {
             /* Close window : exit */
             if (Event.Type == sfEvtClosed)
                 Running = 0;
         }
 
         /* Draw the sprite */
         sfRenderWindow_DrawSprite(App, Sprite);
 
         /* Draw the string */
         sfRenderWindow_DrawString(Text);
 
         /* Update the window */
         sfRenderWindow_Display(App);
     }
 
     /* Cleanup resources */
     sfMusic_Destroy(Music);
     sfString_Destroy(Text);
     sfSprite_Destroy(Sprite);
     sfImage_Destroy(Image);
     sfRenderWindow_Destroy(App);
 
     return EXIT_SUCCESS;
 }