Why get the error attribute info?

in order to get the attribute infomation, app contains such code:
index = glGetAttribLocationARB(glGetHandleARB(GL_PROGRAM_OBJECT_ARB), “inputColor”);
glGetActiveAttribARB(glGetHandleARB(GL_PROGRAM_OBJECT_ARB), index, 100, NULL, &asize, &type, str);

I think str should be “inputColor”, but in fact it is “gl_Normal”. Why?

Is glGetAttribLocationARB returning an index in the [0…GL_OBJECT_ACTIVE_ATTRIBUTES_ARB-1] range?

Yes, the index is 1 and active attribute is 3

Originally posted by Flying_sands:
[b]in order to get the attribute infomation, app contains such code:
index = glGetAttribLocationARB(glGetHandleARB(GL_PROGRAM_OBJECT_ARB), “inputColor”);
glGetActiveAttribARB(glGetHandleARB(GL_PROGRAM_OBJECT_ARB), index, 100, NULL, &asize, &type, str);

I think str should be “inputColor”, but in fact it is “gl_Normal”. Why?[/b]
You are using glGetActiveArribute incorrectly.

From the GL 2.0 spec:
“If index is greater than or equal to
ACTIVE ATTRIBUTES, the error INVALID VALUE is generated. Note that index
simply identifies a member in a list of active attributes, and has no relation to the
generic attribute that the corresponding variable is bound to.”

So you CANNOT use the value returned by glGetAttribLocationARB as input to glGetActiveAttribARB. If you want to find specific info on a known named attribute, you have to iterate over all the attributes and compare the returned strings.

psudeo code:

for(int i=0; i (less than) maxNumAttributes; i++)
{
glGetActiveAttribARB(glGetHandleARB(GL_PROGRAM_OBJECT_ARB), i, 100, NULL, &asize, &type, str)

if(str == “myattribute”)
{
break; // If was found!
}

}

Yes, thanks.
Another question, can glGetAttributeLocation get the right index? I find that the function before and after the glBegin return different value.

What do you mean with “after the glBegin”? Inside glBegin-glEnd commands?
glGet is not allowed there. Add glGetError calls (outside the glBegin-glEnd) and you should see a GL_INVALID_OPERATION.

o, I see. thanks.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.