c++winapiwindows-10directx-11

DirectX 11 on Windows 10


I am trying to learn DirectX 11 and I am using the latest Windows 10 insider build. I am using C++. As my IDE, I am using Visual Studio 2017 Enterprise.

I have access to Allen Sherrod's and Wendy Jones's book Beginning DirectX 11 Game Programming and Frank D. Luna's book Introduction to 3D Game Programming with DirectX 11. But there is a major problem with both: They use the depreciated DirectX 11 June SDK which is incompatible with both the Windows 8 and 10 SDKs. While it is easy to replace the error management code with WinAPI code, I am stuck with:

bool compileResult = CompileD3DShader( "SolidGreenColor.fx", "VS_Main", "vs_4_0", &vsBuffer );

CompileD3DShader seems to be non existent. I hadn't much luck with Googling it. But from what I have found, I have concluded, that they have not just renamed it, but replaced it by some other mechanism. Though I am not sure about it. Could anyone help my write that line in an Windows 8/10 compatible way?

And another question, are those books of any use, provided I am not interested in using the old DirectX SDK?

Does anybody know a good, comprehensive source to learn "modern" DirectX 11? I am open to both books and online content (including YouTube videos).

Are books / online tutorials written for the old Direct X SDK still applicable for Windows 8 / 8.1 / 10 SDKs? I know that I have to use different headers and that some things have been re-named and that the DirectX Error Handling Library has been removed. Apart from the DirectX Error Handling Library, can I just re-name some functions and the code will work or are the differences more substantial?


Solution

  • All the various books on Direct3D 11 are still applicable in their coverage of the core API, the concepts, and functionality of how to use DirectX 11. The problems come in due to their use of the now legacy DirectX SDK. Notably D3DX, D3DXMath or XNAMath, and use of the legacy Effects system. That said, you still end up learning how to do Direct3D graphics programming. I've got a blog post that goes into some detail on the various books with some notes of things to watch out for. See Book Recommendations. Note to self: I should take a look at the Sherrod & Jones book and update the post.

    See Where is the DirectX SDK (2015 Edition)? and in particular MSDN on the proper method for 'mixing' the Windows 8.1/10 SDK with the legacy DirectX SDK if you still want to use the older stuff for learning.

    A complete guide to how to replace all the legacy DirectX SDK stuff when using the Windows 8.1 SDK or Windows 10 SDK is Living Without D3DX. You'll note for the shader compilation API, it links to HLSL, FXC, and D3DCompile. As someone noted in the comments, CompileD3DShader is just some helper function provided by the book author. These days you can just call D3DCompileFromFile. I'm also using Microsoft::WRL::ComPtr which is a good smart-pointer to make use of with modern Direct3D C++ programming.

    #include <d3d11.h>
    #include <d3dcompiler.h>
    #include <wrl/client.h>
    
    using Microsoft::WRL::ComPtr;
    

    ...

    ComPtr<ID3DBlob> shaderBlob;
    ComPtr<ID3DBlob> errorBlob;
    HRESULT hr = D3DCompileFromFile( L"SolidGreenColor.fx",
        nullptr,
        D3D_COMPILE_STANDARD_FILE_INCLUDE,
        "VS_Main", "vs_4_0",
        0 /* You probably want to use D3DCOMPILE_DEBUG in debug builds */,
        0,
        shaderBlob.GetAddressOf(),
        errorMsg.GetAddressOf()));
    
    #ifdef _DEBUG
    if (errorBlob) 
    { 
        OutputDebugStringA( reinterpret_cast<const char*>( errorBlob->GetBufferPointer() ) ); 
    } 
    #endif
    
    if (FAILED(hr))
        // Error condition
    

    Other useful starting resources for learning Direct3D 11:

    DirectX Tool Kit tutorials
    Getting Started with Direct3D 11
    Anatomy of Direct3D 11 Create Device