How to Set Up SDL with Visual Studio 2017

Опубликовал Admin
13-10-2017, 11:00
133
0
Whether you're a novice C++ programmer or a veteran software developer graphics programming is an educational and rewarding experience. Simple DirectMedia Layer is a C library (compatible with C++) that allows simple, low-level access, to the graphics functionality of a variety of platforms. This guide will help you get over the first challenge of using SDL: installing and setting it up. This guide will assume you have already installed Visual Studio 2017. If you have not done so you can download it here. When you get to the workload selection screen start at step 3 in Configuring Visual Studio to select the correct workload. After completing parts 1 and 2 you will only need to complete part 3 each time you make a project.

Configuring Visual Studio

  1. Open the Visual Studio installer. You can find it under ‘V’ in the start menu or through search.
  2. Select the version you wish to use and select modify. If you did not pay for the software, it will be "Visual Studio Community 2017".
  3. Check the Desktop development with C++ workload box. The default options will be automatically selected on the right. These are what you want. If you have already installed a part of the C++ workload, check the summary box on the right to ensure you have at least the following optional components (version numbers may be different):
    • VC++ 2017 v141 toolset (x86,x64)
    • C++ profiling tools
    • Windows 10 SDK (10.0.15063.0) for Desktop C++
    • Visual C++ tools for CMake
    • Visual C++ ATL support
    • Note: Having other workloads or additional options from the C++ workload will not affect your ability to create SDL projects.

Downloading and Setting up SDL

  1. Download the SDL development libraries. They can be found at https://www.libsdl.org/download-2.0.php. Scroll to the bottom of the page and find Development Libraries. Download the version for Visual C++. It will be named something like SDL2-devel-2.0.6-VC.zip (Visual C++ 32/64-bit).
  2. Extract the zip file. Open File Explorer, go to where the file was downloaded (often your downloads folder). Right-click on the zip file and select Extract All. Make sure to note the location that your files are being extracted to.
  3. Create a new directory for the library. The downloads folder is not a good location for a library. Create a new directory for libraries in your location of choice. It's recommended to make a new folder on your C drive called Libraries CPP.
  4. Copy the contents of the library to the new directory and rename it. The name should be short, simple and have no spaces. It is recommended that you use SDL2. Make sure the folder immediately contains the docs, include, and lib directories. If it does not copy the extra folder to your libraries folder, delete the old SDL folder, and rename the folder you just copied to your preferred name.

Creating an SDL Project

  1. Open Visual Studio. Open the version of Visual Studio 2017 you configured in part 1. This is most likely community.
  2. Create an empty project. At the top of the window, click File then go to new > Project… In the left part of the new project window, locate the visual C++ dropdown menu. Click the text portion of the menu directly. In the center of the screen click Empty project. Below that find the name text box and enter a name for the project without spaces. This tutorial will use SDL-WH. Make sure the Create directory for solution box is not checked.
  3. Add your main file to the project. In the solution explorer window at the left side of the screen right click the Source Files folder. Click Add > New Item… Alternatively, you can use the hotkey Ctrl+⇧ Shift+A. In the Add New Item window click C++ file from the middle of the window. In the name text box type Main.cpp or another name without spaces if you prefer. Click the add button. The file will open in the main text editor but leave the file blank for now.
  4. Configure the general additional include directories. Right click on the name of your project and select properties. Open the C/C++ dropdown menu and click general. Click the bank field immediately to the right of the Additional Include Directories entry and click the down arrow at the right of the field. Click <edit> in the dropdown menu.
  5. Add the include folder. At the top of the Additional Include Directories window, click the brown folder icon. Click the three dots next to the text box that is created. In the Select Directory window, navigate to the location you saved the SDL library then click the include folder. Click Select Folder on the Select Directory window and OK on the Additional Include Directories window.
  6. Configure the linker additional library directories. Open the Linker dropdown menu and click General. Click the bank field immediately to the right of the Additional Include Directories entry and click the down arrow at the right of the field. Click <edit> in the dropdown menu.
  7. Add the lib/x86 folder. At the top of the Additional Include Directories window, click the brown folder icon. Then click the three dots next to the text box that is created. In the Select Directory window, navigate to the location you saved the SDL library then click the lib folder followed by the x86 folder. Then click select folder on the Select Directory window and OK on the Additional Include Directories window.
  8. Configure the linker additional dependencies. Open the Linker dropdown menu and click input. Click the bank field immediately to the right of the Additional Dependencies entry and click the down arrow at the right of the field. Click <edit> in the dropdown menu.
  9. Add the two library files. In the top-most text box type SDL2.lib and hit Enter. Then type SDL2main.lib. Click OK on the Additional Dependencies window.
  10. Configure the linker subsystem to console. In the linker dropdown menu, click System. Click the black field to the right of SubSystem. Click the down arrow and select console from the dropdown menu. Click apply then OK on the Property Pages window.
  11. Copy the SDL2.dll file from lib/x86 to your main project file. Navigate to your SDL2 directory in file explorer. Navigate further to lib/x86. Select SDL2.dll and right click then select copy. Navigate to your Visual Studio 2017 folder. This is usually found in your documents library unless you chose a different directory when you created the project. Navigate to Projects then the folder with the same name as your project. Right-click an empty area after the list of files and select Paste. The SDL2.dll file should now be in your project directory along with your Main.cpp file and a few other files created by Visual Studio.
  12. Test your project. Copy paste the following code into your Main.cpp file. Click the Local Windows Debugger button next to the green arrow at the top of the screen. If the project builds and the console prints "SDL initialization succeeded!" then the project was set up correctly. You are now ready to program with SDL!

Tips

  • Learn more about SDL at the official website: https://www.libsdl.org.
Теги:
Information
Users of Guests are not allowed to comment this publication.
ТОП Комментарии
How to Germinate Tree Seeds
Plant Propagation Techniques
How to Grow Cactus Indoors
Growing Succulents and Cacti
How to Gauge Your Ears
Ear Piercing
How to Mount an ISO Image
Computers and Electronics
How to Make Dalia
Basic Cooking Skills