1
0
Fork 0
mirror of https://github.com/eXpl0it3r/Examples.git synced 2026-01-01 10:43:00 +00:00
Smaller or bigger examples that I've written or will write in the future in C++.
Find a file
2024-01-23 09:19:01 +01:00
.github/workflows Update version of the checkout action 2023-02-11 11:11:57 +01:00
SFML Bring Examples inline with the latest SFML version 2024-01-23 09:19:01 +01:00
zlib Modernize and align the examples some more 2021-12-29 22:08:59 +01:00
.gitignore Update CMake structure 2021-10-27 00:49:57 +02:00
CMakeLists.txt Use FetchContent for SFML 2023-02-10 23:50:59 +01:00
LICENSE Use FetchContent for SFML 2023-02-10 23:50:59 +01:00
README.md Add missing images and example 2021-10-28 20:47:32 +02:00

Examples

Every now and then I sit down and try out some features of some library, C++ itself or with SFML. Instead of letting those code fragments go to waste somewhere on my disk or get lost in the depth of the SFML forum, I decided to put them openly and centralized here on GitHub for everyone to see, share and learn from them.

Keep in mind that the code is provided as-is and isn't necessarily suited for your final product, as not a lot of thought was put into performance or code design.

zlib

gzip Decompression

zlib is a small and useful library which allows the compression and decompression of data. By applying some settings it's possible to let zlib decompress a gzip file, which this examples demonstrates by loading a file into memory and output the decompressed data to standard output.

SFML

Center Text

One of the most common questions you'll run into on the SFML forum is how to center a sf::Text object inside a shape, or more commonly, a button. Because sf::Text aligns itself to the baseline instead of the visual top/bottom, it tends to be more confusing that working with shapes and sprites. In order to get it working properly, you have to take into account the LocalBounds as is shown in the given example.

Center Text

Fading Dots

This was originally created as a test for this thread (or was it this one?), but since I kind of liked the result I adjusted a few things and uploaded it.

Fading Dots

Flashlight

Out of nowhere came suddenly all those requests (starting with this one) for subjective blending and I think, I could help a few people with my example on how to achieve what they wanted.

Flashlight 1 Flashlight 2

Hue Shift

Although I can't find the original SFML thread about this, I found the StackOverflow question which was IIRC created before the forum thread. This effect can definitely give a nice ambiance, but it probably could need some retouching. Since the picture do not tell much: Starting off with one color the example automatically iterates through the whole RGB color spectrum in a smooth way.

Hue Shift

Lightning

I had once read a tutorial in connection with SFML on how to create some nice 'laser' effect. Unfortunately I don't remember which blog/site this was on, because he was using some texture moving which made everything look even better. While doing a search to possible find that tutorial again, I found another similar piece of code on the forum, adapted it for SFML 2 and made a nicer class out of it.

Lightning

Mixing SoundBuffers

The other day in #learnprogramming on freenode someone was trying to implement a way to mix two audio files without actually playing them back. I wondered how something like that would work with SFML and thus went ahead an wrote a small example. A quick Google search on audio sample mixing brought me to this site and lead me to the current implementation.

Road

I'm not sure if there ever existed a forum post or if the whole conversation happened on IRC, but someone wanted to make a 'scrolling' road and since I really liked that idea, I went ahead and implemented an example. The code here is particularly not that nice, so keep that in mind when adapting it.

Road

Rotating Triangle

One of the age old questions by game development beginners is along the lines of "How do I rotate my player to face X?". This short example answers that question, by rotating a triangle (sf::CircleShape with three points) to wherever the mouse pointer is on the window.

Rotating Triangle

Rotating Vertices

This example answers the same question as the 'Rotating Triangle' one, but it uses a sf::VertexArray in combination with a sf::Transformable. It's a good foundation to see how one could start to implement an entity class deriving from sf::Transformable and sf::Drawable.

Rotating Vertices

Simple AABB

Every month there's at least one question on simple collision detection testing the last 'bigger' one with in this forum thread, which lead to this example. I've even implemented some very simple physics, which will fail in most situations, but you can at least move around and jump.

AABB

Sound Recording

Even though SFML has a tutorial and an example on sound recording, I wanted to have my own small demonstration of said feature with recording device selection and mono/stereo options.

License

All examples are under the zlib/png license and thus free to use. See the LICENSE file for more details.