glGetAttribLocation and a -1 return value?

I am at my minds end, I have no errors when checking my code with GL’s built in calls, and I am using the vertex attribute in my VS… What else would cause me to get a -1? I am using GLUT to do some test runs on my new shader lib, and the same code works in my engine. The shader runs and shows a textured surface, but the values are wrong, and gDebugger throws the error saying that glEnableVertexAttribArray() has a wrong value…

Thanks

might be that your attrib variable isn’t properly used in your shader thus might be skipped because of no use. happend to me because of exactly that but with uniform variables.

I doubt it as render monkey says its compiles with success. The code in the shader is the same as my engines code and that returns a value other than -1…

Did you test your code on the same hardware for your engine and your new shader lib?
If you did, it seems that your problem comes from your opengl program. I advise you to use the GetActiveAttrib function to get the list of all active attributes and see if everything is fine.

Are you sure that Opengl did not threw any error? Shader program is succesfully linked?

I am not sure to understand you about “GL’s built in calls”, can you elaborate a bit more?

glGetActiveAttrib()

I checked and I only have two active, and those are gl_Vertex and gl_MultiTexCoord0… I should have 5

tangent, bitangent, gl_Normal doesn’t even show up …


#version 120

attribute vec3 Tangent, BiTangent;

void main()
{    
	vec3 t = gl_NormalMatrix * Tangent;
	vec3 b = gl_NormalMatrix * BiTangent;
	vec3 n = gl_NormalMatrix * gl_Normal;
	gl_TexCoord[0] = gl_MultiTexCoord0;
	gl_Position = ftransform();   
}

The only place I have seen this happen before is when I got the order of GLSL compiling, linking, binding and so on messed up. Is that any help?

Hi scratt, nah, I have kept the code in order from my other code base, which works.

_NK47 already explained your problem.
In your vertex shader code you posted I do not see how t, b and n variables are used - therefore they are optimized out. That is why Tangent, BiTangent and gl_Normal also is not needed in shader - so they are also optimized out. This is normal for GLSL. Same thing happens also with uniforms - if you do not use them or some other variables (which are calculated from these uniforms) then uniforms are optimized out.