I'm trying to set up perspective projection in OpenGL but it doesn't work
void Camera::setViewportSize(float left, float right, float bottom, float top)
{
constexpr float fov = glm::radians(45.0f);
m_projectionMatrix = glm::perspective(fov, (right - left) / (top - bottom), 0.1f, 10.0f);
recalculateViewMatrix();
}
void Camera::recalculateViewMatrix()
{
glm::mat4 translate = glm::translate(glm::mat4(1.0f), glm::vec3(m_position, 0.0f));
glm::mat4 rotate = glm::rotate(glm::mat4(1.0f), m_rotation, glm::vec3(0.0f, 0.0f, 1.0f));
glm::mat4 scale = glm::scale(glm::mat4(1.0f), glm::vec3(m_scale, m_scale, 1.0f));
m_viewMatrix = translate * rotate * scale;
m_viewMatrix = glm::inverse(m_viewMatrix);
m_viewProjectionMatrix = m_projectionMatrix * m_viewMatrix;
}
I upload viewProjectionMatrix to shader and use it like this:
gl_Position = u_viewProjectionMatrix * vec4(a_position, 1.0);
It just doesn't show anything. I double checked if I pass good left, right, bottom, top values and it should be all good. Playing with zNear and zFar didn't change anything. Note - When I use ortho, it works like a charm:
m_projectionMatrix = glm::ortho(left, right, bottom, top, 1.0f, -1.0f);
Update I did add model matrix and I translated it -2 units on z axis. I can see the lines: But they are disorted. They
They should be (0.0f, 0.0f), (100.0, 100.0) (0.0f, 0.0f), (600.0f, 800.0f) Itat positions:
line1: (0.0f, 0.0f), (100.0, 100.0)
line2: (0.0f, 0.0f), (600.0f, 800.0f)
It seem like the centre of screen is at (0, 0)???