GLSL matrix storage

Started by
3 comments, last by V-man 16 years, 8 months ago
To summarize I print the matrix (projection*modelview) to a file. In the shader I use a static mat4 with those printed numbers, but the results are not the same as using gl_ModelViewProjectionMatrix; In software, I did this (in pseudocode): float model[16], projection[16], final[16]; glGetMatrix(GL_MODELVIEW, model); glGetMatrix(GL_PROJECTION, projection); glLoadIdentity(); glMultMatrix(projection); glMultMatrix(model); glGetMatrix(GL_MODELVIEW, final); <<----I saved the final as (projection*model); In the shader I use: //modelview is actually (projection*modelview) as previous line above shows. gl_Position = gl_ModelViewMatrix*gl_Vertex; This works perfectly fine. But if I print final to a txt file, and use a static mat4 final = mat4{final[0], final[1].......), then this code doesnt work: gl_Position = final*gl_Vertex;

NBA2K, Madden, Maneater, Killing Floor, Sims http://www.pawlowskipinball.com/pinballeternal

Advertisement
What happens if you use 'final' in your shader? Nothing gets displayed or the object being rendered is not proper?
How are you passing the array 'final' to your shader ?
Is it passed correctly ? I dont see any other reason.


Best Regards,KumGame07
I don't see anything wrong with your code.

Anyway, is there a particular reason you are doing it this way?

It's best to upload you projection matrix to GL_PROJECTION and modelview to GL_MODELVIEW

and in your shader, just stick a

gl_Position = ftransform();

Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
When I use final, I'm not sure exactly what it does but its not right.

I can't use ftransform() as its for skeletal animation. Which btw, What is the proper way to send a mat4 to a shader?

NBA2K, Madden, Maneater, Killing Floor, Sims http://www.pawlowskipinball.com/pinballeternal

Put this in shader
uniform mat4 mymatrix;
and get the location and then
glUniformMatrix(location, FALSE, array_with_matrix, 1);


Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

This topic is closed to new replies.

Advertisement