c++ - D3DX11CompileFromFile 无效参数 C++

标签 c++ directx

我可能忽略了一些简单的事情,但是着色器编译调用的编译声称没有重载函数的实例,尽管代码在其他项目中工作。

//Globals
IDXGISwapChain *swapChain;          //Pointer to the swapchain interface
ID3D11Device *dev;                  //Pointer to the Direct3D Device interface
ID3D11DeviceContext *devcon;        //Pointer to the Direct3D Device context
ID3D11RenderTargetView *backBuffer;

//Shaders
ID3D11VertexShader* pVS;
ID3D11PixelShader* pPS;

void InitPipeline()
{
//Load and Compile Shaders
ID3D10Blob *VS;
ID3D10Blob *PS;

D3DX11CompileFromFile(L"shader.shader", 0, 0, "VShader", "vs_4_0", 0, 0, 0, &VS, 0, 0);
D3DX11CompileFromFile(L"shader.shader", 0, 0, "PShader", "ps_4_0", 0, 0, 0, &PS, 0, 0);

//encapsulate shaders into shader objects
dev->CreateVertexShader(VS->GetBufferPointer(), VS->GetBufferSize(), NULL, &pVS);
dev->CreatePixelShader(PS->GetBufferPointer(), PS->GetBufferSize(), NULL, &pPS);

//Set Shader Objects
devcon->VSSetShader(pVS, 0, 0);
devcon->PSSetShader(pPS, 0, 0);

}

错误是:

no instance of overloaded function "D3DX11CompileFromFileA" matches the argument list argument types are: (const wchar_t [14], int, int, const char [8], const char [7], int, int, int, ID3D10Blob **, int, int)    

最佳答案

D3DX11CompileFromFileA 是一个 ANSI 字符串方法。您试图将一个宽字符常量作为第一个参数 (L"shader.shader") 传递给它。看这个question有关 Windows API 中 ANSI 和 UNICODE 函数之间差异的更多详细信息。

您需要更改您的项目设置,以便 CharacterSet 属性为 UNICODE(参见 here 文档),或者您可以传入一个 UTF-8 字符串(并继续使用 ANSI 方法),通过删除字符串常量前面的 L

关于c++ - D3DX11CompileFromFile 无效参数 C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30757702/

相关文章:

c++ - 将创建多少个 VTable?

C++ this怎么不是成员函数指针?

c++ - 无法打开文件 'd3d9.h' - Windows 10/DirectX 9/VS 2015

c++ - 多常量缓冲区 - 寄存器 - dx12

c++ - 加载自定义 dll + 自定义应用程序失败并显示 : error while loading shared libraries

C++ for_each() 和函数指针

c++ - 在 C++ 中读取文件时有没有办法忽略文件​​结尾字符?

c++ - DirectX C++ 的链接器错误

c++ - DirectX 10 中的平均三角形

c# - Hook /覆盖 DirectX 游戏?