Loading...
Searching...
No Matches
CSFML

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()
{
sfVideoMode mode = {800, 600, 32};
sfRenderWindow* window;
sfTexture* texture;
sfSprite* sprite;
sfFont* font;
sfText* text;
sfMusic* music;
sfEvent event;
/* Create the main window */
window = sfRenderWindow_create(mode, "SFML window", sfResize | sfClose, NULL);
if (!window)
return EXIT_FAILURE;
/* Load a sprite to display */
texture = sfTexture_createFromFile("cute_image.jpg", NULL);
if (!texture)
return EXIT_FAILURE;
sprite = sfSprite_create();
sfSprite_setTexture(sprite, texture, sfTrue);
/* Create a graphical text to display */
font = sfFont_createFromFile("arial.ttf");
if (!font)
return EXIT_FAILURE;
text = sfText_create();
sfText_setString(text, "Hello SFML");
sfText_setFont(text, font);
/* 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 (sfRenderWindow_isOpen(window))
{
/* Process events */
while (sfRenderWindow_pollEvent(window, &event))
{
/* Close window : exit */
if (event.type == sfEvtClosed)
}
/* Clear the screen */
/* Draw the sprite */
sfRenderWindow_drawSprite(window, sprite, NULL);
/* Draw the text */
sfRenderWindow_drawText(window, text, NULL);
/* Update the window */
}
/* Cleanup resources */
return EXIT_SUCCESS;
}
struct sfMusic sfMusic
Definition Audio/Types.h:29
sfColor sfBlack
Black predefined color.
Definition Color.h:47
#define sfTrue
Definition Config.h:155
@ sfEvtClosed
The window requested to be closed (no data)
Definition Event.h:44
void sfFont_destroy(sfFont *font)
Destroy an existing font.
sfFont * sfFont_createFromFile(const char *filename)
Create a new font from a file.
struct sfRenderWindow sfRenderWindow
struct sfTexture sfTexture
struct sfSprite sfSprite
struct sfText sfText
struct sfFont sfFont
sfMusic * sfMusic_createFromFile(const char *filename)
Create a new music and load it from a file.
void sfMusic_play(sfMusic *music)
Start or resume playing a music.
void sfMusic_destroy(sfMusic *music)
Destroy a music.
sfBool sfRenderWindow_pollEvent(sfRenderWindow *renderWindow, sfEvent *event)
Get the event on top of event queue of a render window, if any, and pop it.
void sfRenderWindow_display(sfRenderWindow *renderWindow)
Display a render window on screen.
void sfRenderWindow_clear(sfRenderWindow *renderWindow, sfColor color)
Clear a render window with the given color.
void sfRenderWindow_drawSprite(sfRenderWindow *renderWindow, const sfSprite *object, const sfRenderStates *states)
Draw a drawable object to the render-target.
sfBool sfRenderWindow_isOpen(const sfRenderWindow *renderWindow)
Tell whether or not a render window is opened.
void sfRenderWindow_drawText(sfRenderWindow *renderWindow, const sfText *object, const sfRenderStates *states)
void sfRenderWindow_close(sfRenderWindow *renderWindow)
Close a render window (but doesn't destroy the internal data)
sfRenderWindow * sfRenderWindow_create(sfVideoMode mode, const char *title, sfUint32 style, const sfContextSettings *settings)
Construct a new render window.
void sfRenderWindow_destroy(sfRenderWindow *renderWindow)
Destroy an existing render window.
void sfSprite_destroy(sfSprite *sprite)
Destroy an existing sprite.
sfSprite * sfSprite_create(void)
Create a new sprite.
void sfSprite_setTexture(sfSprite *sprite, const sfTexture *texture, sfBool resetRect)
Change the source texture of a sprite.
void sfText_setCharacterSize(sfText *text, unsigned int size)
Set the character size of a text.
void sfText_setFont(sfText *text, const sfFont *font)
Set the font of a text.
void sfText_setString(sfText *text, const char *string)
Set the string of a text (from an ANSI string)
sfText * sfText_create(void)
Create a new text.
void sfText_destroy(sfText *text)
Destroy an existing text.
sfTexture * sfTexture_createFromFile(const char *filename, const sfIntRect *area)
Create a new texture from a file.
void sfTexture_destroy(sfTexture *texture)
Destroy an existing texture.
@ sfResize
Titlebar + resizable border + maximize button.
Definition WindowBase.h:48
@ sfClose
Titlebar + close button.
Definition WindowBase.h:49
sfVideoMode defines a video mode (width, height, bpp, frequency) and provides functions for getting m...
Definition VideoMode.h:42
sfEvent defines a system event and its parameters
Definition Event.h:222
sfEventType type
Type of the event.
Definition Event.h:223