Issues with GLSL Matrices

07b9e9e8483468e4a0e1bac1843e6e74
1
Snoob 105 Jul 24, 2013 at 12:54 opengl

After upgrading my hardware I now try to migrate my OpenGL 2.x sources to OpenGL 3.x +. Using the fixed function render pipeline my scene is rendered correctly. Now I try to switch to programmable pipeline but I got trouble with my matrices.

I’ve this simple vertex shader:

uniform mat4 projectionMatrix;
uniform mat4 modelViewMatrix;
attribute vec3 vertex;
attribute vec4 color;  
attribute vec2 texCoord0;
// Those values will be passed into the fragment shader.
varying vec4 vColor;  
varying vec2 vTexCoord0;
void main( void )
{     
    gl_Position = projectionMatrix*modelViewMatrix*vec4(vertex, 1.0);
  
    vColor = color;
    vTexCoord0 = texCoord0;
}

The matrix values I directly request from old matrix stack everytime when I update the uniform values with glUniformMatrix4fv. But I only get a black screen, nothing seems to be rendered.

If I use the obsolete GLSL build-in function glModelViewMatrixProjection instead of my uniform matrices anything is rendered as expected. I’ve used APITrace to check if my values are set correct at the shader, everything looks ok. The values are the same used on fixed function pipeline ….

43990 glGetUniformLocation(program = 3, name = "modelViewMatrix") = 65536
43992 glGetFloatv(pname = GL_MODELVIEW_MATRIX, params = {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, -5, 1})
43993 glUniformMatrix4fv(location = 65536, count = 1, transpose = GL_TRUE, value = {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, -5, 1})
43995 glUseProgram(program = 3)
43996 glGetUniformLocation(program = 3, name = "projectionMatrix") = 0
43998 glGetFloatv(pname = GL_PROJECTION_MATRIX, params = {2.897056, 0, 0, 0, 0, 2.414213, 0, 0, 0, 0, -1.0002, -1, 0, 0, -0.20002, 0})
43999 glUniformMatrix4fv(location = 0, count = 1, transpose = GL_TRUE, value = {2.897056, 0, 0, 0, 0, 2.414213, 0, 0, 0, 0, -1.0002, -1, 0, 0, -0.20002, 0})

Any idea what could be wrong? Is there a way to check what the glModelViewMatrixProjection call returns?

2 Replies

Please log in or register to post a reply.

A8433b04cb41dd57113740b779f61acb
0
Reedbeta 167 Jul 24, 2013 at 15:02

I don’t think you want to set tranpose to true in your glUniformMatrix calls, as the matrix returned from glGetFloatv will already be in the same column-major format the shaders expect.

07b9e9e8483468e4a0e1bac1843e6e74
0
Snoob 105 Jul 25, 2013 at 05:20

Thanks for the hint with the transponse, this fixes the failure.