Sfml Visual Studio Code

broken image


Recently I changed my setup from macOS to Windows, and I'd like to do some experiments with GameDev in Windows. So one of the first things that I did was try to set up my dev environment and test some SDL2 code.

Visual Studio is an Integrated Development Environment (IDE) from Microsoft. It is the app that will allow us to enter our C code, compile it and then link it with the SFML code to make our games. Creating the simple game engine project in Visual Studio. To get started we need to create a new project in Visual Studio, complete with all the required properties to work with SFML. If you haven't completed the Building your first SFML game project you will need to do that first in order for the next steps to work. Apr 21, 2021 How to Set Up SFML in a Project on Visual Studio. Setting up SFML in Visual Studio 2017 or 2019 is similar to setting up SDL, freeGLUT, and GLEW, with two peculiarities: there are 29.lib files and 11.dll files. SFML and Visual Studio Introduction. This tutorial is the first one you should read if you're using SFML with the Visual Studio IDE (Visual C compiler). It will explain how to configure your SFML projects. Installing SFML. First, you must download the SFML SDK from the download page.

Tutorial

This is a simple guide to how to setup SDL2 with Visual Studio Code and mingw64, for me worked and I hope that you can start with SDL2 in Windows.

Sfml Visual Studio Code

Installing the tools.

The first thing that we need to install is Visual Studio Code editor. Download, install, and launch VS Code.

You need to install the C/C++ plugin from Microsoft.

Now, you need to install mingw64 to use the compilers that are included like g++, if you want to use the Visual Studio compiler, you can change some of the settings here but for now we continue with mingw64.

For easy installation, use the MinGW-W64 Online Installer, take note of the path where you installed your compiler, because we're going to need it in the configuration.

Note: Be sure that you are added the bin directory of MinGW to your Windows PATH. If you don't do this step, VS Code won't be able to find the proper tools!

Now, we need to download SDL2. For our case, we have to download the Development libraries for MinGW

And download the Runtime libraries to run our games.

We are going to use the x64 version. Unzip those folders in a location that you can find because we are going to need it.

Creating the SDL2 project

Now we are ready to start our SDL2 project. Create a folder for your project and open it with VSCode. Inside the folder, create another called src, here is where are going to save our code files. For our SDL2 and C++ configuration, create a .vscode folder. For the output of our compilation, create a build folder. Your editor should be like this

The first thing that we need to create is our Task to compile our code. In the .vscode folder, create a new file and name it tasks.json. Inside the file, write the following configuration.

label option is the name in which we are going to identify our task.

In the command option, we need to put the path to our g++ installation, that is where we install mingw64.

In the args options, we have some arguments that are important to notice. For example, 'buildgame.exe', is the name of our game and the folder where we're going to save it.

'-ID:/sdk/sdl2/mingw/x86_64/include' is where we save our SDL2 files, this is for SDL2 include libraries, the same as '-LD:/sdk/sdl2/mingw/x86_64/lib', is the path to SDL2 libraries.

'-lmingw32' is an option to compile with the mingw libraries, besides that said 32, we're are using the 64 bits compiler. '-lSDL2main',
'-lSDL2',
'-mwindows'
in this case, we are indicating to our compiler that we need to include the SDL2main and SDL2 libraries and we don't want the command prompt when launching our game.

Now, we need to create a launch.json file to launch our game and debugging.

'program': '${workspaceFolder}buildgame.exe', is the executable that we are going to launch, in our case is the same that our game.

'miDebuggerPath': 'D:sdkmingw-w64x86_64-8.1.0-posix-seh-rt_v6-rev0mingw64bingdb.exe' is the path where gdb.exe is.

When a young Mary McAleese told a priest that she planned to become a lawyer, the priest dismissed the idea: she knew no one in the law, and she was female. The reality of what she went on to achieve - despite those obstacles, and despite a sectarian attack that forced her family to flee their home - is even more improbable. In this luminous memoir, Mary McAleese traces that astonishing arc: from the tight streets of north Belfast. Mary McAleese's Here's The Story: A Memoir is out now, via Penguin Ireland. Here's The Story tells the true rags-to -riches tale of the indomitable former Irish president who, during her. Mary mcaleese heres the story. Mary McAleese was born in Belfast in 1951. In 1975 she was appointed Reid Professor of Law at Trinity College Dublin, and in 1987 she became Director of the Institute of Professional Legal Studies at Queen's University Belfast. She was elected President of Ireland in 1997, and re-elected unopposed in 2004.

How to install sfml
Sfml

This is a simple guide to how to setup SDL2 with Visual Studio Code and mingw64, for me worked and I hope that you can start with SDL2 in Windows.

