Gapry
Gapry

Reputation: 373

Linking with uncompiled shader in Ubuntu

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);

Upvotes: 0

Views: 1786

Answers (1)

genpfault
genpfault

Reputation: 52082

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.

There's absolutely nothing in there about interpreting string as a filesystem path.

You need to load the shader from file yourself, then pass the string(s) containing the shader code to glShaderSource().

Upvotes: 2

Related Questions