Really weird glUniform error with matrices

Hi all,

Relatively new to the OpenGL3.x way of doing things, but I’ve been working to make a simple graphics engine that doesn’t use any deprecated functions. I’ve gotten everything to work using non-deprecated functions except for the modelview/projection transformations - I’m still doing it like this:


glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0, 0.0, -5.0);
glRotatef(rotx, 1.0, 0.0, 0.0);
glRotatef(roty, 0.0, 1.0, 0.0);
glRotatef(rotz, 0.0, 0.0, 1.0);

and in the vertex shader I’ve accessed the built in uniforms:


gl_Position = gl_ModelViewProjectionMatrix*vec4(position, 1.0);

That worked well, but I would like to be able to create my own matrices and send those over to the graphics cards with glUniformMatrix4fv. I tried to do this, and the vertices stopped transforming properly. Just to make sure I called glUniform correctly, I pulled out the matrix value that I sent over to the card like so:


MAT4 tmp = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0}; //a test matrix just to see what was happening more precisely
memcpy(world_matrix, tmp, sizeof(GLfloat)*16);
glUniformMatrix4fv(U_world_matrix, 1, GL_FALSE, world_matrix);
glGetUniformfv(program,  U_world_matrix, &world_matrix);

world_matrix exists and is used in the vertex shader, but I find that it has this with glGetUniformfv:

world_matrix:
[0.20, 0.20, 0.20, 1.00
 5.00, 6.00, 7.00, 8.00
 9.00, 10.00, 11.00, 12.00
 13.00, 14.00, 15.00, 16.00]

In fact, every matrix I send has that same starting sequence of values - 0.2, 0.2, 0.2, 1.0. Does anybody have any idea why this is the case?

I’m implementing this whole thing in linux in C, and I’ve got an (old) nvidia quadro nvs 110m that this is running on. I can send any other uniform just fine, but when I try to send a matrix, the first four values are always 0.2, ,0.2, 0.2, 1.0, even with a mat3. Does anybody have any idea at all why this is the case? I think it might be a driver issue only because I’m doing this in linux, but I have no idea what’s going on.

Thanks for the help.

I’m guessing that “U_world_matrix” isn’t quite the matrix uniform’s location.

Right you are - for some weird reason, glGetUniformLocation is returning one value for two different strings. This I’m not sure of, but it does explain that weird 0.2, 0.2, 0.2, 1.0 row, that’s what I was setting a light’s color to later on in the program. Now I just have to find out why glGetUniformLocation isn’t returning unique values.

Thanks for the help!

Yeah, consider this thread closed - turned out that I was trying to be clever with how I was getting my uniform locations and ended up shooting myself in the foot. Turned out to just be a parenthesis mismatch causing the whole bug.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.