Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: eXpl0it3r's Examples  (Read 9576 times)

0 Members and 1 Guest are viewing this topic.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11035
    • View Profile
    • development blog
    • Email
eXpl0it3r's Examples
« on: October 23, 2012, 04:45:16 pm »
Those who are following me on GitHub might have already noticed my Examples repository, for all the others (and the first ones too of course), I'm making this forum post.

Every now and then I help out some people or goof around with some ideas or code pieces and sometimes I end up with a small example that kind of looks cool, but I don't really have a purpose for it. So instead of just letting it rot somewhere on my harddisk, I thought it could be a inspiring thing to upload them to GitHub. But just reading code mostly isn't that interesting/inspiring thus I'll share here also some screenshots. :)

All the examples related to SFML can be found in the SFML directory. Keep in mind that the code is provided as-is and isn't always suited for final products, since I didn't spend much time thinking about performance or nice code design decisions. ;)

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.



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.



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.



Lightning
I had once read a tutorial in connection with SFML on how to create some nice 'laser' effect. Unfortunatly 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.



Road
I'm not sure if there ever existed a forum post or if the whole conversation happend 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. ;)



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. :)



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.


Everything is under the zlib/png license and you can use it and reference it in whatever way you want. :)
« Last Edit: February 24, 2015, 05:25:50 pm by eXpl0it3r »
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Foaly

  • Sr. Member
  • ****
  • Posts: 453
    • View Profile
Re: eXpl0it3r's Examples
« Reply #1 on: October 23, 2012, 10:13:32 pm »
Nice! Looks good. I like the idea of collecting a couple of working examples! Especially since I was involved in a couple of them.
I only took a quick look at the hue shift example. I faced the same problem lately. But I solved it like this:
        // Calculate the color
        hue += 0.25 * fTime;
        if(hue > 1.0)
            hue = 0.0;

        // convert hue to RGB
        float r = std::abs(3.0 - 6.0 * hue) - 1.0;
        float g = 2.0 - std::abs(2.0 - 6.0 * hue);
        float b = 2.0 - std::abs(4.0 - 6.0 * hue);

        color = sf::Color(Clamp(r, 0.f, 1.f) * 255.f, Clamp(g, 0.f, 1.f) * 255.f, Clamp(b, 0.f, 1.f) * 255.f);
It is a little more efficient and easier to control.

mateandmetal

  • Full Member
  • ***
  • Posts: 171
  • The bird is the word
    • View Profile
    • my blog
Re: eXpl0it3r's Examples
« Reply #2 on: October 23, 2012, 11:38:18 pm »
- Mate (beverage) addict
- Heavy metal addict _lml
- SFML 2 addict
- My first (and free) game: BichingISH!

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11035
    • View Profile
    • development blog
    • Email
Re: eXpl0it3r's Examples
« Reply #3 on: October 24, 2012, 12:12:46 am »
Nice! Looks good. I like the idea of collecting a couple of working examples! Especially since I was involved in a couple of them.
Glad you like it! :)

I only took a quick look at the hue shift example. I faced the same problem lately. But I solved it like this:
What exactly does Clamp do?
If it seemed to work fine, would it be possible to use it in the example (i.e. does it use a zlib compatible license)? ;D

Great!
Pole Position !!!  :'(  ;D
I had more Grand Prix Circuit, which I've played quite a lot, in mind when creating the layout. :D

Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Foaly

  • Sr. Member
  • ****
  • Posts: 453
    • View Profile
Re: eXpl0it3r's Examples
« Reply #4 on: October 24, 2012, 09:30:47 am »
I actually really really like this idea. I think a new wiki category with examples would be an even better idea. That way everybody can edit, extend and explain them. Examples are an awesome thing for beginners, because they can look at existing working code and try to understand things. This would be a nice way to extend the sfml examples without blowing up the whole SDK.

Clamp is a template that clamps a value in given range. I'm sorry I forgot to explain that. I can post the exact code when I'm on my other machine. I actually haven't thought about any licensing yet, because I just use it myself. I'll think about it.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11035
    • View Profile
    • development blog
    • Email
AW: Re: eXpl0it3r's Examples
« Reply #5 on: October 24, 2012, 10:18:01 am »
I actually really really like this idea. I think a new wiki category with examples would be an even better idea. That way everybody can edit, extend and explain them. Examples are an awesome thing for beginners, because they can look at existing working code and try to understand things. This would be a nice way to extend the sfml examples without blowing up the whole SDK.
Well we actually got the Source Code category, which could be a bit similar.
I'm aware that this could be wiki material, but for me it's kind of hard to maintain the wiki pages, where as my Git repository is simple to keep uptodate. Maybe I could create a similar wiki page to this forum post, that captures the ideas and just link to my repository...

Clamp is a template that clamps a value in given range. I'm sorry I forgot to explain that. I can post the exact code when I'm on my other machine.
Yeah I kind of thought that this was the purpose. But what are the parameters for?

I actually haven't thought about any licensing yet, because I just use it myself. I'll think about it.
I'll only use it if it's compatible with the zlib license. (Otherwise I might just steal the idea and use my own implementation.) ;D
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Foaly

  • Sr. Member
  • ****
  • Posts: 453
    • View Profile
Re: eXpl0it3r's Examples
« Reply #6 on: October 24, 2012, 05:53:43 pm »
Maybe I could create a similar wiki page to this forum post, that captures the ideas and just link to my repository...
Alright I guess that would work too.

Here is the Clamp template:
template <typename T> T Clamp(const T& value, const T& low, const T& high)
{
  return value < low ? low : (value > high ? high : value);
}
The parameters are the value to be clamped, the lower and the upper bound.

I'll only use it if it's compatible with the zlib license. (Otherwise I might just steal the idea and use my own implementation.) ;D
Alright you can do whatever you want with it, but it would be nice if you reference me as an author :) The idea is to increment the hue over time and then convert the hue to an RGB color using techniques explained in this blog post: http://chilliant.blogspot.de/2010/11/rgbhsv-in-hlsl.html

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11035
    • View Profile
    • development blog
    • Email
Re: eXpl0it3r's Examples
« Reply #7 on: December 27, 2012, 12:07:25 am »
Finally found the time to take a look at the examples, make some minor corrections and add some more comments.
Additionally I also finally managed to modify the HueShift example to use Foaly's code.

Alright you can do whatever you want with it, but it would be nice if you reference me as an author :)
I've put a comment at the beginning of the file, I hope that's sufficient for you, otherwise let me know. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Foaly

  • Sr. Member
  • ****
  • Posts: 453
    • View Profile
Re: eXpl0it3r's Examples
« Reply #8 on: January 01, 2013, 06:50:13 pm »
Works for me :)
And the code does look better then before  ;D

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11035
    • View Profile
    • development blog
    • Email
Re: eXpl0it3r's Examples
« Reply #9 on: February 24, 2015, 05:31:45 pm »
Hey look what I dug up! ;D

Just added a small example on how to go about mixing two sf::SoundBuffers.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/