2014-11-04 893 views
0

我想使用D3D函数D3DCompilFromFile,它工作得很好,直到我调整了我的着色器,现在突然我的程序停止识别D3DCompileFromFile函数,我已经检查过需要包含哪些头文件/库/ dll,并且他们都在我的知识范围内。错误C3861:'D3DCompileFromFile':找不到标识符

我使用VS2013

下面是一些示例代码

application.cpp

HRESULT Application::CompileShaderFromFile(WCHAR* szFileName, LPCSTR szEntryPoint, LPCSTR szShaderModel, ID3DBlob** ppBlobOut) 
{ 
    HRESULT hr = S_OK; 

    DWORD dwShaderFlags = D3DCOMPILE_ENABLE_STRICTNESS; 
#if defined(DEBUG) || defined(_DEBUG) 
    // Set the D3DCOMPILE_DEBUG flag to embed debug information in the shaders. 
    // Setting this flag improves the shader debugging experience, but still allows 
    // the shaders to be optimized and to run exactly the way they will run in 
    // the release configuration of this program. 
    dwShaderFlags |= D3DCOMPILE_DEBUG; 
#endif 

    ID3DBlob* pErrorBlob; 
    hr = D3DCompileFromFile(szFileName, nullptr, nullptr, szEntryPoint, szShaderModel, 
     dwShaderFlags, 0, ppBlobOut, &pErrorBlob); 

    if (FAILED(hr)) 
    { 
     if (pErrorBlob != nullptr) 
      OutputDebugStringA((char*)pErrorBlob->GetBufferPointer()); 

     if (pErrorBlob) pErrorBlob->Release(); 

     return hr; 
    } 

    if (pErrorBlob) pErrorBlob->Release(); 

    return S_OK; 
} 

application.h

#include <windows.h> 
#include <d3d11_1.h> 
#include <d3dcompiler.h> 
#include <directxmath.h> 
#include <directxcolors.h> 
#include "resource.h" 
#include <iostream> 
#include <vector> 
#include <time.h> 
#include <stdio.h> 
#include <stdlib.h> 

using namespace DirectX; 
using namespace std; 
. 
. 
. 
. 
HRESULT CompileShaderFromFile(WCHAR* szFileName, LPCSTR szEntryPoint, LPCSTR szShaderModel, ID3DBlob** ppBlobOut); 

Lighting.fx

cbuffer cbData 
{ 
    float4x4 World; 
    float4x4 View; 
    float4x4 Projection; 

    float4 gDiffuseMtrl; 
    float4 gDiffuseLight; 
    float3 gLightVecW; 
    float4 gAmbientMtrl; 
    float4 gAmbientLight; 
}; 

struct VS_IN 
{ 
    float4 posL : POSITION; 
    float3 normalL : NORMAL; 
}; 

struct VS_OUT 
{ 
    float4 Pos : SV_POSITION; 
    float4 Col : COLOR; 
}; 

VS_OUT VS(VS_IN vIn) 
{ 
    VS_OUT output = (VS_OUT)0; 

    output.Pos = mul(vIn.posL, World); 
    output.Pos = mul(output.Pos, View); 
    output.Pos = mul(output.Pos, Projection); 


    // Convert from local to world normal 
    float3 normalW = mul(float4(vIn.normalL, 0.0f), World).xyz; 
    normalW = normalize(normalW); 

    // Compute Colour 
    float s = max(dot(gLightVecW, normalW), 0.0f); 
    float3 diffuse = s*(gDiffuseMtrl*gDiffuseLight).rgb; 
    float3 ambient = gAmbientMtrl * gAmbientLight; 
    output.Col.rgb = diffuse + ambient; 
    output.Col.a = gDiffuseMtrl.a; 


    return output; 
} 

float4 PS(VS_OUT pIn) : SV_Target 
{ 
    return pIn.Col; 
} 

technique11 Render 
{ 
    pass P0 
    { 
     SetVertexShader(CompileShader(vs_4_0, VS())); SetGeometryShader(NULL); 
     SetPixelShader(CompileShader(ps_4_0, PS())); 
    } 
} 

很抱歉,如果我只是扔在人太多的代码,但我真的在努力寻找出这

回答

2

原因是您使用的legacy DirectX SDKD3DCompileFromFile在老的#43版本的D3DCompiler中并不存在,这意味着您可能会在DirectX SDK中选择较旧的'd3dcompiler.h'标头,而不是VS 2013中附带的较新的Windows 8.1 SDK版本'd3dcompiler.h'

理想情况下,您根本不应该使用DirectX SDK(请参阅Living without D3DX)。

我从着色器中看到您正在使用Effects 11,所以您应该确保移动到最新的CodePlex版本,该版本不需要任何DXSDK头。请注意,对'fx_5_0'配置文件的支持已被弃用,并且预计将在未来的HLSL编译器更新中被删除。编译器的Windows 8.1 SDK#47版本将发出警告声明,但仍会编译这些着色器。

+0

感谢您的评论,当我去D3DCompileFromFile的定义,它使我d3dcompiler.h它位于文件“的Windows套件\ 8.1 \包含\嗯”,该文件还包含 '#定义D3DCOMPILER_DLL_W大号“d3dcompiler_47.dll” #define D3DCOMPILER_DLL_A“d3dcompiler_47.dll”' 这让我相信我使用正确的编译器文件,在我的Include和Lib路径中我也使用Windows 8.1“include/um”和“ Lib \ winv6.3 \ um \ x86“ – CodeMode 2014-11-04 18:43:09

+0

啊,等等,我想我在VC++目录选项卡中保留了原有的包含路径,现在我已经删除了它们,我收到错误消息说我没有D3DCOMPILER_46。 dll – CodeMode 2014-11-04 18:53:20

+0

#46是VS 2012附带的Windows 8.0 SDK。您的VC++目录选项卡s应该是默认设置(如果它们设置为其他任何设置,它们全部设置为“从父母继承”)。如果您还需要传统DirectX SDK(基本上是D3DX或XACT)的内容,那么您需要将可执行文件设置为“$(ExecutablePath); $(DXSDK_DIR)Utilities \ bin \ x86”或$(ExecutablePath); $(DXSDK_DIR)Utilities \ bin \ x64; $(DXSDK_DIR)Utilities \ bin \ x86''包含到''(IncludePath); $(DXSDK_DIR)Include''和Library到''$(LibraryPath); $ (DXSDK_DIR)Lib \ x86'或$(LibraryPath); $(DXSDK_DIR)Lib \ x64''为VS 2012或VS 2013. – 2014-11-04 19:01:44