This tutorial is part of a Collection: 04. DirectX 12 - Braynzar Soft Tutorials
rate up
1
rate down
6507
views
bookmark
01. Setting up DirectX 12 for Visual Studio 2015

This tutorial will teach you how to set up a Visual Studio 2015 project with DirectX 12

56 downloads
##Requirements## DirectX 12 is Windows 10 exclusive. So the first thing you will need is a windows 10 machine. **Downloads** You will need an IDE to develop the DirectX 12 app. I use Visual Studio 2015. You can download the community version for free: .[https://www.visualstudio.com/en-us/products/vs-2015-product-editions.aspx][https://www.visualstudio.com/en-us/products/vs-2015-product-editions.aspx] Make sure to select Custom Installation when installing, and select the C++ options, because they are deselected by default. Otherwise you'll only be able to make C# projects with VS2015. Next you will need the Windows 10 SDK, which you can download from here: .[https://dev.windows.com/en-us/downloads/windows-10-sdk][https://dev.windows.com/en-us/downloads/windows-10-sdk] ##Setting up Visual Studio 2015## Open VS2015. +[http://www.braynzarsoft.net/image/100173][VS2015] Go to File->new->Project... It will open a new window titled "New Project" +[http://www.braynzarsoft.net/image/100174][New Project] Select Win32 Project. Give the project a name and click "OK" +[http://www.braynzarsoft.net/image/100175][Win32 Project] It will open up a Win32 Application Wizard. Click "Next >" +[http://www.braynzarsoft.net/image/100176][Win32 Application Wizard] On the next screen, check "Empty project" and deselect "Security Development Lifecycle (SDL) checks", then click "Finish" +[http://www.braynzarsoft.net/image/100177][Application Settings] Now we need to include the directx 12 headers and libraries. Now you can either develop a x86 application or a x64 application. x86 applications have a maximum 2GB of memory (RAM) usage, but will work on both x64 and x86 platforms. x64 applications can top out at 1TB of memory (RAM) usage, and can perform faster than x86, but will only run on x64 platforms. Pretty much all newer systems nowdays are 64-bit, and i'm not even really sure if you can buy a x86 system from Best Buy anymore, which is why i suggest we go for the x64 setup. In the toolbar at the top, click on the dropdown that says "x86" and select "x64" +[http://www.braynzarsoft.net/image/100180][Change to 64-bit] **Includes/Libraries** Open the solution Explorer if it is not already open. You can either open the solution explorer by clicking "View->Solution Explorer" or by pressing "Ctrl+Alt+L" +[http://www.braynzarsoft.net/image/100178][Solution Explorer] Right click the project and select "Properties". A new window will pop up. On the left panel, click "VC++ Directories". On the right panel, click "Include Directories", and click on the down arrow on the right side of the row, and click "<Edit...>" a new window will pop up. +[http://www.braynzarsoft.net/image/100182][Includes] Click the folder icon at the top, then click the "..." in the line that appears. +[http://www.braynzarsoft.net/image/100183][Include D3D12 includes] A file explorer will open up. This is where we will need to include the direct3d 12 headers. The two locations we will be including are: Windows Kits->10->Include->{version}->shared Windows Kits->10->Include->{version}->um Visual Studio 2015 comes with Windows 10 SDK, however i found the "shared" and "um" folders were missing from that version of the SDK, which was version "10.0.10.150.0" After installing the latest version of Windows 10 SDK, the includes on my system were located: C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\shared C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\um the shared and um folders are what you might consider traditional windows sdk header files. The shared folder includes "dxgi1_4.h" which we will use for some things like the swapchain. You can find an overview of DXGI .[https://msdn.microsoft.com/en-us/library/windows/desktop/bb205075(v=vs.85).aspx][here]. The um folder contains the directx 12 headers, such as "d3d12.h, "d3dcompiler.h and "d2d12sdklayers.h" (used for debugging) Now add the two directories and click "OK" +[http://www.braynzarsoft.net/image/100184][Include shared and um] Click on "Library Directories" and then the down arrow on the right side of the row, then edit to open up the libraries directories. +[http://www.braynzarsoft.net/image/100185][Library directories] Click the folder icon at the top and then the "..." that appears on the new line to open the file browser again. Navigate to "Windows Kits->10->Lib->{version}->um->x64" then click "Select Folder" On my system it was: C:\Program Files (x86)\Windows Kits\10\Lib\10.0.10240.0\um\x64 Now click "OK" to close the Library directories window. On the left panel expand "Linker" and click on "Input". On the right panel click on "Additional Dependencies" and click the down arrow on the right side of the row. We need to link the d3d and dxgi static libraries. Enter the following into the box that pops up: d3d12.lib dxgi.lib d3dcompiler.lib +[http://www.braynzarsoft.net/image/100186][d3d libs] Click "OK" again to close the properties window. ##DirectX Math## We will be using the DirectX Math Library for all the math involved in the tutorials. DirectX Math is what Microsoft recommends us to use. ##d3dx12.h## .[https://msdn.microsoft.com/en-us/library/windows/desktop/dn708058(v=vs.85).aspx][Helper Structures and Functions for D3D12] We will be using the open source d3d12 helper functions and structures provided by Microsoft. This file does not come with the windows sdk, so you will have to download this separately. Open the "Solution Explorer" and right click on "Header Files", then click "Add->New Item...". In the pop up, select "Header File (.h)", name it "d3dx12.h" and click "Add". Go .[https://github.com/Microsoft/DirectX-Graphics-Samples/blob/master/Samples/Desktop/D3D12HelloWorld/src/HelloTriangle/d3dx12.h][here], copy the code and paste it into the new "d3dx12.h" file you just created and save it. ##stdafx.h## The stdafx.h file is a common filename for a "grouping" of all headers and code that doesn't change often. The way i've decided to do these tutorials is how i've done them in the past. Basically without the use of classes and multiple files so there is less jumping around and it's more straight to the point. of course in a real application, you will have your code more organized and modular, but again for the sake of hopeful clarity, i have everything together. I will use the "stdafx.h" file for all includes, declarations of functions, and declarations and definitions of variables and structures. "Main.cpp" will have all the definitions of the functions. Lets start with the includes we will need throughout the tutorials: **stdafx.h** #pragma once #ifndef WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers. #endif #include <windows.h> #include <d3d12.h> #include <dxgi1_4.h> #include <D3Dcompiler.h> #include <DirectXMath.h> #include "d3dx12.h" ##Create the Main.cpp file## Open the "Solution Explorer" Right click on the "Source Files" folder. Select "Add->New Item...". A window will pop up. On the left side of the window is the different project types. Click "Visual C++". In the next section is the different file types. Select "C++ File (.cpp)", and name the file "main.cpp", then click "Add" Now we need to include "stdafx.h" and create the winmain function #include "stdafx.h" int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int nCmdShow) { return 0; } Your project is ready for development!
Comments
Hey! Great work with the tutorials and thank you very much! Just noticed taht the GitHub link in this sentence "Go here, copy the code and paste it into the new "d3dx12.h" file you just created and save it." is dead. Could you fix it? :/
on Feb 22 `16
Ninglin
Oh yeah, I'll fix of tomorrow, thanks for letting me know!
on Feb 22 `16
iedoc
Really Nice tutorial. But also please take note that the standard windows sdk for windows 10 does not come with directx header/cpp files, only runtime libraries. I had to download the windows sdk 10(10.0.10586.0 at time of this writing) to get all the development related files. The sdk installed with windows 10 does not include these files.
on Jul 31 `16
dx12multicore
ah thanks for mentioning that dx12multicore!
on Jul 31 `16
iedoc
I know this was submitted quite awhile ago so perhaps there have been some changes since then. I am "extremely" new to direct x in general let alone direct x 12, in saying that I mean that direct x 12 is the first time I have touched direct x. Needless to say I tried compiling your code after I was done with this tutorial and got 2 errors for lines 268 and 269 in the // Unit conversion section: // Unit conversion inline XM_CONSTEXPR float XMConvertToRadians(float fDegrees) { return fDegrees * (XM_PI / 180.0f); } inline XM_CONSTEXPR float XMConvertToDegrees(float fRadians) { return fRadians * (180.0f / XM_PI); } both producing this error: constexpr function return is non-constant Not sure whats going on so I thought posting this would help find this answer.
on Aug 22 `16
plasmasnakeneo
Oh I forgot to mention this is within the DirectXMath.h header file which made it seem even stranger since this header file was never even touched.
on Aug 22 `16
plasmasnakeneo
@plasmasnakeneo, I just figured this error with retargeting the sdk version to an older one.
on Sep 21 `16
x5lcfd