Welcome
Welcome to the official SFML documentation for C. Here you will find a detailed view of all the SFML 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 in C :
#include <SFML/Audio.h>
#include <SFML/Graphics.h>
int main()
{
sfRenderWindow* window;
sfTexture* texture;
sfSprite* sprite;
sfFont* font;
sfText* text;
sfMusic* music;
window = sfRenderWindow_create(mode, "SFML window", sfResize | sfClose, NULL);
if (!window)
return EXIT_FAILURE;
texture = sfTexture_createFromFile("cute_image.jpg", NULL);
if (!texture)
return EXIT_FAILURE;
sprite = sfSprite_create();
sfSprite_setTexture(sprite, texture, sfTrue);
font = sfFont_createFromFile("arial.ttf");
if (!font)
return EXIT_FAILURE;
text = sfText_create();
sfText_setString(text, "Hello SFML");
sfText_setFont(text, font);
sfText_setCharacterSize(text, 50);
music = sfMusic_createFromFile("nice_music.ogg");
if (!music)
return EXIT_FAILURE;
sfMusic_play(music);
while (sfRenderWindow_isOpen(window))
{
while (sfRenderWindow_pollEvent(window, &event))
{
if (event.
type == sfEvtClosed)
sfRenderWindow_close(window);
}
sfRenderWindow_clear(window, sfBlack);
sfRenderWindow_drawSprite(window, sprite, NULL);
sfRenderWindow_drawText(window, text, NULL);
sfRenderWindow_display(window);
}
sfMusic_destroy(music);
sfText_destroy(text);
sfFont_destroy(font);
sfSprite_destroy(sprite);
sfTexture_destroy(texture);
sfRenderWindow_destroy(window);
return EXIT_SUCCESS;
}