我需要加载一个* .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);
答案 0 :(得分:2)
const char *vertex_source = "./shader/vshader21.glsl";
^^^^^^^^^^^^^^^^^^^^^^^ wat
glShaderSource (vertex_shader, 1, &vertex_source, NULL);
glShaderSource()
does not work that way!
string
:指定一个指向字符串的指针数组,其中包含要加载到着色器中的源代码。
将string
解释为文件系统路径时,绝对没有没有。
您需要自己从文件加载着色器,然后将包含着色器代码的字符串传递给glShaderSource()
。