# OpenGL viewport is stretched

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);


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.

#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;
}

• Do you make sure to update the viewport and projection matrix whenever your window is resized? Feb 27 '20 at 23:18
• Yes, I have a method which gets the window's width and height and adjusts the projection matrix appropriately. Though my problem isn't that the viewport is being stretched, when the window is resized. My problem is that the viewport is already stretched at the start. Feb 28 '20 at 9:48