Windows 10 上的 DirectX 11

DirectX 11 on Windows 10

我只是想学习 DirectX 11(不,我对 OpenGL 和 Vulcan 都不感兴趣)并且我使用的是最新的 Windows 10 insider build。我知道有 DirectX 12,但据我所知,对于非 (A)AA 来说,它带来的麻烦多于它的价值。我完全清楚,要启动游戏并 运行,使用像 Unreal Engine 这样的现有游戏引擎会更合适。但我对获得一个有效的游戏并不感兴趣。我只想要一些不贬值的好东西来代替 GDI(+)。无论如何,我一直想学习 DirectX。我正在使用 C++,顺便说一句,它可能是主要的编程语言。作为我的 IDE,我使用的是 Visual Studio 2017 Enterprise。我还应该补充一点,我熟悉 Windows API(以前称为 Win32 API)。

我可以访问 Allen Sherrod 和 Wendy Jones 的书 Beginning DirectX 11 Game Programming 和 Frank D. Luna 的书 Introduction to 3D Game Programming with DirectX 11。但两者都有一个主要问题:他们使用已贬值的 DirectX 11与 Windows 8 和 10 SDK 不兼容的 June SDK。虽然用 WinAPI 代码替换错误管理代码很容易,但我坚持使用:

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

CompileD3DShader 似乎不存在。我用谷歌搜索时运气不佳。但根据我的发现,我得出结论,他们不仅重命名了它,而且还用其他机制代替了它。虽然我不确定。谁能帮我用 Windows 8/10 兼容的方式写下那一行?

还有一个问题,如果我对使用旧的 DirectX SDK 不感兴趣,那些书还有用吗?我正在考虑寻找好的在线教程。如果没有足够好的,我将被迫切换到 Luna 的 DirectX 12 书籍和一般的 DirectX 12。不幸的是,似乎没有 DirectX 12 继任者开始 DirectX 11 游戏编程(有一本分别针对 DirectX 9 和 10 的书)我更喜欢(我更喜欢先学习 API 的基础知识,这样我以后就可以专注于数学了)。

有没有人知道学习 "modern" DirectX 11 的良好、全面的来源?我对书籍和在线内容(包括 YouTube 视频)持开放态度。

更新 1: 鉴于寻求有关替代学习的建议 material 似乎是不允许的(我忘记了,对此感到抱歉)我想强调我问题中最重要的部分。

为旧的 Direct X SDK 编写的书籍/在线教程是否仍然适用于 Windows 8 / 8.1 / 10 SDK?我知道我必须使用不同的 headers 并且有些东西已经 re-named 并且 DirectX 错误处理库已被删除。除了 DirectX 错误处理库,我是否可以只 re-name 一些函数和代码就可以工作,或者差异是否更大?

更新 2: 我发现了两个似乎更新的来源。虽然我必须让他们仔细看看,但我想 post 他们的链接,以供遇到与我相同问题并且无法通过 Google 找到正确答案的任何人: http://www.directxtutorial.com/Lesson.aspx?lessonid=111-4-1

https://msdn.microsoft.com/en-us/library/ee416804(v=VS.85).aspx

如果这些教程是最新的,我也许能弄清楚这两本书是否仍然有用。

关于 Direct3D 11 的所有各种书籍仍然适用于它们对核心 API、概念和如何使用 DirectX 11 的功能的覆盖。问题是由于他们使用现在旧版 DirectX SDK。值得注意的是 D3DX、D3DXMath 或 XNAMath,以及遗留效果系统的使用。也就是说,您最终还是要学习如何进行 Direct3D 图形编程。我有一个博客 post,其中详细介绍了各种书籍以及一些需要注意的事项。参见 Book Recommendations。自我提醒:我应该看看 Sherrod & Jones 的书并更新 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.

使用 Windows 8.1 SDK 或 Windows 10 SDK 时如何替换所有遗留 DirectX SDK 内容的完整指南是 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,这是一个很好的智能指针利用现代 Direct3D C++ 编程。

#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

学习 Direct3D 11 的其他有用的入门资源:

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