![]() |
![]() |
Dragonfly with Visual Studio v17 (2022) |
Home | Engine | Games | Tutorial | Docs | Book | Notes |
This is a setup guide for configuring Microsoft Visual Studio to use and develop Dragonfly. This setup guide is good as of SFML version 3.0.0 and Microsoft Visual Studio version 17 (2022).
Open Visual Studio.
Create a new Project
From the menu:
"File" → "New" → "Project"
"Empty Project"
Fill out information:
Name: "Whatever you want"
Location: "Wherever you want"
Solution: "Create new solution"
Solution name: "Whatever you want"
Click "Create"
Note, if needed in the future, there are directions for
Changing
a Windows App to a Console App in Visual Studio
Another note, to keep the console window open after the program
ends, run with ctrl-F5 (instead of just F5). Other suggestions are
available how-to-keep-the-console-window-open-in-visual-c++.
Click "Finish"
Set the compiler/linker settings for SFML:
Menu:
"Project" → "Properties"Select:
"Configuration Properties"Set Configuration in the top left drop-down to:
"All Configurations"Set Platform in the top center drop-down to:
"All Platforms"
Select:
"VC++ Directories"Click top line, then "..." button on right. Use file browser to add:
"Include Directories" → (Dropdown arrow) → "Edit"
(Directory where extracted SFML)\includee.g.,
..\..\SFML-3.0\include
If linking in Dragonfly (versus developing Dragonfly), on the next line, also add:
(Directory where extracted dragonfly)\includee.g.,
..\..\dragonfly\include
Click "OK"
Set Configuration in the top left drop-down to:
"Debug"
Select:
"Library Directories" → (Dropdown arrow) → "Edit"Click top line, then "..." button on right. Use file browser to add:
(Directory where extracted SFML)\libe.g.,
..\..\SFML-3.0\lib
If linking in Dragonfly (versus developing Dragonfly), on the next line, also add:
(Directory where extracted dragonfly library)e.g.,
..\..\dragonfly\lib
Make sure to have "Inherit from parent or project defaults"
checked (tip: this may be the problem if you get the
message: cannot open file 'Winmm.lib'
).
Click "OK"
Select:
"Linker" → "Input" → "Additional Dependencies" → (Dropdown arrow) → "Edit"Add:
sfml-system-d.lib
sfml-window-d.lib
sfml-graphics-d.lib
sfml-audio-d.lib
sfml-network-d.lib
Winmm.lib
Ws2_32.lib
If linking in Dragonfly (versus developing Dragonfly), also add:
libdragonfly-x64-debug.lib(Adjust the name to the version of the library appropriate for the build). Click "OK"
Note! Changing from "Debug" to "Release" requires different SFML libraries for linking.
Set C++ standard for completion:
"Configuration Properties" → "General" → "C++ Language Standard"Select:
ISO C++17 Standard (/std:c++17)
(optional) Suppress realtime warning:
"Configuration Properties" → "C/C++" → "Advanced" → "Disable Specific Warnings"Enter:
4275
Create program to build.
Menu:"View" → "Solution Explorer"Select:
(Expand Project name)
Right click "Source Files" → "Add" → "New Item"
"Installed" → "Visual C++"Fill out information:
"C++ File (.cpp)"
Name: "game.cpp"Click "Add"
Location: (leave as-is)
Do ONE of the below options:
// // game.cpp // // Engine includes. #include "GameManager.h" #include "LogManager.h" int main(int argc, char *argv[]) { // Start up game manager. df::GameManager &game_manager = df::GameManager::getInstance(); if (game_manager.startUp()) { df::LogManager &log_manager = df::LogManager::getInstance(); log_manager.writeLog("Error starting game manager!"); game_manager.shutDown(); return 0; } // Show splash screen. df::splash(); // Shut everything down. game_manager.shutDown(); }
#include <SFML/Graphics.hpp> int main() { sf::RenderWindow window(sf::VideoMode({200, 200}), "SFML works!"); sf::CircleShape shape(100.f); shape.setFillColor(sf::Color::Green); while (window.isOpen()) { // See if window has been closed. while (const std::optional<sf::Event> p_event = window.pollEvent()) { if (p_event -> is<sf::Event::Closed>()) window.close(); } window.clear(); window.draw(shape); window.display(); } return 0; }
Set main()
as a starting point.
If the project created is a "Console App", you can already
use main()
as an entry point (start) for your
program. If you used an "Empty Project" you cannot - SFML 3.0.0
does not have entry to main()
defined. You can do
so with something similar to:
// Since SFML 3.0 doesn't seem to have win-main-d.lib, // define it here. #if defined(_WIN32) || defined(_WIN64) #include <Windows.h> int main(); // Prototype int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { return main(); } #endif
Build (ctrl-shift-B).
Warnings about "PDB" files not found can be ignored
If linking in Dragonfly (versus developing Dragonfly), copy
"df-font.ttf" to the directory with the .exe just built
(e.g., (Project name)\Debug
)
Ensure access to SFML DLLs. To do this, do ONE of the below options:
Copy all DLL files:
(Directory where extracted SFML)\bin\*.dllto the directory with the .exe just built (e.g.,
saucer-shoot\Debug
).
Go to project properties:
"Menu" → "Project" → "Properties"Then:
"Configuration Properties" → "Debugging"Add:
"Environment" → (Dropdown arrow) → "Edit"
PATH=%PATH%;(Directory where extracted SFML)\bin;e.g.,
PATH=%PATH%;..\..\SFML-3.0\bin;
Click "OK"
(Optional) Change the working directory when running:
Go to project properties:
"Menu" → "Project" → "Properties"Then:
"Configuration Properties" → "Debugging"Use file browser to select the directory where the application .exe is (e.g.,
"Working Directory" → (Dropdown arrow) → "Browse"
$(ProjectDir)\x64\Debug
)Click "OK"
Compile via:
"Build" → "Build Solution"If compilation works fine, proceed to the next step.
But, if you get a compiler error in an SFML file called
"Rect.inl" that is similar to '(': illegal error on right side
of token '::')
, fix it by adding a preprocessing directive.
Go to project properties:
"Menu" → "Project" → "Properties"Then:
"C/C++" → "Preprocessor" → "Preprocessor Definitions" → (Dropdown arrow) → "Edit"Add:
NOMINMAX
Do "Build" → "Clean solution"and then build again. Alternatively, you can delete the offending file, "Rect.inl". It should be under the directory: SFML source
/include/SFML/Graphics/Rect.inl
Run (press F5).
Home | Engine | Games | Tutorial | Docs | Book | Notes |