Reputation: 21
https://github.com/rdunnington/d3d12-hello-triangle
I found this example and decided to compile it in C/C++ project in visual studio, created new project, imported directx 12 sdk with Nuget and Ctrl+C/Ctrl+V main.c from this project. And 80% of d3d12 calls and identifiers are undefined. Why? How to build it properly?
Upvotes: 0
Views: 365
Reputation: 41067
The problem here is that the code sample you found is using "C" and not "C++". It's also building as "MBCS" rather than "UNICODE".
If you name the source file 'main.c' in Visual C++ and set the Project Properties Advanced -> Character Set to "Use Multi-Byte Character Set" it compiles as "C". You then have to add d3dcompiler.lib
, d3d12.lib
, dxguid.lib
, and dxgi.lib
to the Linker Additional Dependencies, then it will link assuming you have a "Windows Project" instead of a "Console Project".
That said, it's not a very good sample to start with unless you really want to use "C". All the Developer Education around DirectX 12 including samples, helper libraries, and docs assume you are using C++.
I'd recommend instead you take a look at the official GitHub samples, and the DirectX Tool Kit for DX12 tutorials. There's also some basic DirectX12 samples here.
Upvotes: 1