【问题标题】:D3DX11CompileFromFile Invalid Arguments C++D3DX11CompileFromFile 无效参数 C++
【发布时间】:2015-06-10 13:24:01
【问题描述】:

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

//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)    

【问题讨论】:

  • 请给出您遇到的错误的文本。
  • 1 IntelliSense:没有重载函数“D3DX11CompileFromFileA”的实例与参数列表参数类型匹配:(const wchar_t [14], int, int, const char [8], const char [7], int, int, int, ID3D10Blob **, int, int) d:\Documents\GitHub\Matrixology\Engine\Engine\D3D.cpp 73

标签: c++ directx


【解决方案1】:

D3DX11CompileFromFileA 是一种 ANSI 字符串方法。您正在尝试将宽字符常量作为第一个参数 (L"shader.shader") 传递给它。有关 Windows API 中 ANSI 和 UNICODE 函数之间区别的更多详细信息,请参阅此question

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

【讨论】:

  • 更好的是,直接使用D3DCompileFromFile 而不是传统的D3DX 包装器...见this blog post
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-08-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多