For this project I am using GLFW, glad and glm.
My window looks like this:
The dimensions of the window are correct, but the viewport is stretched, making my square into a rectangle.
How do I use a 16:9 resolution (1280x720) without my viewport stretching?
This is what the window should look like:
I have a projection matrix set up in my code, and sent to my shader:
projection = glm::perspective(glm::radians(camera.fov), (float)SCR_WIDTH / (float)SCR_HEIGHT, 0.1f, 1000.0f);
glUniformMatrix4fv(glGetUniformLocation(basicShader.ID, "projectionMatrix"), 1, GL_FALSE, glm::value_ptr(projection));
EDIT: So I update the viewport everytime the window is resized, to it's correct dimensions. But now, even with a 1:1 (600x600) aspect, the square remains a rectangle. So I guess it isn't the viewport's fault? So something else is causing the stretch, as far I know the vertices aren't at fault, seeing as they're correct:
std::vector<GLfloat> vert {
1, 0, 0, 1.0, 0.0,
-1, 0, 0, 0.0, 0.0,
-1, 1, 0, 0.0, 1.0,
1, 1, 0, 1.0, 1.0,
-1, 1, 0, 0.0, 1.0,
1, 0, 0, 1.0, 0.0
};
And the modelMatrix is set up correctly, without any changes being made to it.
My vertex shader:
#version 330 core
layout (location = 0) in vec3 Pos;
layout (location = 1) in vec2 TexCoord;
out vec2 texCoord;
uniform mat4 modelMatrix;
uniform mat4 projectionMatrix;
uniform mat4 viewMatrix;
void main() {
gl_Position = projectionMatrix * viewMatrix * modelMatrix * vec4(Pos.x, Pos.y, Pos.z, 1.0f);
texCoord = TexCoord;
}