Search code examples
c++openglglslvertex-shader

GLSL 1.20: sending attribute causes segmentation fault


I need to pass an attribute variable to the shader, to know how to compute gl_Position. This value should be different for any object drawn. This is the declaration:

attribute int drawText;

According to it's value I decide how to compute gl_Position. This is hot I pass it in the c++ program:

// Pass some uniforms
GLint location= glGetAttribLocation(program_id, (char*)"drawText");
glEnableVertexAttribArray(location);
glVertexAttribI1i(location,1);
glutSolidCube(15);
glDisableVertexAttribArray(location);

But I get segmentation fault. I tried to comment the line where I send the attribute (glVertexAttribI1i), and the program doesn't crash in this case. What could the problem be?


Solution

  • Integer vertex attributes requires OpenGL 3.0 and GLSL >= 1.30.

    Maybe you are using GLEW? You should check that (void*)(glVertexAttribI1i) != 0 before using it.

    Moreover, when an attribute has the same value for each vertex, like in the snippet you posted, you should use uniforms.