[DF]
[Dragonfly]

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 2.6.* and Microsoft Visual Studio version 17 (2022).

  1. Open Visual Studio.

  2. Create a new Project

    1. From the menu:

      "File" → "New" → "Project"
      "Empty Project"
    2. Fill out information:

      Name: "Whatever you want"
      Location: "Wherever you want"
      Solution: "Create new solution"
      Solution name: "Whatever you want"
    3. 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++.

    4. Click "Finish"

  3. Set the compiler/linker settings for SFML:

    1. 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"
    2. Select:

      "VC++ Directories"
      "Include Directories" → (Dropdown arrow) → "Edit"
      Click top line, then "..." button on right. Use file browser to add:
      (Directory where extracted SFML)\include
      e.g.,..\..\SFML-2.6\include

      If linking in Dragonfly (versus developing Dragonfly), on the next line, also add:

      (Directory where extracted dragonfly)\include
      e.g., ..\..\dragonfly\include

      Click "OK"
      Set Configuration in the top left drop-down to:

      "Debug"
    3. Select:

      "Library Directories" → (Dropdown arrow) → "Edit"
      Click top line, then "..." button on right. Use file browser to add:
      (Directory where extracted SFML)\lib
      e.g., ..\..\SFML-2.6\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"

    4. Select:

      "Linker" → "Input" → "Additional Dependencies" → (Dropdown arrow) → "Edit"
      Add:
      sfml-system-d.lib
      sfml-window-d.lib
      sfml-graphics-d.lib
      sfml-main-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. See: SFML and Visual studio for details.

  4. Create program to build. Menu:

    "View" → "Solution Explorer"
    (Expand Project name)
    Right click "Source Files" → "Add" → "New Item"
    Select:
    "Installed" → "Visual C++"
    "C++ File (.cpp)"
    Fill out information:
    Name: "game.cpp"
    Location: (leave as-is)
    Click "Add"

    Do ONE of the below options:

    1. If linking in Dragonfly (versus developing Dragonfly), paste in the below code:
      //
      // 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();
      }
      
    2. If developing Dragonfly (versus linking in Dragonfly), paste in the below code:
      #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())
          {
              sf::Event event;
              while (window.pollEvent(event))
              {
                  if (event.type == sf::Event::Closed)
                      window.close();
              }
      
              window.clear();
              window.draw(shape);
              window.display();
          }
      
          return 0;
      }
      
  5. 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)

  6. Ensure access to SFML DLLs. To do this, do ONE of the below options:

    1. Copy all DLL files:

      (Directory where extracted SFML)\bin\*.dll
      to the directory with the .exe just built (e.g., saucer-shoot\Debug).
    2. Go to project properties:

      "Menu" → "Project" → "Properties"
      Then:
      "Configuration Properties" → "Debugging"
      "Environment" → (Dropdown arrow) → "Edit"
      Add:
      PATH=%PATH%;(Directory where extracted SFML)\bin;
      e.g., PATH=%PATH%;..\..\SFML-2.6\bin;

      Click "OK"

  7. (Optional) Change the working directory when running:

    Go to project properties:

    "Menu" → "Project" → "Properties"
    Then:
    "Configuration Properties" → "Debugging"
    "Working Directory" → (Dropdown arrow) → "Browse"
    Use file browser to select the directory where the application .exe is (e.g., $(ProjectDir)\x64\Debug)

    Click "OK"

  8. 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
  9. Run (press F5).

Home Engine Games Tutorial Docs Book Notes

Copyright ©2024, Mark Claypool (claypool [at] cs.wpi.edu) and WPI. All rights reserved.