Getting Started with SFML using Code::Blocks
SFML is a simple fast multimedia library that is a pleasure to use. The instructions below for getting started, written at the end of May 2015, are even more detailed than the official page. The instructions apply to CodeBlocks installed on Windows following the instructions on the preceding page and are for the use of dynamic linked libraries rather than for static libraries.
=== TDM-GCC Compiler Suite for Windows ===
--- GCC 4.6 & 4.7 Series ---
- Download SFML version GCC 4.7.1 TDM (SJLJ) - 32-bit from the download page.
Unzip to a convenient folder.
We unzipped to C:\Program Files (x86)\CodeBlocks\.
- In CodeBlocks, select menu option SFML_Trial. and open an Empty project. Name it
- Select menu item then select the Search directories tab and the Compiler tab within it.
- Press the Add button, select the include path such as C:\Program Files (x86)\CodeBlocks\SFML-2.3\include and choose not to keep it as relative path.
- Select the Linker tab instead of Compiler tab, press the Add button, select the lib path such as C:\Program Files (x86)\CodeBlocks\SFML-2.3\lib and choose not to keep it as relative path.
- Select menu item then select the Linker settings tab.
- Click the Add button and enter sfml-graphics.
Similarly add sfml-window and sfml-system.
See the screenshot on the official page.
- Click the OK button.
- Select menu item main.cpp (for both debug and release). and save it as
- Copy the test program from the official page and paste it into main.cpp.
Select menu option
.You should find the object file main.o in a folder such as C:\Working\SFMLCodeBlocks\SFML_Trial\obj\Debug.
Copy all the .dll files from SFML-2.3\bin to the folder that will contain the final executable, creating new folders as necessary.
We copied the dynamic link libraries from C:\Program Files (x86)\CodeBlocks\SFML-2.3\bin to C:\Working\SFMLCodeBlocks\SFML_Trial\bin\Debug.
Click the Build and run button.
You should see an empty console window and a graphics window with a green circle.
If you do not want the console window, select menu item
, select the Build targets tab and select GUI application instead of Console application in the combo box. Select menu option and accept the invitation to continue.Continue following the instructions to try the stunning demonstration of shaders.
Copy Effect.hpp and the resources folder from the examples\shader folder to your project folder.
We copied from C:\Program Files (x86)\CodeBlocks\SFML-2.3\examples\shader to C:\Working\SFMLCodeBlocks\SFML_Trial.
- Open with a text editor such as Notepad++ examples\shader\Shader.cpp and copy and paste all of the code to replace the existing code in main.cpp.
- Rebuild, execute and prepare to be impressed!