在哪里设置着色器文件的入口点(错误X3501)?

时间:2015-06-30 20:42:39

标签: c++ directx directx-11

我是DirectX的菜鸟,并在Visual Studio中运行[this] [1]教程。在编译时,我遇到这个错误:“错误X3501:'main':找不到入口点。”现在一些谷歌搜索引导我[这个答案] [2],它说输入我的着色器文件的属性,设置Shader类型和入口点到您想要的入口点。现在作为一个提供的答案,我不知道我的入口点应该是什么。起初我认为它应该是我D3DX11CompileFromFile()中实际调用ColorShaderClass::InitializeShader的地方,但我再次遇到错误X3501。怎么办?

我的文件如下

ColorVS.hlsl
ColorPS.hlsl

使用名称的方法

bool ColorShaderClass::Initialize(ID3D11Device* device, HWND hwnd)
{
    bool result;


    // Initialize the vertex and pixel shaders.
    result = InitializeShader(device, hwnd, L"ColorVS.hlsl", L"ColorPS.hlsl");
    if (!result)
    {
        return false;
    }

    return true;
}

bool ColorShaderClass::InitializeShader(ID3D11Device* device, HWND hwnd, WCHAR* vsFilename, WCHAR* psFilename)
{
    HRESULT result;
    ID3D10Blob* errorMessage;
    ID3D10Blob* vertexShaderBuffer;
    ID3D10Blob* pixelShaderBuffer;
    D3D11_INPUT_ELEMENT_DESC polygonLayout[2];
    unsigned int numElements;
    D3D11_BUFFER_DESC matrixBufferDesc;

// Initialize the pointers this function will use to null.
errorMessage = 0;
vertexShaderBuffer = 0;
pixelShaderBuffer = 0;

    // Compile the vertex shader code.
    result = D3DX11CompileFromFile(vsFilename, NULL, NULL, "ColorVertexShader", "vs_5_0", D3D10_SHADER_ENABLE_STRICTNESS, 0, NULL,
    &vertexShaderBuffer, &errorMessage, NULL);
if (FAILED(result))
{
    // If the shader failed to compile it should have writen something to the error message.
    if (errorMessage)
    {
        OutputShaderErrorMessage(errorMessage, hwnd, vsFilename);
    }
    // If there was nothing in the error message then it simply could not find the shader file itself.
    else
    {
        MessageBox(hwnd, vsFilename, L"Missing Shader File", MB_OK);
    }

    return false;
}

// Compile the pixel shader code.
result = D3DX11CompileFromFile(psFilename, NULL, NULL, "ColorPixelShader", "ps_5_0", D3D10_SHADER_ENABLE_STRICTNESS, 0, NULL,
    &pixelShaderBuffer, &errorMessage, NULL);
if (FAILED(result))
{
    // If the shader failed to compile it should have writen something to the error message.
    if (errorMessage)
    {
        OutputShaderErrorMessage(errorMessage, hwnd, psFilename);
    }
    // If there was  nothing in the error message then it simply could not find the file itself.
    else
    {
        MessageBox(hwnd, psFilename, L"Missing Shader File", MB_OK);
    }

    return false;
}
//more code
}

修改

正如tsandy回答的那样,入口点是实际执行着色的函数。对于遵循本教程并使用与着色器文件相同的方案的任何人

ColorPS.hlsl的入口点为“ColorPixelShader”

ColorVS.hlsl的入口点为“ColorVertexShader”

1 个答案:

答案 0 :(得分:2)

对于每个hlsl文件,入口点应该是执行着色的hlsl文件中的函数名称。 例如。在以下像素着色器hlsl:

struct PixelInputType
{
    float4 position : SV_POSITION;
    float4 color : COLOR;
};

float4 ColorPixelShader(PixelInputType input) : SV_TARGET
{
    return input.color;
}

您可以使用ColorPixelShader作为切入点。