-
-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
76c1e64
commit 4221950
Showing
3 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
add_executable(example example.c) | ||
target_link_libraries(example PRIVATE csfml-graphics csfml-audio) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#include <SFML/Audio.h> | ||
#include <SFML/Graphics.h> | ||
|
||
#include <stdlib.h> | ||
|
||
int main() | ||
{ | ||
/* Create the main window */ | ||
sfVideoMode mode = {800, 600, 32}; | ||
sfRenderWindow* window = sfRenderWindow_create(mode, "SFML window", sfResize | sfClose, NULL); | ||
if (!window) | ||
return EXIT_FAILURE; | ||
|
||
/* Load a sprite to display */ | ||
sfTexture* texture = sfTexture_createFromFile("cute_image.jpg", NULL); | ||
if (!texture) | ||
return EXIT_FAILURE; | ||
sfSprite* sprite = sfSprite_create(); | ||
sfSprite_setTexture(sprite, texture, sfTrue); | ||
|
||
/* Create a graphical text to display */ | ||
sfFont* font = sfFont_createFromFile("arial.ttf"); | ||
if (!font) | ||
return EXIT_FAILURE; | ||
sfText* text = sfText_create(); | ||
sfText_setString(text, "Hello SFML"); | ||
sfText_setFont(text, font); | ||
sfText_setCharacterSize(text, 50); | ||
|
||
/* Load a music to play */ | ||
sfMusic* music = sfMusic_createFromFile("nice_music.ogg"); | ||
if (!music) | ||
return EXIT_FAILURE; | ||
|
||
/* Play the music */ | ||
sfMusic_play(music); | ||
|
||
/* Start the game loop */ | ||
sfEvent event; | ||
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; | ||
} |