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 <CSFML/Audio.h>
#include <CSFML/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, true);
/* 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:27
const sfColor sfBlack
Black predefined color.
Definition Color.h:46
@ sfEvtClosed
The window requested to be closed (no data)
Definition Event.h:44
void sfFont_destroy(const 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
void sfMusic_destroy(const sfMusic *music)
Destroy a music.
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.
bool sfRenderWindow_pollEvent(sfRenderWindow *renderWindow, sfEvent *event)
Pop the event on top of event queue, if any, and return it.
void sfRenderWindow_display(sfRenderWindow *renderWindow)
Display a render window on screen.
bool sfRenderWindow_isOpen(const sfRenderWindow *renderWindow)
Tell whether or not a render window is opened.
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.
void sfRenderWindow_destroy(const sfRenderWindow *renderWindow)
Destroy an existing render window.
sfRenderWindow * sfRenderWindow_create(sfVideoMode mode, const char *title, uint32_t style, sfWindowState state, const sfContextSettings *settings)
Construct a new render window.
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)
void sfSprite_setTexture(sfSprite *sprite, const sfTexture *texture, bool resetRect)
Change the source texture of a sprite.
void sfSprite_destroy(const sfSprite *sprite)
Destroy an existing sprite.
sfSprite * sfSprite_create(const sfTexture *texture)
Create a new 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.
sfText * sfText_create(const sfFont *font)
Create a new text.
void sfText_setString(sfText *text, const char *string)
Set the string of a text (from an ANSI string)
void sfText_destroy(const sfText *text)
Destroy an existing text.
void sfTexture_destroy(const sfTexture *texture)
Destroy an existing texture.
sfTexture * sfTexture_createFromFile(const char *filename, const sfIntRect *area)
Create a new texture from a file.
@ sfResize
Titlebar + resizable border + maximize button.
Definition WindowBase.h:49
@ sfClose
Titlebar + close button.
Definition WindowBase.h:50
sfVideoMode defines a video mode (width, height, bpp, frequency) and provides functions for getting m...
Definition VideoMode.h:44
sfEvent defines a system event and its parameters
Definition Event.h:210
sfEventType type
Type of the event.
Definition Event.h:211