c++ - GLSL 1.20 : sending attribute causes segmentation fault

标签 c++ opengl glsl vertex-shader

我需要将属性变量传递给着色器,以了解如何计算 gl_Position。对于绘制的任何对象,此值都应该不同。这是声明:

attribute int drawText;

根据它的值,我决定如何计算 gl_Position。这很热,我在 C++ 程序中传递它:

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

但是我遇到了段错误。我尝试对发送属性 (glVertexAttribI1i) 的行进行注释,在这种情况下程序不会崩溃。可能是什么问题?

最佳答案

整数顶点属性需要 OpenGL 3.0 和 GLSL >= 1.30。

也许您正在使用 GLEW?在使用它之前,您应该检查 (void*)(glVertexAttribI1i) != 0

此外,当一个属性对每个顶点具有相同的值时,就像您发布的代码片段中那样,您应该使用制服。

关于c++ - GLSL 1.20 : sending attribute causes segmentation fault,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20074943/

相关文章:

c++ - void* 与 static_cast 对比 intptr_t 与 reinterpret_cast

c++ - 非 native 类型上具有多个条件的 GDB 断点

c++ - 我们可以获取 xvalue 的地址吗

c++ - cv::LUT() - 插值参数是什么?

java - OpenGL混合: Remove pixels being drawn over (immediate mode)

java - 无限循环阻止文本字段接受输入

c++ - 无法在 Linux 上找到 SDL2_gfx 库

opengl - 如何计算 PBR 中的镜面反射贡献?

java - LWJGL VAO/VBO 不显示

opengl - GLSL片段着色器——绘制简单的粗曲线