PDA

View Full Version : Problem with Uniforms and matrices



lemi13
04-07-2016, 06:01 AM
Hello!
Before i start i would like to point out that im really bad when it comes to programming and im trying to learn it.:whistle:

So i am trying to get a 3d application with a camera and with the help of uniforms. I want a setUniform to have both a location and a 4v4 matrix (glm::mat4).
But i googled around for glUniform to use and stumble across a problem. I tryied glUniform4ui but than it complains about (glm::mat4) and says that the type name is not allowed. Than i got help from a guy who said that i should use glUniformMatrix4fv and still got the same error. As i said in the beginning im really bad at programming and still trying to learn it so please dont be harsh on me if im missing some major point here. :D

Thanks in advance!


void ShaderManager::setUniform(GLuint gMyUniformLocation,glm::mat4)
{
glUniformMatrix4fv(gMyUniformLocation, glm::mat4);
}

GClements
04-07-2016, 03:05 PM
void ShaderManager::setUniform(GLuint gMyUniformLocation,glm::mat4)
{
glUniformMatrix4fv(gMyUniformLocation, glm::mat4);
}

You're confusing variables with types. glm::mat4 is a type, not a variable. You need a variable of that type, and to pass it to the function, which should look like e.g.



void ShaderManager::setUniform(GLuint gMyUniformLocation, glm::mat4 matrix)
{
glUniformMatrix4fv(gMyUniformLocation, matrix);
}

lemi13
04-08-2016, 12:38 AM
Well did as you said but now its complaining on something else :S

https://gyazo.com/17abad2a08fd0d86ffee405d98786f7e

Spoops
04-08-2016, 10:50 AM
Two arguments are missing, and glUniformMatrix4fv expects a pointer, not a glm::mat4. Read the documentation (https://www.opengl.org/sdk/docs/man/html/glUniform.xhtml).

It should look like this :
glUniformMatrix4fv(gMyUniformLocation, 1, GL_FALSE, glm::value_ptr(matrix));