glGetActiveAttrib and wrong number

hi

i send number pf active attrib to the glGetActiveAttrib but it returns wrong name of attrib:

my code:

GLint active_attribs;
glGetProgramiv(prog_id,GL_ACTIVE_ATTRIBUTES,&active_attribs);
for ( i = 0  ; i < active_attribs ; i++)
{
glGetActiveAttrib(m_uID,i,50,NULL,&isize,&itype,attrib_name); 
m_vars[attrib_name] = i; 
}

and the shader:

#version 150 core 
in vec3 in_Position;
in vec3 in_Color;
out vec3 ex_Color;
void main(void)
{
gl_Position = vec4(in_Position, 1.0);
ex_Color = in_Color;
}

returned values:
in_Position: 1
in_Color: 0

but it must be return:
in_Position: 0
in_Color: 1

where is my wrong??

Don’t get them, set them to what you want them to be, using glBindAttribLocation, e.g:

glBindAttribLocation(m_uID, 0, “in_Position”);
glBindAttribLocation(m_uID, 1, “in_Color”);

Regards
elFarto

Do this before linking the program, not after.

i do this in my game engine:

user can send value or attribute by telling it’s name or ID:
for examlpe:

GLSLProgram prog* = DRenderer.createGpuProgram(“test_shader.xml”);
prog.setValue(“specular”,16.3);

or

prog.setValue(2,16.3);

i get all variables when i create shader and after i compile it. (this is for faster access and dont using glGetUniformLocation ro attrib location at run-time in every call of function) .

glGetActiveUniform works correctly and return true numbers but glGetActiveAttrib return a wrong number.

There is no “wrong number” to OpenGL; if you do not specify particular attribute values with the API that elFarto described, it will assign them arbitrarily. So if your program needs “in_Position” to be attribute number 0, then you must set it to attribute number 0.

i’m not need to set in_Position or … to pre-defined number.

i want just to get currect attribs id. and no more.

i want just to get currect attribs id. and no more.

The function you used did return the correct attribute ids. You said that:

returned values:
in_Position: 1
in_Color: 0

Because you did not specifically assign those attribute values to a particular index, OpenGL is free to give them whatever attribute index it wants. Thus, what this function returns is what attribute index OpenGL assigned to that attribute.

After that, you said.

but it must be return:
in_Position: 0
in_Color: 1

If you need in_Position to have an attribute index of 0, then you must tell OpenGL to give it an attribute index of 0. Otherwise, OpenGL is free to assign it whatever attribute index it wants.

i changed my code to this:


// getting active attribs			
GLint active_attribs;
glGetProgramiv(m_uID,GL_ACTIVE_ATTRIBUTES,&active_attribs);

for ( i = 0  ; i < active_attribs ; i++)
{
glGetActiveAttrib(m_uID,i,50,NULL,&isize,&itype,attrib_name); 
m_vars[attrib_name] = glGetAttribLocation(m_uID,attrib_name); 
}

at now it works correctly. returned values:
in_Position: 0
in_Color: 1