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?

有帮助吗?

解决方案

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.

其他提示

Check the data type is the same, or the attribute name "drawText" is correct.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top