Skip to content

Instantly share code, notes, and snippets.

@def-
Created February 19, 2015 10:05
Show Gist options
  • Star 15 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save def-/fee8bb041719337c8812 to your computer and use it in GitHub Desktop.
Save def-/fee8bb041719337c8812 to your computer and use it in GitHub Desktop.
CSFML example
#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 1;
/* Load a sprite to display */
texture = sfTexture_createFromFile("cute_image.jpg", NULL);
if (!texture)
return 1;
sprite = sfSprite_create();
sfSprite_setTexture(sprite, texture, sfTrue);
/* Create a graphical text to display */
font = sfFont_createFromFile("arial.ttf");
if (!font)
return 1;
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 1;
/* 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 0;
}
@codeurH24
Copy link

sfMusic_createFromFile run failled ?

@codeurH24
Copy link

https://www.noelshack.com/2018-10-1-1520257905-capture.png.
If i run the source, sfMusic_createFromFile crash the program

@codeurH24
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment