OpenGL
is inherently a 3D API. However,
sometimes it is convenient to switch to “2D mode”, based on the screen size in
pixels.
This
can be achieved by changing the projection matrix using
glm::ortho(0, w, 0, h);
where
[w, h]T is the window size, and using an
identity matrix for the modelview matrix.
In
the template code, there is an orthographic projection matrix based on the
window size already defined. Use it, and
an identity matrix for the modelview to enter “2D mode”:
fontProgram->SetUniform("matrices.projMatrix", pCamera->GetOrthographicProjectionMatrix());fontProgram->SetUniform("matrices.modelViewMatrix",
glm::mat4(1));Typically one does 2D rendering
last, after all the 3D rendering has occurred.
Example: in the template, the
text is rendered after
the
3D graphics.

Once
we’re in “2D mode”, units are in pixels.
The OpenGL coordinate system will be:

To
render a full-screen quad, simply draw a triangle strip to fill the screen (can
be done with four vertices v0 v1 v2 v3). z values can be 0. For example:
modelViewMatrixStack.Push();
modelViewMatrixStack.SetIdentity();
pMainProgram->SetUniform("matrices.modelViewMatrix",
modelViewMatrixStack.Top());
pMainProgram->SetUniform("matrices.projMatrix", m_pCamera->GetOrthographicProjectionMatrix());
m_pQuad->Render(); // Render quad in 2D mode
modelViewMatrixStack.Pop();