CSFML 3.0.0
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);
sfText_setCharacterSize(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 (sfRenderWindow_isOpen(window))
{
/* Process events */
while (sfRenderWindow_pollEvent(window, &event))
{
/* Close window : exit */
if (event.type == sfEvtClosed)
sfRenderWindow_close(window);
}
/* Clear the screen */
sfRenderWindow_clear(window, sfBlack);
/* Draw the sprite */
sfRenderWindow_drawSprite(window, sprite, NULL);
/* Draw the text */
sfRenderWindow_drawText(window, text, NULL);
/* Update the window */
sfRenderWindow_display(window);
}
/* Cleanup resources */
sfMusic_destroy(music);
sfText_destroy(text);
sfFont_destroy(font);
sfSprite_destroy(sprite);
sfTexture_destroy(texture);
sfRenderWindow_destroy(window);
return EXIT_SUCCESS;
}
sfMusic
struct sfMusic sfMusic
Definition Audio/Types.h:27
Audio.h
sfBlack
const sfColor sfBlack
Black predefined color.
Definition Color.h:46
sfEvtClosed
@ sfEvtClosed
The window requested to be closed (no data).
Definition Event.h:44
sfFont_destroy
void sfFont_destroy(const sfFont *font)
Destroy an existing font.
sfFont_createFromFile
sfFont * sfFont_createFromFile(const char *filename)
Create a new font from a file.
sfRenderWindow
struct sfRenderWindow sfRenderWindow
Definition Graphics/Types.h:35
sfTexture
struct sfTexture sfTexture
Definition Graphics/Types.h:39
sfSprite
struct sfSprite sfSprite
Definition Graphics/Types.h:37
sfText
struct sfText sfText
Definition Graphics/Types.h:38
sfFont
struct sfFont sfFont
Definition Graphics/Types.h:30
Graphics.h
sfMusic_destroy
void sfMusic_destroy(const sfMusic *music)
Destroy a music.
sfMusic_createFromFile
sfMusic * sfMusic_createFromFile(const char *filename)
Create a new music and load it from a file.
sfMusic_play
void sfMusic_play(sfMusic *music)
Start or resume playing a music.
sfRenderWindow_pollEvent
bool sfRenderWindow_pollEvent(sfRenderWindow *renderWindow, sfEvent *event)
Pop the event on top of event queue, if any, and return it.
sfRenderWindow_display
void sfRenderWindow_display(sfRenderWindow *renderWindow)
Display a render window on screen.
sfRenderWindow_isOpen
bool sfRenderWindow_isOpen(const sfRenderWindow *renderWindow)
Tell whether or not a render window is opened.
sfRenderWindow_clear
void sfRenderWindow_clear(sfRenderWindow *renderWindow, sfColor color)
Clear a render window with the given color.
sfRenderWindow_drawSprite
void sfRenderWindow_drawSprite(sfRenderWindow *renderWindow, const sfSprite *object, const sfRenderStates *states)
Draw a drawable object to the render-target.
sfRenderWindow_destroy
void sfRenderWindow_destroy(const sfRenderWindow *renderWindow)
Destroy an existing render window.
sfRenderWindow_create
sfRenderWindow * sfRenderWindow_create(sfVideoMode mode, const char *title, uint32_t style, sfWindowState state, const sfContextSettings *settings)
Construct a new render window.
sfRenderWindow_drawText
void sfRenderWindow_drawText(sfRenderWindow *renderWindow, const sfText *object, const sfRenderStates *states)
sfRenderWindow_close
void sfRenderWindow_close(sfRenderWindow *renderWindow)
Close a render window (but doesn't destroy the internal data).
sfSprite_setTexture
void sfSprite_setTexture(sfSprite *sprite, const sfTexture *texture, bool resetRect)
Change the source texture of a sprite.
sfSprite_destroy
void sfSprite_destroy(const sfSprite *sprite)
Destroy an existing sprite.
sfSprite_create
sfSprite * sfSprite_create(const sfTexture *texture)
Create a new sprite.
sfText_setCharacterSize
void sfText_setCharacterSize(sfText *text, unsigned int size)
Set the character size of a text.
sfText_setFont
void sfText_setFont(sfText *text, const sfFont *font)
Set the font of a text.
sfText_create
sfText * sfText_create(const sfFont *font)
Create a new text.
sfText_setString
void sfText_setString(sfText *text, const char *string)
Set the string of a text (from an ANSI string).
sfText_destroy
void sfText_destroy(const sfText *text)
Destroy an existing text.
sfTexture_destroy
void sfTexture_destroy(const sfTexture *texture)
Destroy an existing texture.
sfTexture_createFromFile
sfTexture * sfTexture_createFromFile(const char *filename, const sfIntRect *area)
Create a new texture from a file.
sfResize
@ sfResize
Titlebar + resizable border + maximize button.
Definition WindowBase.h:49
sfClose
@ sfClose
Titlebar + close button.
Definition WindowBase.h:50
sfVideoMode
sfVideoMode defines a video mode (width, height, bpp, frequency) and provides functions for getting m...
Definition VideoMode.h:44
sfEvent
sfEvent defines a system event and its parameters
Definition Event.h:210
sfEvent::type
sfEventType type
Type of the event.
Definition Event.h:211