在哪里设置着色器文件的入口点(错误X3501)
Where to set the entrypoint of Shader files (error X3501)?
我是DirectX的新手,正在Visual Studio中运行[this][1]教程。在编译时,我遇到了这样的错误:"错误X3501:'main':找不到入口点。"现在,一些谷歌搜索让我找到了[this answer][2],它说要输入着色器文件的属性,请将着色器类型和入口点设置为所需的入口点。现在,作为一个很好的答案,我不知道我的入口点应该是什么。起初我认为它应该是我实际调用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"
对于每个hlsl文件,入口点应该是hlsl文件中执行着色的函数的名称。例如,在以下像素着色器hlsl:中
struct PixelInputType
{
float4 position : SV_POSITION;
float4 color : COLOR;
};
float4 ColorPixelShader(PixelInputType input) : SV_TARGET
{
return input.color;
}
您将使用ColorPixelShader作为入口点。
相关文章:
- 警告处理为错误这里有什么问题
- "error: no matching function for call to"构造函数错误
- boost::进程间消息队列引发错误
- C++,OpenCV,尝试显示图像时"OpenCV(4.3.0) Error: Assertion failed (size.width>0 && size.height>0)"此错误
- 有关插入适配器的错误。[错误]请求从 'back_insert_iterator<vector<>>' 类型转换为非标量类型
- QT在错误的班级中寻找空位
- vector.resize()中的分配错误
- 代码在main()中运行,但在函数中出现错误
- 释放错误后堆使用
- (C++)分析树以计算返回错误值的简单算术表达式
- Project Euler问题4的错误解决方案
- 我的字符计数代码计算错误.为什么
- 从"int*"强制转换为"unsigned int"会丢失精度错误
- 尝试导入pybind-opencv模块时出现libgtk错误
- CMake项目Boost库错误:Boost/config/compiler/gcc.hpp:165:10:致命错误:cs
- 在某些循环内使用vector.push_back时出现分段错误
- MSVC多行宏编译器错误
- 静态数据成员的问题-修复链接错误会导致编译器错误
- DirectX 11.2 错误: X3501: 找不到'main'入口点
- 在哪里设置着色器文件的入口点(错误X3501)