glm::perspective(fov,
aspect, near, far);
glm::perspective
creates a 4x4 perspective projection matrix that is used in a shader
(typically, vertex shader) to transform points.
A
few tips:
- Often,
one sets up the projection transformation and does not change it during the
course of a game, unless user changes the window
- Think
of znear and zfar as
distance from the camera
- A
vertical field of view of 45 degrees is reasonable
- The
aspect ratio should match the window size
- Don’t
use zero for znear (use a small number like 1.0 instead)

Some
OpenGL programmers combine the modelling, viewing, and projection matrices, and
pass the combined matrix to the vertex shader.
mMVP = mProjectionMatrix * mViewingMatrix * mModelingMatrixExample:glm::mat4 mProjection =
glm::perspective(45.0f, (GLfloat)width
/ (GLfloat)height,
1.0f, 150.0f);This creates a viewing volume with a 45
degree field of view in the y direction (in eye coordinates) for the given
window size (width, height). The near
clipping plane is 1 unit away from the camera, and far clipping plane is 150
units away.