gpt4 book ai didi

c++ - "No definition of main in vertex shader"在 OpenGL 程序链接状态检查期间

转载 作者:搜寻专家 更新时间:2023-10-31 01:33:42 27 4
gpt4 key购买 nike

我正在使用 VBO 和 GLSL 着色器编写一个 OpenGL/C++ 插件。然而,虽然我可以成功编译着色器并将它们链接到程序,但它的状态链接检查 glGetProgramiv(...,GL_LINK_STATUS,...) 返回“No definition of main in vertex着色器”错误。

顶点着色器正在向片段着色器发送颜色。如果我删除此颜色传递,则链接已成功验证。

如果我想将颜色传递给片段着色器,我的代码有什么问题?

    const GLchar *vert_src =
"#version 410\n"
"layout (location = 0) in vec3 Pos;\n"
"layout (location = 1) in vec3 vColor;\n"
"uniform mat4 projectionMatrix;\n"
"uniform mat4 modelViewMatrix;\n"
"out vec3 color;\n"; // -> REMOVING THIS LINE MAKES THE VALIDATION WORK
"void main() {\n"
" color=vColor;\n" // -> AND THIS LINE TOO
" gl_Position = projectionMatrix*modelViewMatrix*vec4(Pos.x, Pos.y, Pos.z, 1.0);"
"}\n";

const GLchar *frag_src =
"#version 410\n"
"in vec3 color;\n";
"out vec4 fragColor;\n"
"void main() {\n"
" fragColor = vec4(color, 1.0);"
"}\n";

GLuint program = glCreateProgram();

GLuint v_shader = glCreateShader(GL_VERTEX_SHADER);
GLuint f_shader = glCreateShader(GL_FRAGMENT_SHADER);
int len=(GLint)strlen(vert_src);
glShaderSource(v_shader, 1, &vert_src, &len);
glCompileShader(v_shader);

glGetShaderiv(v_shader, GL_COMPILE_STATUS, &success); --> SUCCESS

len=(GLint)strlen(frag_src);
glShaderSource(f_shader, 1, &frag_src, &len);
glCompileShader(f_shader);

glGetShaderiv(f_shader, GL_COMPILE_STATUS, &success); --> SUCCESS

glAttachShader(program, v_shader); --> SUCCESS
glAttachShader(program, f_shader); --> SUCCESS

glLinkProgram(program); --> SUCCESS

glValidateProgram(program); --> SUCCESS
glGetProgramiv(program, GL_LINK_STATUS, &success); --> ERROR: Program is not successfully linked
[...] rest of code

最佳答案

你有分号在字符串之外不应该在那里:

const GLchar *vert_src =
"#version 410\n"
"layout (location = 0) in vec3 Pos;\n"
"layout (location = 1) in vec3 vColor;\n"
"uniform mat4 projectionMatrix;\n"
"uniform mat4 modelViewMatrix;\n"
"out vec3 color;\n"; // <- HERE YOU HAVE A SEMICOLON
"void main() {\n"
" color=vColor;\n"
" gl_Position = projectionMatrix*modelViewMatrix*vec4(Pos.x, Pos.y, Pos.z, 1.0);"
"}\n";

const GLchar *frag_src =
"#version 410\n"
"in vec3 color;\n"; // <- HERE YOU HAVE ANOTHER SEMICOLON
"out vec4 fragColor;\n"
"void main() {\n"
" fragColor = vec4(color, 1.0);"
"}\n";

关于c++ - "No definition of main in vertex shader"在 OpenGL 程序链接状态检查期间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40938390/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com