Lately, I’ve been writing a matrix implementation of my own to replace the built-in matrix stack that is deprecated as of OpenGL 3.0 and finally removed in core 3.3 / 4.0. The exact profile I’m developing for is core OpenGL 3.2 / GLSL 150.
Referring to the detailed instructions provided here, I’ve set up my perspective projection matrix as follows (symmetric viewing frustum):
I figured the only way to clearly display matrices on the forums would be to typeset them with LaTeX ;). The values -2.22 and -1.22 (obviously) suffer from truncation.
Anyway, however, the rendering result doesn’t quite match the one I’m expecting to see (the primitive is deformed beyond recognition; vertices at the boundaries of the viewing volume seem to be approaching infinity). More often than not I would initially see an completely black scene, and with a simple keyboard control mechanism was, on occasion, able to get at least something to show up.
Now, please take a moment to look at the actual code I’m working with. Here are the relevant bits (btw, I’m using the Eigen library, which by default uses column-major storage order):
uni_modelview_loc = glGetUniformLocation(programHandle, "ModelView");
uni_projection_loc = glGetUniformLocation(programHandle, "Projection");
...
//The matrices projection, model and view have been initialized as shown above
//premultiply these two
Eigen::Matrix4f modelview = model * view;
glUniformMatrix4fv(uni_modelview_loc, 1, GL_FALSE, modelview.data());
glUniformMatrix4fv(uni_projection_loc, 1, GL_FALSE, projection.data());
/* set up attribpointers and draw scene */
// VERTEX SHADER
#version 150
in vec3 in_position;
in vec3 in_normal;
uniform mat4 ModelView;
uniform mat4 Projection;
out vec3 vvertex;
out vec4 vnormal;
void main(void)
{
gl_Position = Projection * ModelView * vec4(in_position, 1.0);
vnormal = vec4(in_normal, 1.0);
}
Without providing any matrix uniforms to the shader, the primitive is rendered correctly. Weirdly enough, reversing the order in which the matrices ModelView and Projection are multiplied (again, in the shader) sometimes yields a result one could consider a perspective projection of sorts, but still not the one I would have expected (i.e. one similar to the default projection).
Please point out the error(s) I may be failing to see here. If required, images demonstrating this issue can also be arranged.