简体   繁体   English

OpenGL ES 2.0-在顶点着色器中找不到属性

[英]OpenGL ES 2.0 - Can't find Attribute in Vertex Shader

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. 我的ATTRIB值是枚举。

I've created a cube in OpenGL ES 2.0 for Iphone development. 我已经在OpenGL ES 2.0中为Iphone开发创建了一个多维数据集。

My Shader.vsh looks like this: 我的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);
}

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: 我将这些绑定到我的LoadShader函数中的部分是这样的:

glBindAttribLocation(program, ATTRIB_VERTEX, "position");
glBindAttribLocation(program, ATTRIB_NORMAL, "normal");

Again, the position works. 同样,该职位有效。 But "normal" cannot be found. 但是找不到“正常”。 Any ideas? 有任何想法吗?

normal isn't found because your GLSL compiler was smart. 找不到normal因为您的GLSL编译器很聪明。 It saw that you didn't actually do something with normal , so it pretends it doesn't exist to save resources. 它看到你实际上并没有一些与normal ,所以它假装它不存在,以节省资源。

Also, your normal and position should be vec3 's since you're only passing 3 values. 另外,您的法线和位置应该是vec3 ,因为您仅传递了3个值。 This isn't strictly required, but it is better form to make your inputs and attributes match. 这不是严格要求的,但是它是使输入和属性匹配的更好形式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM