OpenGL ES 2.0 - 在顶点着色器中找不到属性
我已经寻找这个问题的答案一段时间了 - 但我运气不佳。 我想做的就是将普通数据传递到顶点着色器中。位置正确传递,但是在尝试加载着色器时收到“未找到正常属性”错误。
我的 ATTRIB 值是枚举。
我已经在 OpenGL ES 2.0 中为 Iphone 开发创建了一个立方体。
我的 Shader.vsh 看起来像这样:
attribute vec4 normal;
attribute vec4 position;
varying vec4 colorVarying;
uniform mat4 mvp_matrix;
void main()
{
//Trasform the vertex
gl_Position = mvp_matrix * position;
colorVarying = vec4(1.0, 1.0, 0.0, 0.0);
}
我在绘图框架中更新属性值的部分看起来像这样:
// Update attribute values.
glVertexAttribPointer(ATTRIB_VERTEX, 3, GL_FLOAT, 0, 0, cubeVerticesStrip);
glEnableVertexAttribArray(ATTRIB_VERTEX);
glVertexAttribPointer(ATTRIB_NORMAL, 3, GL_FLOAT, 0, 0, cubeNormalsStrip);
glEnableVertexAttribArray(ATTRIB_NORMAL);
我在 LoadShader 函数中绑定这些属性值的部分像这样:
glBindAttribLocation(program, ATTRIB_VERTEX, "position");
glBindAttribLocation(program, ATTRIB_NORMAL, "normal");
再次,该位置有效。但找不到“正常”。有什么想法吗?
I've looked for a while for an answer for this - but I'm not having much luck.
All I'm trying to do is pass my normal data into my vertex shader. Positions are passing in correctly, however I'm receiving a "normal attribute not found" error when trying to load my shaders.
My ATTRIB values are enums.
I've created a cube in OpenGL ES 2.0 for Iphone development.
My Shader.vsh looks like this:
attribute vec4 normal;
attribute vec4 position;
varying vec4 colorVarying;
uniform mat4 mvp_matrix;
void main()
{
//Trasform the vertex
gl_Position = mvp_matrix * position;
colorVarying = vec4(1.0, 1.0, 0.0, 0.0);
}
The part where I update attribute values in the drawframe looks like this:
// Update attribute values.
glVertexAttribPointer(ATTRIB_VERTEX, 3, GL_FLOAT, 0, 0, cubeVerticesStrip);
glEnableVertexAttribArray(ATTRIB_VERTEX);
glVertexAttribPointer(ATTRIB_NORMAL, 3, GL_FLOAT, 0, 0, cubeNormalsStrip);
glEnableVertexAttribArray(ATTRIB_NORMAL);
And the part where I bind these in my LoadShader function is like this:
glBindAttribLocation(program, ATTRIB_VERTEX, "position");
glBindAttribLocation(program, ATTRIB_NORMAL, "normal");
Again, the position works. But "normal" cannot be found. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
找不到
normal
因为您的 GLSL 编译器很智能。它发现您实际上并没有使用normal
执行某些操作,因此它假装它不存在以节省资源。另外,你的法线和位置应该是 vec3 的,因为你只传递了 3 个值。这不是严格要求的,但它是使您的输入和属性匹配的更好形式。
normal
isn't found because your GLSL compiler was smart. It saw that you didn't actually do something withnormal
, so it pretends it doesn't exist to save resources.Also, your normal and position should be
vec3
's since you're only passing 3 values. This isn't strictly required, but it is better form to make your inputs and attributes match.