My first modified GLSL Fragment Shader Demo in SFML
#1
I recently downloaded the latest MinGW C++ toolchain (8.1.0) and the SFML library (2.5.0) to get prepared to start creating more powerful graphical demos and games while I am working on my new site so I don't get burned out on my work. I chose the SFML library due to it had all the tools I was looking for, plus some. I was excited by all it had to offer so I had to get it working. I just didn't realize how long it was going to take me to be able to use it.

While I understand a good bit of C++ ver 17, I am not up to par on the differences between versions (ie: v14, v11, etc...), which caused me to run into issues trying to get SFML working with the version of the MinGW C++ toolchain that I chose to use. As I will show, SFML does offer various versions to download for various toolchains, they didn't have one for the version I chose to use. So I had to download the source code and compile it in my preferred version.

If you would like to download the latest version of the MinGW toolchain I am using, you can get it at: https://sourceforge.net/projects/mingw-w64/files/External%20binary%20packages%20%28Win64%20hosted%29/gdb/

Here's a screenshot of the current page:



You can download the latest version of SFML (Simple and Fast Multimedia Library) at: https://www.sfml-dev.org/download.php

Here is a screenshot of the current SFML downloads page:



If you looked at the above screenshot of the SFML downloads page, you may have noticed that they offer a precompiled version for the GCC 7.3.0 MinGW (SEH) - 64-Bit toolchain. As shown in the MinGW screenshot above, they offer that version as well. however, I wanted the latest and greatest version, which is why I went through all the trouble to compile SFML's source code in MinGW 8.1.0.

After figuring out how to compile SFML in MinGW 8.1.0, I realized I needed to make a YouTube video on how to do it. I have part of a script written for the video already, but I have to make a logo for my "TJP's SOAP" brand which I will be using for all my educational video's as well as the next website I want to create after the current one I am working on. What does "TJP's SOAP" stand for you ask? It is short for: "The Joyful Programmer's: School of Awesome Programming".

After getting SFML working in the MinGW 8.1.0 toolchain, and both of them working in Code::Blocks ver 17.12 (the latest at the time of this writing), I started playing around with the demos in their examples folder. While there are only twelve demos all together, they are all powerful and very useful. After trying most of the examples, I got hooked on playing with the "Shaders" demo, especially since I found a ton of them on the internet that I could add to the demo. The demo I am about to share contains thirty-three (33) total shaders, including the original five written by SFML.

One thing I must admit, all the shaders I added to the demo are what they call, "Fragment Shaders". A fragment shader manipulates textures (hardware images) at the pixel level, unlike the other shaders that work on other components of scene like the "Vertex Shader" that manipulates the 3D points of vertices (the points that make up the triangles that makes up all 2D and 3D scenes).

SFML uses, and is based on OpenGL. The cool thing is (to me), you can use OpenGL commands in your SFML projects. The shader code you write is the same code you would write in OpenGL. The shader programming language, GLSL (short for: OpenGL Shading Language), is similar to the C programming language, and should be relatively easy to write for C/C++ coders.

I must admit, you have to change the way you look at how you build your images for your textures when you use shaders, but once you get the hang of it, your imagination is your only limit to what you can. The demo I am sharing contains all source code, including those for the shaders, so you can see how they are created. I did not create any of them, just gathered them from the web and placed in this one demo for your enjoyment. The code you write for the fragment shader is called for each and every single pixel on the screen, so it would be costly if you want to manipulate more pixels per iteration. This is why I am very amazed how many people have created such amazing shader demos I found and used in this attached demo. To me, its like going from writing code in DOS to event-driven apps in Windows. I had to change the way I looked at the solution I needed for each problem I had, just like those going from BASIC to C++.

Here are the screenshots of all the shader effects in the attached shader demo:



Here's a little fact about the shaders in the demo that might blow your mind, the only external images used are only in the 1st, 4th, and 5th effects. All other shader effects are created in real time and on-the-fly.

About the attached demo: There is only one executable, and it can be only ran on a 64-Bit version of Microsoft Windows. I haven't setup these toolchains and libraries in Linux at the moment, and I am not very sure I will. I don't own a MAC either, so I will not compile it for that machine.


Attached Files .zip   SFML-Shader-v2-CODE.zip (Size: 1,019.62 KB / Downloads: 9)
Dedicated to empowering computer programming hobbyists, tinkerers, amateurs, and enthusiasts.
profile for Walter Whitman at Stack Overflow, Q&A for professional and enthusiast programmers


Reply
#2
Just for a giggle, I ran the shader program on my Linux machine, just to see if Wine could handle it.

At least half of the shaders ran as they were supposed to; Some would say that the shader was 'not supported'... but eventually poor Wine "spat the dummy" and basically "took its bat and ball and went home". As a parting gesture it locked up my machine so as to leave me with no choice but to power down. lol

But, the shaders that DID work, were REALLY impressive... Very cool... the shaders... not my machine locking up... lol

J
May your journey be free of incident.

Live long and prosper.
Reply
#3
@Johnno56,

I am still studying, as well as playing with SFML and OpenGL in C++ ver 17 (MinGW 8.1.0) 64-bit, but from what I have seen, "the not supported" error message you get is either due to SFML not being able to load the *.FRAG fragment shader file, there is an error in the code (which I am sure is not the case in your situation since I have tested the demo before I uploaded it, or your current video card driver does not recognize some of the code due to it being an earlier version. This demo uses Open GL 4.0's GLSL programming language, and is not compatible with drivers built for earlier versions of OpenGL.

Also, some of the effects provided in the demo are very taxing to the video card processors, and can crash the video card on older machines and laptops. Several of them run slow on my laptop, like the cake, octopus, both space scenes, and the wood effect, but they run fine on my work computer. There were several effects I found during my lunch breaks that I loved, but they could not run on my laptop, so I didn't include them in the demo. I did find hundreds upon hundreds of shader demos on the web, so there are plenty of examples out there. However, I would suggest being careful if you go looking for them, especially if your browser can run 3D. If you have an older machine that can run 3D in the browser (in HTML5 with the CANVAS element - No plugins), these sites will run the shaders. I had to restart my laptop numerous times becuase many of the shader effects were too processor intense, and crashed my video card. A few times my video card was able to reboot itself, but other times it took too long, so I turned it off then back on (after at least 15 seconds).

On another note, this is the first thread, of what might be many, on SFML in C++ ver 17, 64-bit, as I would like to share with what I create as I continue to learn these technologies. If I share any more executables, they shouldn't be as video card processor intense.
Dedicated to empowering computer programming hobbyists, tinkerers, amateurs, and enthusiasts.
profile for Walter Whitman at Stack Overflow, Q&A for professional and enthusiast programmers


Reply