gpt4 book ai didi

c++ - OpenGL Mac OSX 顶点着色器未链接到片段着色器

转载 作者:太空宇宙 更新时间:2023-11-04 11:32:19 24 4
gpt4 key购买 nike

我在 Mac OSX 10.9 中编译和执行简单的 OpenGL 应用程序时遇到问题。它在 Windows 中工作得很好。但是在 Mac 中,我在 shaderProgram 中将顶点着色器链接到片段着色器时不断遇到一些错误。

这是我的控制台输出。

4.1 INTEL-8.26.34

ERROR! could not link the shader program
WARNING: Output of vertex shader 'outColor' not read by fragment shader
ERROR: Input of fragment shader 'inColor' not written by vertex shader
Program ended with exit code: 0

这是我用来将两者链接在一起的方法。

GLuint createShaderProgram(GLuint vertexShader, GLuint fragmentShader)
{
// Create and link the shader program
GLuint shaderProgram = glCreateProgram(); // create handle
if (!shaderProgram) {
ERROR("could not create the shader program", false);
return NULL_HANDLE;
}
glAttachShader(shaderProgram, vertexShader); // attach vertex shader
glAttachShader(shaderProgram, fragmentShader); // attach fragment shader
glLinkProgram(shaderProgram);



// check to see if the linking was successful
int linked;
glGetProgramiv(shaderProgram, GL_LINK_STATUS, &linked); // get link status
if (!linked) {
ERROR("could not link the shader program", false);
int maxLength;
int length;
glGetProgramiv(shaderProgram, GL_INFO_LOG_LENGTH, &maxLength);
char* log = new char[maxLength];
glGetProgramInfoLog(shaderProgram, maxLength,&length,log);
printf(log);

return NULL_HANDLE;
}

return shaderProgram;
}

这是我的顶点着色器。

#version 410 core
layout (location = 0) in vec3 inPosition;
layout (location = 3) in vec3 inColor;
layout (location = 3) smooth out vec4 outColor;
void main()
{
gl_Position = vec4(inPosition, 1.0);
outColor = vec4(inColor, 1.0);
}

这是fragShader

#version 410 core
layout (location = 3) smooth in vec4 inColor;
layout (location = 0) out vec4 outColor;
void main()
{
outColor = inColor;
}

谢谢!!

最佳答案

名称需要匹配:

让顶点着色器的输出名称与片段着色器的输入名称相匹配:

#version 410 core
layout (location = 0) in vec3 inPosition;
layout (location = 3) in vec3 inColor;
smooth out vec4 vertOutColor;
void main()
{
gl_Position = vec4(inPosition, 1.0);
vertOutColor = vec4(inColor, 1.0);
}

片段着色器:

#version 410 core
smooth in vec4 vertOutColor;
layout (location = 0) out vec4 outColor;
void main()
{
outColor = vertOutColor;
}

关于c++ - OpenGL Mac OSX 顶点着色器未链接到片段着色器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24267069/

24 4 0
文章推荐: html -
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com