Installing the tools.

The first thing that we need to install is Visual Studio Code editor. Download, install, and launch VS Code.

You need to install the C/C++ plugin from Microsoft.

Now, you need to install mingw64 to use the compilers that are included like g++, if you want to use the Visual Studio compiler, you can change some of the settings here but for now we continue with mingw64.

For easy installation, use the MinGW-W64 Online Installer, take note of the path where you installed your compiler, because we're going to need it in the configuration.

Note: Be sure that you are added the bin directory of MinGW to your Windows PATH. If you don't do this step, VS Code won't be able to find the proper tools!

Now, we need to download SDL2. For our case, we have to download the Development libraries for MinGW

And download the Runtime libraries to run our games.

We are going to use the x64 version. Unzip those folders in a location that you can find because we are going to need it.

Creating the SDL2 project

Now we are ready to start our SDL2 project. Create a folder for your project and open it with VSCode. Inside the folder, create another called src, here is where are going to save our code files. For our SDL2 and C++ configuration, create a .vscode folder. For the output of our compilation, create a build folder. Your editor should be like this

The first thing that we need to create is our Task to compile our code. In the .vscode folder, create a new file and name it tasks.json. Inside the file, write the following configuration.

label option is the name in which we are going to identify our task.

In the command option, we need to put the path to our g++ installation, that is where we install mingw64.

In the args options, we have some arguments that are important to notice. For example, 'buildgame.exe', is the name of our game and the folder where we're going to save it.

'-ID:/sdk/sdl2/mingw/x86_64/include' is where we save our SDL2 files, this is for SDL2 include libraries, the same as '-LD:/sdk/sdl2/mingw/x86_64/lib', is the path to SDL2 libraries.

'-lmingw32' is an option to compile with the mingw libraries, besides that said 32, we're are using the 64 bits compiler. '-lSDL2main',
'-lSDL2',
'-mwindows'
in this case, we are indicating to our compiler that we need to include the SDL2main and SDL2 libraries and we don't want the command prompt when launching our game.

Now, we need to create a launch.json file to launch our game and debugging.

'program': '${workspaceFolder}buildgame.exe', is the executable that we are going to launch, in our case is the same that our game.

'miDebuggerPath': 'D:sdkmingw-w64x86_64-8.1.0-posix-seh-rt_v6-rev0mingw64bingdb.exe' is the path where gdb.exe is.

When a young Mary McAleese told a priest that she planned to become a lawyer, the priest dismissed the idea: she knew no one in the law, and she was female. The reality of what she went on to achieve - despite those obstacles, and despite a sectarian attack that forced her family to flee their home - is even more improbable. In this luminous memoir, Mary McAleese traces that astonishing arc: from the tight streets of north Belfast. Mary McAleese's Here's The Story: A Memoir is out now, via Penguin Ireland. Here's The Story tells the true rags-to -riches tale of the indomitable former Irish president who, during her. Mary mcaleese heres the story. Mary McAleese was born in Belfast in 1951. In 1975 she was appointed Reid Professor of Law at Trinity College Dublin, and in 1987 she became Director of the Institute of Professional Legal Studies at Queen's University Belfast. She was elected President of Ireland in 1997, and re-elected unopposed in 2004.

'preLaunchTask': 'SDL2' before launch our program, we need to run the task 'SDL2', this is the name that we put in the label option in tasks.json.

Now, as the last configuration step, we need to configure our C++ options to have a better Intellisense autocomplete and configuration of our compiler.

In Visual Studio Code, press CTRL + SHIFT + P, write C/C++ and select C/C++ Edit configurations (GUI). Here we're are going to change some configurations.

In Compiler Path, you need to put the path to your compiler. Like we put in the tasks.json and change the IntelliSense mode to gcc_x64. In Include Path, add the path to your SDL2 includes.

Other options that you may change are C Standard and C++ Standard, If you save these configurations, you are going to have a file named c_cpp_properties.json in your .vscode folder.

Now, you need to put the SDL2.dll file in the build folder, to be able to run our SDL2 game.

Sfml Vscode

Remember to use the version of your game

Testing our SDL2 game.

Visual Studio

Create a main.cpp file in the src folder to test our environment, and write the next code

Press F5 and cross your fingers. You should watch a red window, is you see it, then you are ready to work with SDL2 and VS Code!

Sfml Download

This is a simple configuration for start with SDL2, if you want to use SDL_image, you should do the same steps to add the headers and libraries. I will continue with SDL2 and check if with this configuration can be have some problems, but for now, you are able to start working with SDL2.





broken image