OpenGLES GLSL Shader attributes always bound to 0
Posted
by
codemonkey
on Game Development
See other posts from Game Development
or by codemonkey
Published on 2012-11-08T13:15:54Z
Indexed on
2012/11/08
17:26 UTC
Read the original article
Hit count: 300
So I have a very simple vertex shader as follows
#version 120
attribute vec3 position;
attribute vec3 inColor;
uniform mat4 mvp;
varying vec3 fragColor;
void main(void){
fragColor = inColor;
gl_Position = mvp * vec4(position, 1.0);
}
Which I load, as well as the fragment shader:
#version 120
varying vec3 fragColor;
void main(void) {
gl_FragColor = vec4(fragColor,1.0);
}
Which I then load, compile, and link to my shader program. I check for link status using
glGetProgramiv(shaderProgram, GL_LINK_STATUS, &shaderSuccess);
which returns GL_TRUE so I think its ok. However, when I query the active attributes and uniforms using
#ifdef DEBUG
int totalAttributes = -1;
glGetProgramiv(shaderProgram, GL_ACTIVE_ATTRIBUTES, &totalAttributes);
for(int i=0; i<totalAttributes; ++i) {
int name_len=-1, num=-1;
GLenum type = GL_ZERO;
char name[100];
glGetActiveAttrib(shaderProgram, GLuint(i), sizeof(name)-1,
&name_len, &num, &type, name );
name[name_len] = 0;
GLuint location = glGetAttribLocation(shaderProgram, name);
fprintf(stderr, "Attribute %s is bound at %d\n", name, location);
}
int totalUniforms = -1;
glGetProgramiv(shaderProgram, GL_ACTIVE_UNIFORMS, &totalUniforms);
for(int i=0; i<totalUniforms; ++i) {
int name_len=-1, num=-1;
GLenum type = GL_ZERO;
char name[100];
glGetActiveUniform(shaderProgram, GLuint(i), sizeof(name)-1,
&name_len, &num, &type, name );
name[name_len] = 0;
GLuint location = glGetUniformLocation(shaderProgram, name);
fprintf(stderr, "Uniform %s is bound at %d\n", name, location);
}
#endif
I get:
Attribute inColor is bound at 0
Attribute position is bound at 1
Uniform mvp is bound at 0
Which leads to failure when trying to use the shader to render the objects. I have tried switching the order of declaration of position & inColor, but still, only position is bound with the other two giving 0
Can someone please explain why this is happening? Thanks
© Game Development or respective owner