How to include Direct3D in a program?

2019-06-09 06:54发布

I am learning Direct3D from directxtutorial.com. I am including it through a preprocessor directive in the code below.

#pragma comment(lib, "d3d11.lib")
#pragma comment(lib, "d3dx11.lib")
#pragma comment(lib, "d3dx10.lib")

This is not doing it, however. I am guessing it is because the library files aren't where its checking to find them. But could someone explain what's going on here? Thanks. The error message is: "Intellisense: could not open source file"

标签: c++ direct3d
1条回答
对你真心纯属浪费
2楼-- · 2019-06-09 07:42

You'll need to download and install the Windows SDK from this link.

Next, you'll need to configure your solution in Visual Studio to look for the appropriate files. This may be broken down in to two categories: Adding the include paths and Linking the libraries. Please take note of your Windows SDK directory. On my system, it is C:\Program Files (x86)\Microsoft SDKs\Windows\7.0A\.

Adding include paths

Visual Studio comes pre-packed with a subset of the DirectX header .h files, but the complete collection is available in WindowsSDKPath\Include.

Add this path to your project's additional includes:

  • Right click the project in the Solution Explorer, and choose Properties from the menu:
  • Configure the dialog box to affect both Debug and Release builds: Visual C++ Property Pages
    • Select the first drop-down and choose All Configurations.
  • From the tree on the left, choose Configuration Properties | C/C++ | General. This option will only appear if you have at least one .c or .cpp file in your project.
  • In the Additional Include Directories box, add the path to your Windows SDK Includes, for example: C:\Program Files (x86)\Microsoft SDKs\Windows\7.0A\Include.
  • Press Apply.
  • You're now ready to include the Direct 3D header files in your C++ code files, i.e. #include <d3d11.h>.

Linking the libraries

The Direct 3D libraries are contained in the WindowsSDKPath\Lib folder.

  • From the tree on the left, choose Configuration Properties | Linker | Input.
  • Tick the arrow on the drop-down of the Additional Dependencies field, choose Edit...
  • In the pop-up dialog, add the full paths to each library, with each path on its own line, like so: Linking Direct 3D Libraries
  • Press Okay, then press Apply or Okay.

Your project should now be configured to build Direct 3D Applications.

查看更多
登录 后发表回答