我目前正在对尝试编译 GLSL 着色器时遇到的错误感到沮丧,我已经成功地编译了两个着色器,但是在链接它们时我得到了一个错误。没有输出,但链接失败。
这是编译+链接代码:
GLuint program = NULL;
GLint compile_ok = GL_FALSE, link_ok = GL_FALSE;
GLuint vs = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(vs, 1, &vertCont, NULL);
glCompileShader(vs);
glGetShaderiv(vs, GL_COMPILE_STATUS, &compile_ok);
char logBuf[1024];
int len;
if (0 == compile_ok)
{
glGetShaderInfoLog(vs, sizeof(logBuf), &len, logBuf);
LogMgr::logMessage(LogMgr::CRITICAL, "Error in vertex shader\n", logBuf);
return false;
}
GLuint fs = glCreateShader(GL_FRAGMENT_SHADER);
glShaderSource(fs, 1, &fragCont, NULL);
glCompileShader(fs);
glGetShaderiv(fs, GL_COMPILE_STATUS, &compile_ok);
if (!compile_ok)
{
glGetShaderInfoLog(vs, sizeof(logBuf), &len, logBuf);
LogMgr::logMessage(LogMgr::CRITICAL, "Error in fragment shader", logBuf);
return false;
}
glAttachShader(program, vs);
glAttachShader(program, fs);
glLinkProgram(program);
glGetProgramiv(program, GL_LINK_STATUS, &link_ok);
if (!link_ok)
{
glGetShaderInfoLog(vs, sizeof(logBuf), &len, logBuf);
LogMgr::logMessage(LogMgr::CRITICAL, "Could not link basic shaders!", logBuf);
return false;
}
return program;
这是顶点着色器:
#version 330
layout(location = 0) in vec4 position;
void main()
{
gl_Position = position;
}
片段着色器:
#version 330
out vec4 outputColor;
void main()
{
outputColor = vec4(1.0f, 0.0f, 1.0f, 1.0f);
}
有什么线索吗?