Urgent: GLSL and VertexAttrib problems (solved)

Started by
3 comments, last by Android_s 19 years, 5 months ago
Hi I am trying to make a set of classes to handle shading programs and i'm asked to have support for "User Defined Vertex Attributes". I've read all that i can find but frankly i'm not getting any wiser... I add a attribute float fooBar; to my .vert shader, and set it with a function SetVertexAttrib1fARB(string name, float val);. This function looks like this inside:

void ShadingProgram::SetVertexAttribute1f(std::string name, float f)
{
	if(shaderProgram == NULL) return;

	glVertexAttrib1fARB(GetAttribLoc(name), f);
}
GetAttribLoc() looks like this:

int ShadingProgram::GetAttribLoc(std::string name)
{
	if(shaderProgram == NULL) return -1;

	int loc = glGetAttribLocationARB(shaderProgram, name.c_str());

	if (loc == -1)
	{
		std::ostringstream stream;
		stream << "No such attribute named \"" << name << "\"";
		ErrorLog(stream.str());
	}

	CheckOpenGLError();  // Check for OpenGL errors

    return loc;
}
Now when i run my test application it spams me with "No such attribute named fooBar", and i can't figure out why... Is there something i have forgotten or missunderstood regarding the VertexAttributes? [Edited by - Android_s on November 12, 2004 6:11:47 AM]
----------------------------------------------------------------------------------------------------------------------"Ask not what humanity can do for you, ask what you can do for humanity." - By: Richard D. Colbert Jr.
Advertisement
is the attribute used in the program at all? the compiler will strip out anything not used, resulting in that error...
Hmm, is that so..?
You are correct, the attribute isn't used in the program, it's just a test variable. I will make some use of it and then try.

Thank you for the help!

I have one more question i might aswell ask right now [smile]

When i want to set a mat2, mat3 or mat4, how am i supposed to go about then? Is it possible to use the GetAttribLoc() function and then do something like this:
// m is a [2][2] arrayglVertexAttrib2fvARB(GetAttribLoc(name), m[0]);glVertexAttrib2fvARB(GetAttribLoc(name) + 1, m[1]);


...or is there a better way?
----------------------------------------------------------------------------------------------------------------------"Ask not what humanity can do for you, ask what you can do for humanity." - By: Richard D. Colbert Jr.
yeah, thats the way todo it. The matrix must be loaded in colunm major order...
Ahh, thank you!
I was thinking there were a more "clean" way to do the matrix setting, but that will do [smile]
----------------------------------------------------------------------------------------------------------------------"Ask not what humanity can do for you, ask what you can do for humanity." - By: Richard D. Colbert Jr.

This topic is closed to new replies.

Advertisement