SFML Documentation
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
www.sfml-dev.org.
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()
{
sfWindowSettings Settings = {24, 8, 0};
sfVideoMode Mode = {800, 600, 32};
sfRenderWindow* App;
sfImage* Image;
sfSprite* Sprite;
sfFont* Font;
sfString* Text;
sfMusic* Music;
sfEvent Event;
App = sfRenderWindow_Create(Mode, "SFML window", sfResize | sfClose, Settings);
if (!App)
return EXIT_FAILURE;
Image = sfImage_CreateFromFile("cute_image.jpg");
if (!Image)
return EXIT_FAILURE;
Sprite = sfSprite_Create();
sfSprite_SetImage(Sprite, Image);
Font = sfFont_CreateFromFile("arial.ttf", 50, NULL);
if (!Font)
return EXIT_FAILURE;
Text = sfString_Create();
sfString_SetText(Text, "Hello SFML");
sfString_SetFont(Text, Font);
sfString_SetSize(Text, 50);
Music = sfMusic_CreateFromFile("nice_music.ogg");
if (!Music)
return EXIT_FAILURE;
sfMusic_Play(Music);
while (sfRenderWindow_IsOpened(App))
{
while (sfRenderWindow_GetEvent(App, &Event))
{
if (Event.Type == sfEvtClosed)
sfRenderWindow_Close(App);
}
sfRenderWindow_Clear(App, sfBlack);
sfRenderWindow_DrawSprite(App, Sprite);
sfRenderWindow_DrawString(App, Text);
sfRenderWindow_Display(App);
}
sfMusic_Destroy(Music);
sfString_Destroy(Text);
sfFont_Destroy(Font);
sfSprite_Destroy(Sprite);
sfImage_Destroy(Image);
sfRenderWindow_Destroy(App);
return EXIT_SUCCESS;
}