gpt4 book ai didi

opengl - 在 Ubuntu 中与未编译的着色器链接

转载 作者:行者123 更新时间:2023-12-04 19:03:44 25 4
gpt4 key购买 nike

我需要加载 *.glsl 来绘制一些东西。我的环境是 Ubuntu 13.04,因此它不存在 GLuint InitShader (GLuint, GLuint)。这是我用于对象创建、预链接步骤和链接的配置。不幸的是,它仍然发生错误,它与未编译的着色器链接。我怎么了?

    glewExperimental = GL_TRUE;
glewInit ();

glGenVertexArrays (1, &_vao_vertex_array[_vao_index++]);
glBindVertexArray (_vao_vertex_array [_vao_index - 1]);

GLuint buffer;
glGenBuffers (1, &buffer);
glBindBuffer (GL_ARRAY_BUFFER, buffer);
glBufferData (GL_ARRAY_BUFFER,
sizeof (GLfloat) * 2 * NumPoints + sizeof (GLfloat) * 4 * NumPoints, 0, GL_STATIC_DRAW);

GLuint program_object = glCreateProgram ();
GLuint vertex_shader = glCreateShader (GL_VERTEX_SHADER);
GLuint fragment_shader = glCreateShader (GL_FRAGMENT_SHADER);

const char *vertex_source = "./shader/vshader21.glsl";
glShaderSource (vertex_shader, 1, &vertex_source, NULL);
printProgramInfoLog (vertex_shader);

const char *fragment_source = "./shader/fshader21.glsl";
glShaderSource (fragment_shader, 1, &fragment_source, NULL);
printProgramInfoLog (fragment_shader);

GLuint loc = glGetAttribLocation (program_object, "vPosition");
glEnableVertexAttribArray (loc);
glVertexAttribPointer (loc, 2, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET (0));
glBufferSubData (GL_ARRAY_BUFFER, 0, sizeof (GLfloat) * 2 * NumPoints, points);

GLuint loc1 = glGetAttribLocation (program_object, "vColor");
glEnableVertexAttribArray (loc1);
glVertexAttribPointer (loc1, 4, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET (sizeof (GLfloat) * 2 * NumPoints));
glBufferSubData (GL_ARRAY_BUFFER, sizeof (GLfloat) * 2 * NumPoints, sizeof (GLfloat) * 4 * NumPoints, colors);

glCompileShader (vertex_shader);
glAttachShader (program_object, vertex_shader);
printProgramInfoLog (program_object);

glCompileShader (fragment_shader);
glAttachShader (program_object, fragment_shader);
printProgramInfoLog (program_object);

glLinkProgram (program_object);
printProgramInfoLog (program_object);

最佳答案

const char *vertex_source = "./shader/vshader21.glsl";
^^^^^^^^^^^^^^^^^^^^^^^ wat
glShaderSource (vertex_shader, 1, &vertex_source, NULL);

glShaderSource() does not work that way!

string: Specifies an array of pointers to strings containing the source code to be loaded into the shader.



那里绝对没有关于口译的内容 string作为文件系统路径。

您需要自己从文件加载着色器,然后将包含着色器代码的字符串传递给 glShaderSource() .

关于opengl - 在 Ubuntu 中与未编译的着色器链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19168843/

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