Sign in to follow this  
Android_s

OpenGL Urgent: GLSL and VertexAttrib problems (solved)

Recommended Posts

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]

Share this post


Link to post
Share on other sites
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] array
glVertexAttrib2fvARB(GetAttribLoc(name), m[0]);
glVertexAttrib2fvARB(GetAttribLoc(name) + 1, m[1]);


...or is there a better way?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this