问题描述
我需要加载一个* .glsl来绘制一些东西.我的环境是Ubuntu 13.04,因此它不存在GLuint InitShader(GLuint,GLuint).这是我用于对象创建,预链接步骤和链接的配置.不幸的是,它仍然会发生错误,该错误与未编译的着色器链接.我怎么了?
I need to load a *.glsl to draw something. My environment is Ubuntu 13.04, hence it doesn't exist GLuint InitShader (GLuint, GLuint). It is my config for object creation, pre-link step and linking. Unfortunately, it still occurs the error, which is linking with uncompiled shader. What's wrong with me?
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
解释为文件系统路径绝对没有 .
There's absolutely nothing in there about interpreting string
as a filesystem path.
您需要自己从文件中加载着色器,然后将包含着色器代码的字符串传递给glShaderSource()
.
You need to load the shader from file yourself, then pass the string(s) containing the shader code to glShaderSource()
.
这篇关于在Ubuntu中与未编译的着色器链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!