OpenGL and C++ projection matrix not working
<p>I'm trying to set up a working camera in c++ with opengl - I want to implement it by myself, not using glm.</p>

<p>I was trying to find my error for long time now, tried much different approaches but it's not working like it should. vector&amp;matrix are implemented in the framework I got at university (row-major).</p>

<p>I thought, setting the camera at +10 @z-axis and placing the object at the origin should at least show anything. But it's just a blue window. If i just load ViewMatrix*ModelMatrix to the vertex shader, I get a rectangle, which is fine. </p>

<p>I'm not sure if I understand near and far plane right - the values are regarding to the position of the camera, right ? So e.g. having the camera positioned at z=10, and having zn=2 &amp; zf = 20, means that the planes are actually positioned on zn=8 and zf=-10, right ?</p>

<pre><code>void Camera::calcProjMatrix() {

float s = 1.0f / (_alpha * tanf(_beta / 2.0f * M_PI / 180.0f ));
float frustum = _zf - _zn;

_projectionMatrix = matrix&lt;float, 4, 4&gt;(0);
_projectionMatrix._11 = s;
_projectionMatrix._22 = s * _alpha;
_projectionMatrix._33 = -(_zf + _zn) / frustum;
_projectionMatrix._34 = -(2 * _zf * _zn) / frustum;
_projectionMatrix._43 = -1;
}

void Camera::calcViewMatrix() {

vector&lt;float, 3&gt; zAxis = normalize(_pos - _target);
vector&lt;float, 3&gt; xAxis = normalize(cross(_up, zAxis));
vector&lt;float, 3&gt; yAxis = cross(zAxis, xAxis);

vector&lt;float, 4&gt; row1 = vector&lt;float, 4&gt;(xAxis.x, yAxis.x, zAxis.x, 0);
vector&lt;float, 4&gt; row2 = vector&lt;float, 4&gt;(xAxis.y, yAxis.y, zAxis.y, 0);
vector&lt;float, 4&gt; row3 = vector&lt;float, 4&gt;(xAxis.z, yAxis.z, zAxis.z, 0);
vector&lt;float, 4&gt; row4 = vector&lt;float, 4&gt;(-dot(xAxis, _pos), -dot(yAxis, _pos), -dot(zAxis, _pos), 1);

_viewMatrix = matrix&lt;float, 4, 4&gt;();
_viewMatrix = matrix&lt;float, 4, 4&gt;::from_rows(row1, row2, row3, row4);   
}
</code></pre>

<p>I'm creating the camera with following parameters:</p>

<pre><code>vector&lt;float, 3&gt; position = vector&lt;float, 3&gt;(0.1f, 0.1f, 10);
vector&lt;float, 3&gt; up = vector&lt;float, 3&gt;(0, 1, 0);
vector&lt;float, 3&gt; target = vector&lt;float, 3&gt;(0, 0, 0);
float beta = 45.0f;
float zn = 2.0f; float zf = 30.0f;
float alpha = 4.0f / 3.0f;

camera = Camera(position, up, target, alpha, beta, zn, zf);
</code></pre>

<p>render loop: (modelmatrix is Identity matrix)</p>

<pre><code>matrix&lt;float, 4, 4&gt; mv = camera.getViewMatrix() * cube.getModelMatrix();
matrix&lt;float, 4, 4&gt; mvp = camera.getProjMatrix() * mv;
shader.loadMatrix4f("mvp", GL_TRUE, mvp._m);
</code></pre>

<p>vertex shader:</p>

<pre><code>#version 410
layout(location=0) in vec3 position;

uniform mat4 mvp;


void main()
{
    gl_Position = mvp * vec4(position, 1.0f);
}
</code></pre>

<p>Thanks for any help!</p>