Ben
Ben

Reputation: 11

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.

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?

Upvotes: 1

Views: 3563

Answers (1)

Nicol Bolas
Nicol Bolas

Reputation: 474436

normal isn't found because your GLSL compiler was smart. It saw that you didn't actually do something with normal, 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.

Upvotes: 13

Related Questions