c++ - 错误 C3861 : 'D3DCompileFromFile' : identifier not found

标签 c++ visual-studio-2013 direct3d directx-11

我正在尝试使用 D3D 函数 D3DCompilFromFile,它工作得非常好,直到我稍微调整了我的着色器,现在我的程序突然停止识别 D3DCompileFromFile 函数,我检查了头文件/库/dll 的内容我需要包括在内,据我所知,它们都在那里。

我正在使用 VS2013

下面是一些示例代码

应用程序.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;
}

应用程序.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);

灯光特效

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() ) );
    }
}

抱歉,如果我只是向人们扔了太多代码,但我真的很难找出造成这种情况的原因

最佳答案

您使用的是 legacy DirectX SDKD3DCompileFromFileD3DCompiler 的旧 #43 版本中不存在这意味着您可能在 DirectX SDK 中选择较旧的“d3dcompiler.h” header ,而不是 VS 2013 附带的较新的 Windows 8.1 SDK 版本的“d3dcompiler.h”。

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

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

关于c++ - 错误 C3861 : 'D3DCompileFromFile' : identifier not found,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26740980/

相关文章:

用于初始化指向实例化模板友元函数的指针的 C++ 语法

c++ - 处理线程失控问题的线程新手

检查变量是否为某个值

visual-studio - Visual Studio 警告 : “Some of the properties associated with the solution could not be read”

c++ - 用于投影的 D3DX vector 数学函数?

c++ - 什么是可伸缩锁?

c++ - Windows CreateFile 可能的错误代码

.net - 无法启动 vsixinstaller.exe,VSIX 安装程序进程失败,退出代码 1006

direct3d - 我在 D3D12 中使用 SetGraphicsRootDescriptorTable 可能有什么问题?

direct3d - DirectX 架构资源