Now that we have a working development environment we can go ahead and configure a project and write some code that actually does something. For the sake of actually seeing SFML in action we will write some code but we will not learn about each and every line of it. Rather we will improve our understanding as we progress during future SFML projects and C++ tutorials .[widgets_on_pages id=”udemy_advert_cpp_1″][widgets_on_pages id=”udemy_code_details”]
Getting started
In this project we will start from the very beginning as this is our first SFML project. It is true that there is quite a bit of messing around to be done with regard to configuring our first project to use SFML in the way that we need. We will however be saving these configurations in a Visual Studio template so that all future projects can be started with a couple of clicks. When we have done this we will finally get to see SFML in action as we draw some fancy text to the screen.
Configuring the SFML project
Start Visual Studio 2017 and select File | New Project.
In the New Project window choose Visual C++ || Windows Desktop then Win32 Console Application. You can see all these selections in the next screenshot.
Now at the bottom of the New Project window type HelloSFML in the Name: field. It is a tradition when learning a new language to start making a program which says “Hello World” to the user. This is what we will do in this project but we will quickly get closer and closer to a real game as we progress through future projects.
Next, browse to the Visual Studio Stuff\Projects\ folder that we created in the Setting up a Visual Studio 2017 and SFML development environment project. This will be the location that all our project files will be kept.
When you have completed the steps above click OK. and Visual Studio will create our new project.
[widgets_on_pages id=”bcgp_cfgp_gpp”]
The slightly dull (but important) configuration stuff
Next, we will add some fairly intricate and vital project settings. This is the laborious part but we will only need to do this once. What we need to do is to tell Visual Studio, or more specifically the code compiler that is part of Visual Studio where to find a special type of code file from the SFML SDK. The special type of file I am referring to is a header file. Header files are the files that define the format of the SFML code. So when we use the SFML code the compiler knows how to handle it. Note that the header files are distinct from the main source code files and they are contained in files with the .hpp file extension. All this will become clearer when we eventually start adding our own header files in a few projects time. In addition, we need to tell Visual Studio where it can find the SFML library files.
We can achieve the above by doing the following:
From the Visual Studio main menu select Project | HelloSFML properties. In the resulting HelloSFML Property Pages window take the following steps which are numbered and can be referred to in the next image.
- Select All Configurations from the Configuration: drop-down.
- Select C/C++ then General from the left-hand menu.
- Locate the Additional Include Directories edit box and type the drive letter where your SFML folder is followed by \SFML\include. So the full path to type if you located your SFML folder on your D drive is, as shown in the screen-shot D:\SFML\include.
Click Apply to save our configurations so far.
Still, in the same window perform these next numbered steps which again refer to the next image.
- Select Linker then General.
- Find the Additional Library Directories edit box and type the drive letter where your SFML folder is followed by \SFML\lib. So the full path to type if you located your SFML folder on your D drive is, as shown in the screen-shot is D:\SFML\lib.
Click Apply to save our configurations so far.
Finally for this stage, still in the same window perform these numbered steps which again refer to the next image.
- Switch the Configuration: drop down to Debug as we will be running and testing our games in debug mode for now.
- Select Linker then Input.
- Find the Additional Dependencies edit box and click it at the far left. Now copy & paste the following sfml-graphics-d.lib;sfml-window-d.lib;sfml-system-d.lib;sfml-network-d.lib;sfml-audio-d.lib; at the indicated place (3). Again be REALLY careful to place the cursor exactly and not to overwrite any of the text that is already there.
- Click OK.
Let’s make a template of our work so far so we never have to do this again.
Creating a reusable project template
This is really easy. In Visual Studio select File | Export Template…. Then in the Export Template Wizard window make sure the Project template option is selected and the HelloSFML project is selected for the From which project do you want to create a template option. Click Next and then Finish. That’s it. Next time we create a project I’ll show you how to do it from this template.
Copying the .dll files to the project folder
That’s the tedious stuff done. In future, we will just be able to create a new project based on the template we just made. The only other step will be to copy the .dll files into the project folder which we will step through now.
My project folder is D:\Visual Studio Stuff\Projects\HelloSFML\HelloSFML. The files we need to copy into there are located at D:\SFML\bin. Of course, if you installed Visual Studio and the Visual Studio Stuff folder on a different drive then replace D: from the previous paths with your appropriate drive letter. Open a window for each location and highlight the required files as shown in the next screenshot on the left.
Copy & paste the files in the YOUR_DRIVE:\SFML\bin to YOUR_DRIVE:\Visual Studio Stuff\Projects\HelloSFML\HelloSFML.
Let’s code!
Writing the SFML “Hello World” game code
[widgets_on_pages id=”udemy_advert_cpp_2″][widgets_on_pages id=”udemy_code_details”]
Notice in the Visual Studio editor window there is a code file that was created for us. You can see the tab at the top-left in the next image the file name is HelloSFML.cpp. The .cpp stands for C++.
As I mentioned at the start of the slightly lengthy tutorial I won’t be explaining the code but I just want you to copy & paste some so you actually have something to show for all this effort.
Before we do SFML needs a font in order to draw text.
- Download this free-for-personal-use font from http://www.1001freefonts.com/28_days_later.font.
- Click the Download button.
- Unzip the download.
- Add the 28 Days Later.ttf file into the YOUR_DRIVE:\Visual Studio Stuff\Projects\HelloSFML\HelloSFML folder.
Delete all the code in the HelloSFML.cpp code file and add this code. Don’t be overwhelmed, at least half of it is just comments that don’t do anything but give hints and we will get to the bottom of all the weird symbols and words in a future tutorial. Be sure to read all the comments!
// Anything after // is a comment not actual C++ code // Comments are important and I use them to explain things // Why not read the comments in this code // These "include" code from the C++ library and SFML too #include "stdafx.h" #include <SFML/Graphics.hpp> // This is the main C++ program- Duh! // It is where our game starts from int main() { // Make a window that is 800 by 200 pixels // And has the title "Hello from SFML" sf::RenderWindow window(sf::VideoMode(800, 200), "Hello from SFML"); // Create a "Text" object called "message". Weird but we will learn about objects soon sf::Text message; // We need to choose a font sf::Font font; font.loadFromFile("28 Days Later.ttf"); // Set the font to our message message.setFont(font); // Assign the actual message message.setString("Hello world"); // Make it really big message.setCharacterSize(100); // Choose a color message.setFillColor(sf::Color::White); // This "while" loop goes round and round- perhaps forever while (window.isOpen()) { // The next 6 lines of code detect if the window is closed // And then shuts down the program sf::Event event; while (window.pollEvent(event)) { if (event.type == sf::Event::Closed) // Someone closed the window- bye window.close(); } // Clear everything from the last run of the while loop window.clear(); // Draw our message window.draw(message); // Draw our game scene here // Just a message for now // Show everything we just drew window.display(); }// This is the end of the "while" loop return 0; }
Now click the button shown in the next image
Gaze in awe at your creation.
If you found this tutorial hard you can rest easy. It is not uncommon when learning any language that setting up the development environment can be challenging. C++ environments can be especially so because of the way that headers and libraries work. These will become more familiar and less of a strain as we proceed. And most tutorials and projects in the future will be much shorter than this one.
GTA 6 is so close I can smell it! Not quite I suppose but we can start learning to code in C++.
It pops up with a warning that my computer lacks MSVCP140D.dll, and I’m using vs2013. Is it essential to use vs2015 or it’s just something wrong with my computer?
Hi,
The steps of the tutorial should work for 2013 as well as 2015 with the exception that you would need to download the SFML package that is suitable for 2013. MSVCP140D.dll is part of VS 2015. This might sound odd but Visual C++ 14 is part of Visual Studio 2015.
It sounds like you might have downloaded the SFML package for 2015 (as suggested in the tutorial because the tutorial is aimed at 2015). Try leaving the configuration of your project the same but making sure you put the replace SFML files for 2013 in the same place as well as copying the SFML dll files from the 2013 package to the project directory and deleting the dll files from the 2015 package of course.
Good luck and let me know how you get on as I will help if I can.
It worked! Thanks a lot mate.
A pleasure, have fun.
Whenever I click Local Windows Debugger it says ‘Unable to Start program ‘C:\Users\Documents\Visual Studio Stuff\Projects\HelloSMFL\Debug\HelloSMFL.exe’.
Could not find path specified
Any idea as to what is happening?
It is probably a minor miss-configuration.
Try this:
In the Solution Explorer window on the right, Right Click your solution Solution “HelloSFML”, and choose Configuration Manager
Check that Active Solution Platform: is set to x86
And Active Solution Configuration is set to Debug
Close the config window and try running the project again.
Configuring a project with the right settings can be a major pain but once you have got it right, save it as a template and every other sfml tutorial or project you do can be started with a couple of clicks. So it is worth a bit of pain to get it right. If it still doesn’t work consider starting a brand new project and make sure every step is followed exactly, just in case you slightly mis-configured somewhere.
There are some more suggestions here: http://stackoverflow.com/questions/5864520/error-while-trying-to-run-project-unable-to-start-program-cannot-find-the-file
The link suggests a range of possibilities including things like anti virus conflicts. Glance over them to see if any of the suggestions gets your attention as being relevant to your situation but it might be just as quick to try again from scratch. Delete the entire project folder or just use a new name, HelloSFML2 or similar.
The important thing is to make the template when you have got it right and you will never have to do this again.
All the best,
John
Thanks John, I started from scratch but I’m getting the same issue, my computer is 64bit while the platform is win32, could this be an issue?
Hi Cody,
The Platform should be set to win32 and Active Solution Platform should be set to x86 although this seems to fly in the face of logic. The idea being that one day you will deploy a game for others to use and by using these settings it will work with 32 and 64 bit platforms.
It is worth me checking that you definitely downloaded the 32 bit SFML packages as well? Again, it is very counter-intuitive to download the 32bit version but for the steps in the tutorial to succeed it is necessary.
Actually there are so few 32 bit PC’s these days it probably wouldn’t hurt to use the 64bit SFML package as well as configure your project to 64bit. However the steps in the tutorial would need to be changed as well.
When i try to run the program, i get an error message that says the file HelloSMFL.exe can not be found
Hi Callum, Thanks for your comment.
It is possible the the .exe cannot be found because it wasn’t created because of errors in the code. Try clicking the Build option which does everything except trying to execute the program. Then you will probably see an error or two in the window below the code.
Often the errors are self explanatory and easy to solve but if not, feel free to post it here and I will try and help you solve it.
The first error says cannot open source file “SMFL/Graphics.hpp”
The most likely cause for this is a slight misconfiguration. Double check the part of the tutorial headed “The slightly dull (but important) configuration stuff”. In particular the section that talks about header files. Make sure that the you use the exact same folder as where you unzipped the SFML files to.
Sometimes, because the project configuration is a bit intricate, it can be just as quick to start a new project and step through the configuration again from the start. Also re-read Setting up Visual Studio and SFML… to make sure SFML is prepared in the relevant place that relates to this tutorial.
Perhaps surprisingly, the first project is the most challenging of all, because of the config. Once you get this bit done, all the others are just a matter of getting the code right and adding the right assets. So keep at it and when you get it working be sure to make the template as described, so you never have to do this again.
Good luck.
I have resolved my problem. But how do you access the template of the sample project for use in other projects?
Hi Pac.
This project steps through making the template:
http://gamecodeschool.com/sfml/building-your-first-sfml-game-project/
And this project uses the template:
http://gamecodeschool.com/sfml/conditions-and-branching-demo-bouncing-shapes/
Hi,i am getting the same problem.can you tell me how you resolved yours?
Do you have setup instructions for xcode? I’ve got SFML configured to run it’s default app, need some help. Thanks
Hi Chris,
Really sorry but I have never set it up on XCode before. There is a tutorial for xcode sfml setup on the SFML site but I haven’t tried it.
http://www.sfml-dev.org/tutorials/2.3/start-osx.php
The only difference in the code might be file and folder names for things like loading fonts, textures and sound effects.
Sorry I can’t be more definite but hopefully that tutorial will get you started.
Thanks John, I played around with it but it will be easier if I just move to my Windows laptop, so I’m going to do that this evening. I’m excited for the upcoming game programming book and am curious if–beyond the basics (syntax, etc.)–it will make big an impact in helping the reader/user think like a programmer?
Hi Chris,
I want to add a Mac tutorial for all the getting started guides eventually but is going to take a while. I am contemplating contracting them out but the problem with that is it is hard to support people when they get stuck and I din’t do it myself.
Hopefully the book will help the reader to develop skills like thinking like a professional but mainly it is about using entirely games based content to cover what a C++ beginners guide would cover. So topics like design patterns which might be what you allude to will not be covered in-depth but they are introduced. In addition, as the complexity of the game projects increase throughout the book, the way the code is structured evolves to handle that complexity.
Thanks for your comment.
Hello
I don’t know if you are still interested but I got it to work for Xcode. On the SFML website there are instructions on where to save everything, and once you have a new project open you can just copy the SFML library file into your resources. I am super new to this, but managed to make it work (somehow)
Good luck
Thanks alot. the error apears in consol:
“failed to load font “28 days later.tff”
although i put the font file in the project file.
It works now.
Nice job!
Hi John,
Going through your “Building your first SFML game project” tutorial, and I’m at the part where I’m supposed to copy the contents of DRIVE:\SFML\bin into HelloSFML, only I don’t have a bin folder in my sfml folder. I checked the folder that I copied those files from, and the zip from there, and didn’t see it anywhere.
Assuming I did download the correct versions of visual studios and the SFML package, which I have double checked, what did I do wrong?
Ahem…. never mind.
Hello, i have an problem with visual studio, there is no Windows 32 console application option and i just proceeded with “windows console application ” and in step two there is no configuration tab .
Hi Azhar,
It is totally possible to start from a console application but I showed the steps the way I did to avoid some pitfalls. Try starting again again and be sure the Win32 (underneath C++) option is selected from the left-hand list of options. It is not all that clear in the image.
Why do we have to copy the .dll files?
Can’t we do a setting so that it loads from the SFML folder?
Hi Diana, Yes, your suggestion would be more efficient. I will hopefully get round to improving this tutorial soon. Many thanks.
When I try and build it, it says that it cannot open tile ‘sfml-graphics-d.lib’
This could be caused by either not adding all the text in the configuratiin process or trying to build the release instead of debug version. Perhaps take a look at these steps again. Sometimes it is just as quick to start again. Config is the most awkward bit but once you have a usable template you never have to do it again. Hope this helps a bit.
Did you find out what was wrong? I had this issue too and then realized I had forgotten to set my lib to SFML’s folder under the Linker/General/Additional Library Directories path as shown above in the config step.
Igetting error LNK1112 modul-computertype x64 have konflikt with targetcomputertype x86
Possibly the wrong .dll files were added to the project. There are a set for x64 and a set for x86. Try the other one. Good luck.
Hey, I got following error when building “C4996 ‘sf::Text::setColor': was declared deprecated”
Try commenting the line out or just removing it //…setolor… and see if that works.
They recently updated it to include both an outline color and a fill color for text. So you should use setFillColor instead.
Thanks Christian,
I will update this soon.
Hey,
If I want to make a new project and click on Visual C++, I see 4 maps: Windows, MFC, Cross Platform and Extensibility. If I click on those maps, it only gives me options to install things. For example: Install Microsoft Foundation Classes for C++.
Can you help me?
Do you have a C++ option as opposed to Visual C++. If not try reinstalling Visual Studio using this tutorial. http://gamecodeschool.com/sfml/setting-up-visual-studio-and-sfml-development-environment/
Hi,
i have a problem with configuring the SFML project part. I had to install VS express in C:\Program Files (x86) where i put the other 2 folders.
When i start a new project and browse to the Visual Studio Stuff\Projects\ folder and click ‘OK’ the window closes and opens again with the location set to my Documents directory.
I really hope you can help me!
This sounds like windows organizing for you with a virtual directory. You could continue and modify the rest of the instructions or start again and choose folders outside of … (x86) which might make the rest of the instructions more straightforward.
Updated to SFML 2.4 using setFillColor instead of setColor on 6th September 2016
Hey, all i read is that sfml are for Visual Studio.. so the real question is how can i use it for Developer C++ software instead? same language different software.. so yea
Hi there,
Do you mean Dev-C++? I haven’t tried it but can see no reason why it wouldn’t work.
Hi
I currently have visual studio 2008 pro installed. Can you please point me in the right direction to set it up with the SFML sdk
Thanks
Ok, I think i got it to work correct because it outputs “Hallo World” using the font.
I had to create an empty project and then add a c++ source file.
I also had to replace #include “stdafx.h” with #include “windows.h”
I then got an error at line 35: —-> message.setFillColor(sf::Color::White); —> it said error c2039: ‘setFillColor': is not a member of sf::Text —-> So i commented the line out, and the code compiled and ran.
I am new to this, So do you think this would cause problems later for me, if I continue with your tutorials ?
Thanks
This is awesome
Hi Max,
My best guess is you have already beaten the tough bit.
Which version of SFML do you have? setFillColor replaced setColor very recently. Try uncommenting the line and change it to setColor. If it works then try checking you have the latest version.
Don’t worry too much there isn’t much difference between the versions and the only difference I can think of in my tutorials is the change from setColor to the newer setFillColor.
This shouldn’t be a problem at all. It would just be a matter of identifying the configuration options in the older user interface.
the font can’t display the screen? how fix it, and not have error.
Hi Henry,
Is the code to load the font using exactly the same name as the font file? Is the font file in the same folder as the sfml dll files?
I hope this helps a bit.
I´ve tried every solution above but and I still get can´t it to work.
The first error the pops up is ” There was build errors. Would you like to continue and run the last successful build? “.
I click yes and then it says ” Unable to start program C:\Program Files (x86)\Visual Studio 2015\HelloSFML\Debug\HelloSFML.exe. Can´t find the file. ”
Then I press OK and I get 16 errors in error list and the first one says ” cannot open source file “SFML/Graphics.hpp” “.
Please help John!
Hi Nymbus,
“Can’t find file” might suggest a project configuration error. Have you successfully run this preparation project?
http://gamecodeschool.com/sfml/setting-up-visual-studio-and-sfml-development-environment/
Yes I´va done everything you said in the tutorial. However it was a little bit different on my computer.
First I had to put the Visual Studio 2015 folder in Program (x86) from the documents folder. Then in the Visual studios program I had to let it know that I had my Visual studio 2015 folder in program (x86) by changing it in the Imporot and Export settings.
Second I didn´t do a Visual studio stuff folder because when I tried to make a new project, it refused to let me press ok and continue it just reloaded the page. The solution to that was using the project folder in the Visual studio 2015.
Hi Nymbus, the only thing I can think to suggest is to make sure that whatever values you entered for the Additional Include Directories and Additional Library Directories actually refer to the SFML folder (or whatever you called it).
I can’t think of any other cause other than Visual Studio not being able to find the SFML files.
Ok never mind I solved it by making a few changes. Thank you John!
Undefined reference error. What could be wrong?
c:\Projects\hello_sfml>echo ” Compiling …”
” Compiling …”
c:\Projects\hello_sfml>g++ -c Hello.cpp -Ic:\SFML-2.4.0\include
c:\Projects\hello_sfml>echo “Linking …”
“Linking …”
c:\Projects\hello_sfml>g++ Hello.o -o hello-sfml -Lc:\SFML-2.4.0\lib -lsfml-graphics -lsfml-window -lsfml-system
Hello.o:Hello.cpp:(.text+0x1c9): undefined reference to `_imp___ZN2sf4Font12loadFromFileERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIc
EEE’
collect2.exe: error: ld returned 1 exit status
c:\Projects\hello_sfml>echo “Run executable file”
“Run executable file”
c:\Projects\hello_sfml>hello-sfml.exe
‘hello-sfml.exe’ is not recognized as an internal or external command,
operable program or batch file.
I am using TDM-GCC-32bit + SFML gcc-4.9.2-tdm-32 + VS Code
Here’s the my make.bat script:
echo ” Compiling …”
g++ -c Hello.cpp -Ic:\SFML-2.4.0\include
echo “Linking …”
g++ Hello.o -o hello-sfml -Lc:\SFML-2.4.0\lib -lsfml-graphics -lsfml-window -lsfml-system
echo “Run executable file”
hello-sfml.exe
I fixed the issue by using GCC 6.1.0 MinGW (DW2) – 32-bit . Unfortunately, the GCC 4.9.2 TDM (SJLJ) – 32-bit package comes with g++ version 5.1.0 and this violates the instruction on the SFML download page that “The compiler versions have to match 100%!”.
Note: I prefer the GCC option because it has a smaller footprint (= 7 GB on disk).
You can use VS code with the following batch script to compile and link your code using the Integrated Terminal in VS Code:
REM make.bat
@echo ” Compiling …”
g++ -c Hello.cpp -Ic:\SFML-2.4.0\include
@echo “Linking …”
g++ Hello.o -o hello-sfml -Lc:\SFML-2.4.0\lib -lsfml-graphics -lsfml-window -lsfml-system
@echo “Executing: hello-sfml.exe”
hello-sfml.exe
Thanks for sharing the solution Austin. It does seem slightly imperfect but if it works that should be good enough for most. I don’t know of any better solution as I have not set up SFML on Linux before. Thanks again, John.
Hello John. The setup is for Windows, not Linux.
GCC 6.1.0 MinGW (DW2) – 32-bit works perfectly well on Windows. I had issues installing the 12GB VS 2015 Express so I decided to give gcc a try.
Here is what I am using:
1. Visual Studio Code for Windows
2. SFML GCC 6.1.0 MinGW (DW2) – 32-bit for Windows
3. i686-6.1.0-release-posix-dwarf-rt_v5-rev0.7z (mingw32 GCC G++ 6.1.0 compiler for Windows)
4. A Batch script to automate the compilation and linking – .bat script already shared above
Thanks
Thanks for putting me straight. I will leave all your comments here because I am sure they will help someone. Thanks, Austin.
Hi John, I’ve also read in some introductory SFML C++ game development tutorials that the bin .dll files from the SFML folder are copy-pasted into the Debug folder inside SFML, as opposed to yours which are just pasted directly to the open folder SFML. What’s the difference between the two? Also, when are these .dll called? Can I just skip copying them? Thanks.
Hi Loqz, thanks very much for buying my book. The program will compile without the dll files. They are called when the project is linked. You can try this out by temporarily removing them. Using the configuration in the book they are also needed at runtime when you double click the .exe. If you look in the runnable folder of the download bundle they are amongst the projects there as well. They can be placed in other folders as long as you change the configuration settings accordingly. I hope this helps a bit and thanks very much for your comment.
Thank you John, this is really a good tutorial for me.
The programmed will crash when the the code executes to “font.loadFromFile(“28 Days Later.ttf”);”
And the vs popups with a message, “Unhandled exception at 0x6A98D417 (vcruntime140.dll) in HelloSFML.exe”
Sorry I made a mistake, I should use sfml-xxxx-d.lib, but I use sfml-xxx.lib.
Hi Jack,
Thanks for the problem and solution. This could help others.
Hi John,
I still have two problems.(My English is poor, hope you can understand what i say.)
1. The programme launched successfully, but the window is all black. I watched the Font Object, the member variable m_info is {family=”28 Days Later” }, so I guess the font file loaded success.
2. Two windows appear when the programme run. One is console window, and the other is normal window. ps. If I set Subsystem to “Windows”, it pops up a link error. “Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol _WinMain@16 referenced in function “int __cdecl invoke_main(void)” (?invoke_main@@YAHXZ) HelloSFML C:\Users\Jack\documents\visual studio 2015\Projects\HelloSFML\HelloSFML\MSVCRTD.lib(exe_winmain.obj) 1
“
Hi Jack,
This sounds like a config issue rather than code. Perhaps restart the configuration process again and double check the project type you select.
it says unable to start program c:\visual studio projects\HelloSFML\Debug\HelloSFML. exe
the system cannot find the file specified
It means the .exe was not built because something else prevented it. Are the .dll files in the project folder? If yes, did you definitely use the .dll files with the -d postfix? Are there some more errors/warnings on some of the other tabs of output next to the one you mention.
Hi John,
I get this error “‘…SFML/Graphics.hpp': No such file or directory”. I’ve double-checked the configuration, restarted the projected and double-checked again. The file is definitely in the folder, I’m obviously making some mistake, I just can’t seem to find it.
Thanks
Hi Mike,
In my view, setting up Visual Studio with SFML is the toughest of everything until you get to advanced programming topics. It is unfortunate that we must do this step before we can do anything else.
To solve this problem it is often easier to start again configuring a new project rather than trying to tweak the current config.
Some things to check/try when you start again are as follows.
Make sure you have the right version of SFML.
Don’t use the My Docs… folder in Windows for SFML as different versions of Windows have different access and path rules. Try to put SFML and projects at the root of the same drive.
Obviously be accurate with everything you type in.
Be sure to use the SFML .dll files with the -d extension and that they are in the project folder.
Don’t let this beat you because once you get the empty black screen running it is all easier from then on.
Good luck.
needed to change start to C: haha
cheers George
mine says
Warning: detected”Microsoft Corporation GDI Generic” OpenGL implementation
The current OpenGL implementation is not hardware-accelerated
setting vertical sync is not supported
faild to load font “28 Days Later.ttf” failed to create the font face)
OpenGL extension SGIS_texture_edge_clamp unavailable
Artifacts may occur along texture edges
Ensure thathardware acceleration is enable is available
Hi Neeraj, The opengl/texture warnings shouldn’t matter (for the sake of learning). Perhaps you have an old/unusual graphics card. Th demos should still work ok. The fon loading error does matter or you won’t see the font. This could be because the font is in the wrong folder, not unzipped or misspelt.
Hope this helps
Hello, I wrote your code line by line, and I keep getting this error message:
” Severity Code Description Project File Line Suppression State
Error C3867 ‘sf::Window::close': non-standard syntax; use ‘&’ to create a pointer to member HelloSFML c:\users\brandon\documents\visual studio 2015\projects\hellosfml\hellosfml\hellosfml.cpp 48 ”
and the line of code it is referring to is this :
” window.close; ”
Not sure what happened, I followed everything, and it lets me run the code if I let it run the “Last successful build”, Which I guess is when I simply copied and pasted your code, but not sure where I went wrong.
Nevermind. I am a dumbass. Couldn’t see the forset for the trees and was so focused on the overall code and how I set it up I completely missed the lack of ” () ” that should have come after. I guess a case of couldn’t see the trees for the forest eh?
By the way love your tutorials! The comments explaining the code and how you go through it line by line and step by step is by far one of the easiest for me to understand I have tried( After giving up on several). You make it easy for me to “get” the code! Keep up the good work!
Well done for solving this. This is a common typo error and it occurs because Visual Studio assumes that the function name is supposed to be a pointer. I have done this myself and scratched my head for a while before realizing the function call needs the brackets ().
Hi john. It keeps showing me this message .
Failed to load “28 Days Later”. (failed to create the font face)
I’ve re-downloaded and tried again but it didn’t work. What should I do?
Either the font name is misspelled in the code or the font is in the wrong folder.
The “Export template” option is not there when I open File… What do I do?
Hi Simon, Go back over the steps carefully. It is probably easier to start again. If the problem persists and your keen to get on with it you could simply create the project each time and skip the exporting step.
in VS community 2017 export template has moved to the “projects” menu.
so now Projects > Export Template .
in previous versions its an occasional install bug
Thanks for the information. I am going to update this to VS 2017 Community in about a month.
I’m having a lot of difficulty with just setting up Visual Studio right now. I just downloaded the 2017 Community Version of Visual Studio and now when I try to set up the first project, I don’t have Win32 showing up or anything installed yet. I don’t know what to install and how to install it. Much help needed ;-;
Hi Daniel,
Yes, they changed things around a bit. I have updated the previous tutorial to show how to install the correct options with Visual Studio 2017 for making SFML projects. I have also updated the subtle but confusing differences for creating a project with Visual Studio 2017 in this tutorial. The main difference is you choose Windows Desktop || Visual C++ then Console Application. The meat of the configuration from the section titled “The slightly dull (but important) configuration stuff” remains the same as far as I could tell.
Hope this helps,
John
The stdafx.h header file is missing in my HelloSFML directory. At which step did I made a mistake?
Not sure. But if it wasn’t auto-generated it might not be needed. Try removing the #include stdafx.d line of code. Does it run?
I have the same problem too, i tried commenting that line but it throws another error: LINK : fatal error LNK1104: cannot open file ‘sfml-graphics-d.lib’
Check the project configuration specifically where sfml-graphics-d.lib is referred to. Eg. is the folder where you have placed this file referred to exactly?
hello…i am getting this error “sfml-graphics-d.lib(sfml-graphics-d-2.dll) : fatal error LNK1112: module machine type ‘x64′ conflicts with target machine type ‘X86″ what should i do now????
You have probably downloaded the 64 bit sfml package. If you replace it with the 32 bit your projects should then run on any Windows pc and hopefully this error will be fixed.
when I run the code im getting this error – cannot open file ‘sfml-audio-d.libkernel32.lib’ and the code is LNK1104. also is it fine that i removed the #include “stdafx.h” part because its giving me this error ‘E1696 cannot open source file “stdafx.h”.’?
Hi, Yes, removing stdafx is fine if you don’t get any errors after doing so. The link errors could be caused either by the dll files not being present or the wrong dll files if you didn’t use the debug versions.
I put the dll files in C:\Visual Studio Stuff\Projects\HelloSFML\HelloSFML that I got from C:\SFML\bin so did I do anything wrong, also what do you mean by “debug versions”? heres some screenshots of my dll files
C:\SFML\bin – https://i.gyazo.com/5640923e55603d9a82e5537d1319de32.png, C:\Visual Studio Stuff\Projects\HelloSFML\HelloSFML – https://i.gyazo.com/b7a2b1efd3b770ef69b57a6ee47b3e7f.png.
Hi there, By debug versions I mean the ones with -d near the end. I can see from your image that both versions are in there so should be fine. I think I can see the error. I think you have missed a semicolon and a few letters between the last sfml addition and the existing items in the additional linker properties. Your
Check your project properties in Project|…Properties from the main menu and then select Linker>Input>Additional dependencies box. It should say the following.
…sfml-audio-d.lib;libkernel32.lib…
I think you might have mistyped it as sfml-audio-d.libkernel32.lib which could be causing the error.
thanks it worked!!
Really pleased!
Hi, I was really hoping to be able to learn something here but I can’t seem to get the setup to work. I am using Microsoft Visual Studio 2019 which i thought might be why it doesn’t work. However, I did try to build the SMFL library whatever in cMake but am very lost and confused. I can’t get the example code to run because I have no stfax.h file nor a SFML/Graphics.hpp file. If I do everything according to the tutorial using the SFML 2015 C++ download will it work for Visual Studio 2019? Sorry for the rambling this is my second day of not getting it to work and I’m rather muddled, any help would be awesome, thanks.
Hi Leif,
The tutorial was updated to VS2017 and for another publication I recently did a tutorial for VS2019 and everything is near-identical. One change is that stdafx.h is NOT needed by default so you can delete that. Regarding SFML/Graphics.hpp you do need that. I wonder if you missed the first step about acquiring SFML? Details here. http://gamecodeschool.com/sfml/setting-up-visual-studio-and-sfml-development-environment/.
Configuring your first project is a pain but once you have succeeded, hopefully you will make faster progress.
Thanks for the comment I hope this helps.
John
Hi John,
Thanks for the quick reply! I did indeed follow the first step of installing the SFML library and followed the steps to create a template that automatically included it in projects, however no SFML/Graphics.hpp app was in the folder (I searched), and without it, the sf namespace isn’t included so I get a bunch of errors using the code you provided. Do you have any suggestions, and would you be able to get me a link to the tutorial for VS2019 you did?
Thanks,
Leif
Hi Leif,
It sounds like something most likely went wrong in the first stage. My suggestion would be to start again and skip the step making the template. On reflection, it is probably better to get fammiliar configuring a project rather than saving a few minutes making a template. Just add the code to the file with the main function in it.
Im getting correct results when testing my c++ hello world app, but when i try to follow the steps for Configuration Properties i cant see a c++ option there.
Its just Configuration Properties, and under that, “Configuration”.
Any idea how i can see same options as in this guide?
I figured that one out, but now im stuck on no sf namespace.. trying to figure it out but its hard.
Yes configuration is a fiddle. Can you tell me a bit more about the problem or error you are getting and I’ll try and give yo a solution. Once you have configured a few projects it seems much easier.
After pasting the code I noticed I had a red line under #include “stdafx.h” so I commented it out and checked everything. I ran it and it work fine. But what is up with the header and is there something I can do to fix it or do I even need it
Yes. stdafx is no longer needed. When I wrote the tutorial wit vs2017(I think) default project used the file. If you want to know what it is then see this: https://stackoverflow.com/questions/4726155/what-is-stdafx-h-used-for-in-visual-studio
Thank you sir
I tried on the 2017 Community version and I am getting a lot of errors
Hi Nic.
Share the details and what you have tried so far and I will share any suggestions.
#include “SFML/Window.hpp”
#include
this worked for me not the std..
thank you for the starters…
#include “SFML/Window.hpp”
#include
Hello. When I run this code, I get error 0xc000007b. What to do?