diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 74215a15..e57188f9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -51,7 +51,7 @@ jobs: - name: Configure CSFML CMake shell: bash - run: cmake -S $GITHUB_WORKSPACE/CSFML -B $GITHUB_WORKSPACE/CSFML/build -DCMAKE_INSTALL_PREFIX=$GITHUB_WORKSPACE/CSFML/install -DBUILD_SHARED_LIBS=TRUE -DCSFML_LINK_SFML_STATICALLY=FALSE -DSFML_DIR=$GITHUB_WORKSPACE/SFML/install/lib/cmake/SFML -DCMAKE_VERBOSE_MAKEFILE=ON -DWARNINGS_AS_ERRORS=TRUE ${{matrix.platform.flags}} + run: cmake -S $GITHUB_WORKSPACE/CSFML -B $GITHUB_WORKSPACE/CSFML/build -DCMAKE_INSTALL_PREFIX=$GITHUB_WORKSPACE/CSFML/install -DBUILD_SHARED_LIBS=TRUE -DCSFML_BUILD_EXAMPLES=TRUE -DCSFML_LINK_SFML_STATICALLY=FALSE -DSFML_DIR=$GITHUB_WORKSPACE/SFML/install/lib/cmake/SFML -DCMAKE_VERBOSE_MAKEFILE=ON -DWARNINGS_AS_ERRORS=TRUE ${{matrix.platform.flags}} - name: Build CSFML shell: bash diff --git a/CMakeLists.txt b/CMakeLists.txt index dcd5f133..58d5763f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -87,3 +87,9 @@ install(DIRECTORY include PATTERN ".svn" EXCLUDE) install(FILES license.md DESTINATION ${INSTALL_MISC_DIR}) install(FILES readme.md DESTINATION ${INSTALL_MISC_DIR}) + +# add an option for building the examples +csfml_set_option(CSFML_BUILD_EXAMPLES FALSE BOOL "TRUE to build the CSFML examples, FALSE to ignore them") +if(CSFML_BUILD_EXAMPLES) + add_subdirectory(examples) +endif() diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt new file mode 100644 index 00000000..b9068f60 --- /dev/null +++ b/examples/CMakeLists.txt @@ -0,0 +1,5 @@ +set(SRC example.c) + +add_executable(example ${SRC}) +target_link_libraries(example PRIVATE csfml-graphics csfml-audio) +set_file_warnings(${SRC}) diff --git a/examples/doodle_pop.ogg b/examples/doodle_pop.ogg new file mode 100644 index 00000000..555ea348 Binary files /dev/null and b/examples/doodle_pop.ogg differ diff --git a/examples/example.c b/examples/example.c new file mode 100644 index 00000000..62f169dc --- /dev/null +++ b/examples/example.c @@ -0,0 +1,89 @@ +#include +#include + +#include + +int main(void) +{ + // Create the main window + const 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("sfml_logo.png", NULL); + if (!texture) + { + sfRenderWindow_destroy(window); + return EXIT_FAILURE; + } + sfSprite* sprite = sfSprite_create(); + sfSprite_setTexture(sprite, texture, sfTrue); + const sfVector2f spritePosition = {200, 200}; + sfSprite_setPosition(sprite, spritePosition); + + // Create a graphical text to display + sfFont* font = sfFont_createFromFile("tuffy.ttf"); + if (!font) + { + sfSprite_destroy(sprite); + sfTexture_destroy(texture); + sfRenderWindow_destroy(window); + 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("doodle_pop.ogg"); + if (!music) + { + sfText_destroy(text); + sfFont_destroy(font); + sfSprite_destroy(sprite); + sfTexture_destroy(texture); + sfRenderWindow_destroy(window); + 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; +} diff --git a/examples/sfml_logo.png b/examples/sfml_logo.png new file mode 100644 index 00000000..509acc07 Binary files /dev/null and b/examples/sfml_logo.png differ diff --git a/examples/tuffy.ttf b/examples/tuffy.ttf new file mode 100755 index 00000000..8ea64709 Binary files /dev/null and b/examples/tuffy.ttf differ diff --git a/include/SFML/Audio/Listener.h b/include/SFML/Audio/Listener.h index 10a0874a..2a875a4d 100644 --- a/include/SFML/Audio/Listener.h +++ b/include/SFML/Audio/Listener.h @@ -68,7 +68,7 @@ CSFML_AUDIO_API void sfListener_setPosition(sfVector3f position); /// \return The listener's position /// //////////////////////////////////////////////////////////// -CSFML_AUDIO_API sfVector3f sfListener_getPosition(); +CSFML_AUDIO_API sfVector3f sfListener_getPosition(void); //////////////////////////////////////////////////////////// /// \brief Set the orientation of the forward vector in the scene @@ -91,7 +91,7 @@ CSFML_AUDIO_API void sfListener_setDirection(sfVector3f direction); /// \return Listener's forward vector (not normalized) /// //////////////////////////////////////////////////////////// -CSFML_AUDIO_API sfVector3f sfListener_getDirection(); +CSFML_AUDIO_API sfVector3f sfListener_getDirection(void); //////////////////////////////////////////////////////////// /// \brief Set the upward vector of the listener in the scene @@ -114,7 +114,7 @@ CSFML_AUDIO_API void sfListener_setUpVector(sfVector3f upVector); /// \return Listener's upward vector (not normalized) /// //////////////////////////////////////////////////////////// -CSFML_AUDIO_API sfVector3f sfListener_getUpVector(); +CSFML_AUDIO_API sfVector3f sfListener_getUpVector(void); #endif // SFML_LISTENER_H diff --git a/include/SFML/Audio/SoundRecorder.h b/include/SFML/Audio/SoundRecorder.h index 9fa9c800..d26ba0c9 100644 --- a/include/SFML/Audio/SoundRecorder.h +++ b/include/SFML/Audio/SoundRecorder.h @@ -157,7 +157,7 @@ CSFML_AUDIO_API const char** sfSoundRecorder_getAvailableDevices(size_t* count); /// \return The name of the default audio capture device (null terminated) /// //////////////////////////////////////////////////////////// -CSFML_AUDIO_API const char* sfSoundRecorder_getDefaultDevice(); +CSFML_AUDIO_API const char* sfSoundRecorder_getDefaultDevice(void); //////////////////////////////////////////////////////////// /// \brief Set the audio capture device diff --git a/include/SFML/Config.h b/include/SFML/Config.h index 04261f42..d6f74bf1 100644 --- a/include/SFML/Config.h +++ b/include/SFML/Config.h @@ -119,7 +119,7 @@ // ... // }; // -// CSFML_DEPRECATED void globalFunc(); +// CSFML_DEPRECATED void globalFunc(void); //////////////////////////////////////////////////////////// #if defined(CSFML_NO_DEPRECATED_WARNINGS) diff --git a/include/SFML/Graphics/RenderStates.h b/include/SFML/Graphics/RenderStates.h index 5bb7bf08..435f6aae 100644 --- a/include/SFML/Graphics/RenderStates.h +++ b/include/SFML/Graphics/RenderStates.h @@ -50,6 +50,6 @@ typedef struct /// \brief Define the default values for a RenderState /// //////////////////////////////////////////////////////////// -CSFML_GRAPHICS_API sfRenderStates sfRenderStates_default(); +CSFML_GRAPHICS_API sfRenderStates sfRenderStates_default(void); #endif // SFML_RENDERSTATES_H diff --git a/include/SFML/Graphics/RenderTexture.h b/include/SFML/Graphics/RenderTexture.h index fc7f5f14..e026eb07 100644 --- a/include/SFML/Graphics/RenderTexture.h +++ b/include/SFML/Graphics/RenderTexture.h @@ -326,7 +326,7 @@ CSFML_GRAPHICS_API const sfTexture* sfRenderTexture_getTexture(const sfRenderTex /// \return The maximum anti-aliasing level supported by the system /// //////////////////////////////////////////////////////////// -CSFML_GRAPHICS_API unsigned int sfRenderTexture_getMaximumAntialiasingLevel(); +CSFML_GRAPHICS_API unsigned int sfRenderTexture_getMaximumAntialiasingLevel(void); //////////////////////////////////////////////////////////// /// \brief Enable or disable the smooth filter on a render texture diff --git a/include/SFML/Graphics/Texture.h b/include/SFML/Graphics/Texture.h index ab7adb2b..19b1b9a9 100644 --- a/include/SFML/Graphics/Texture.h +++ b/include/SFML/Graphics/Texture.h @@ -403,7 +403,7 @@ CSFML_GRAPHICS_API void sfTexture_bind(const sfTexture* texture, sfTextureCoordi /// \return Maximum size allowed for textures, in pixels /// //////////////////////////////////////////////////////////// -CSFML_GRAPHICS_API unsigned int sfTexture_getMaximumSize(); +CSFML_GRAPHICS_API unsigned int sfTexture_getMaximumSize(void); #endif // SFML_TEXTURE_H diff --git a/include/SFML/Graphics/VertexBuffer.h b/include/SFML/Graphics/VertexBuffer.h index d7f3d0df..182a5d09 100644 --- a/include/SFML/Graphics/VertexBuffer.h +++ b/include/SFML/Graphics/VertexBuffer.h @@ -248,7 +248,7 @@ CSFML_GRAPHICS_API void sfVertexBuffer_bind(const sfVertexBuffer* vertexBuffer); /// \return True if vertex buffers are supported, false otherwise /// //////////////////////////////////////////////////////////// -CSFML_GRAPHICS_API sfBool sfVertexBuffer_isAvailable(); +CSFML_GRAPHICS_API sfBool sfVertexBuffer_isAvailable(void); #endif // SFML_VERTEXBUFFER_H diff --git a/include/SFML/Network/UdpSocket.h b/include/SFML/Network/UdpSocket.h index abf05ff6..bb42b9bc 100644 --- a/include/SFML/Network/UdpSocket.h +++ b/include/SFML/Network/UdpSocket.h @@ -203,7 +203,7 @@ CSFML_NETWORK_API sfSocketStatus sfUdpSocket_receivePacket(sfUdpSocket* socket, /// \return The maximum size of a UDP datagram (message) /// //////////////////////////////////////////////////////////// -CSFML_NETWORK_API unsigned int sfUdpSocket_maxDatagramSize(); +CSFML_NETWORK_API unsigned int sfUdpSocket_maxDatagramSize(void); #endif // SFML_UDPSOCKET_H diff --git a/include/SFML/Window/Clipboard.h b/include/SFML/Window/Clipboard.h index f21f00ae..c2a60d30 100644 --- a/include/SFML/Window/Clipboard.h +++ b/include/SFML/Window/Clipboard.h @@ -42,7 +42,7 @@ /// \return Clipboard contents as a locale-dependent ANSI string /// //////////////////////////////////////////////////////////// -CSFML_WINDOW_API const char* sfClipboard_getString(); +CSFML_WINDOW_API const char* sfClipboard_getString(void); //////////////////////////////////////////////////////////// @@ -55,7 +55,7 @@ CSFML_WINDOW_API const char* sfClipboard_getString(); /// \return Clipboard contents as UTF-32 /// //////////////////////////////////////////////////////////// -CSFML_WINDOW_API const sfUint32* sfClipboard_getUnicodeString(); +CSFML_WINDOW_API const sfUint32* sfClipboard_getUnicodeString(void); //////////////////////////////////////////////////////////// /// \brief Set the content of the clipboard as ANSI string data diff --git a/include/SFML/Window/Context.h b/include/SFML/Window/Context.h index 689826b3..c7bfca5c 100644 --- a/include/SFML/Window/Context.h +++ b/include/SFML/Window/Context.h @@ -32,7 +32,7 @@ #include #include -typedef void (*GlFunctionPointer)(); +typedef void (*GlFunctionPointer)(void); //////////////////////////////////////////////////////////// /// \brief Create a new context @@ -104,6 +104,6 @@ CSFML_WINDOW_API sfContextSettings sfContext_getSettings(const sfContext* contex /// \return The active context's ID or 0 if no context is currently active /// //////////////////////////////////////////////////////////// -CSFML_WINDOW_API sfUint64 sfContext_getActiveContextId(); +CSFML_WINDOW_API sfUint64 sfContext_getActiveContextId(void); #endif // SFML_CONTEXT_H diff --git a/include/SFML/Window/Vulkan.h b/include/SFML/Window/Vulkan.h index 45a1b1a2..187b4393 100644 --- a/include/SFML/Window/Vulkan.h +++ b/include/SFML/Window/Vulkan.h @@ -43,7 +43,7 @@ typedef uint64_t VkSurfaceKHR; typedef struct VkAllocationCallbacks VkAllocationCallbacks; -typedef void (*sfVulkanFunctionPointer)(); +typedef void (*sfVulkanFunctionPointer)(void); //////////////////////////////////////////////////////////// /// \brief Tell whether or not the system supports Vulkan @@ -79,4 +79,4 @@ CSFML_WINDOW_API sfVulkanFunctionPointer sfVulkan_getFunction(const char* name); /// \return Vulkan instance extensions required for graphics /// //////////////////////////////////////////////////////////// -CSFML_WINDOW_API const char* const* sfVulkan_getGraphicsRequiredInstanceExtensions(); +CSFML_WINDOW_API const char* const* sfVulkan_getGraphicsRequiredInstanceExtensions(void);