CSFML - C binding of the Simple and Fast Multimedia Library

CSFML 2.6.1

- Main Page
- Related Pages
- Classes
- Files

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);
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:29
Audio.h
sfBlack
sfColor sfBlack
Black predefined color.
Definition Color.h:47
sfTrue
#define sfTrue
Definition Config.h:155
sfEvtClosed
@ sfEvtClosed
The window requested to be closed (no data)
Definition Event.h:44
sfFont_destroy
void sfFont_destroy(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:36
sfTexture
struct sfTexture sfTexture
Definition Graphics/Types.h:40
sfSprite
struct sfSprite sfSprite
Definition Graphics/Types.h:38
sfText
struct sfText sfText
Definition Graphics/Types.h:39
sfFont
struct sfFont sfFont
Definition Graphics/Types.h:31
Graphics.h
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.
sfMusic_destroy
void sfMusic_destroy(sfMusic *music)
Destroy a music.
sfRenderWindow_pollEvent
sfBool sfRenderWindow_pollEvent(sfRenderWindow *renderWindow, sfEvent *event)
Get the event on top of event queue of a render window, if any, and pop it.
sfRenderWindow_display
void sfRenderWindow_display(sfRenderWindow *renderWindow)
Display a render window on screen.
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_isOpen
sfBool sfRenderWindow_isOpen(const sfRenderWindow *renderWindow)
Tell whether or not a render window is opened.
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)
sfRenderWindow_create
sfRenderWindow * sfRenderWindow_create(sfVideoMode mode, const char *title, sfUint32 style, const sfContextSettings *settings)
Construct a new render window.
sfRenderWindow_destroy
void sfRenderWindow_destroy(sfRenderWindow *renderWindow)
Destroy an existing render window.
sfSprite_destroy
void sfSprite_destroy(sfSprite *sprite)
Destroy an existing sprite.
sfSprite_create
sfSprite * sfSprite_create(void)
Create a new sprite.
sfSprite_setTexture
void sfSprite_setTexture(sfSprite *sprite, const sfTexture *texture, sfBool resetRect)
Change the source texture of a 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_setString
void sfText_setString(sfText *text, const char *string)
Set the string of a text (from an ANSI string)
sfText_create
sfText * sfText_create(void)
Create a new text.
sfText_destroy
void sfText_destroy(sfText *text)
Destroy an existing text.
sfTexture_createFromFile
sfTexture * sfTexture_createFromFile(const char *filename, const sfIntRect *area)
Create a new texture from a file.
sfTexture_destroy
void sfTexture_destroy(sfTexture *texture)
Destroy an existing texture.
sfResize
@ sfResize
Titlebar + resizable border + maximize button.
Definition WindowBase.h:48
sfClose
@ sfClose
Titlebar + close button.
Definition WindowBase.h:49
sfVideoMode
sfVideoMode defines a video mode (width, height, bpp, frequency) and provides functions for getting m...
Definition VideoMode.h:42
sfEvent
sfEvent defines a system event and its parameters
Definition Event.h:222
sfEvent::type
sfEventType type
Type of the event.
Definition Event.h:223