Skip to main content
added vertex shader
Source Link
user130558
user130558

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

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.

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;
}
added 448 characters in body
Source Link
user130558
user130558

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

MyEDIT: So I update the viewport is set up ineverytime the framebufferSizeCallbackwindow is resized, to it's correct dimensions. But now, even with a 1:1 (600x600) methodaspect, 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:

voidstd::vector<GLfloat> framebufferSizeCallback(GLFWwindowvert *window{
         1, int width0, int height)0,   1.0, 0.0,
{        -1,  0,  0,   0.0, 0.0,
    glViewport(    -1,  1,  0,   0.0, width1.0, 
 height);        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.

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

My viewport is set up in the framebufferSizeCallback() method:

void framebufferSizeCallback(GLFWwindow *window, int width, int height)
{
    glViewport(0, 0, width, height);
}

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.

Source Link
user130558
user130558

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);
glUniformMatrix4fv(glGetUniformLocation(basicShader.ID, "projectionMatrix"), 1, GL_FALSE, glm::value_ptr(projection));

My viewport is set up in the framebufferSizeCallback() method:

void framebufferSizeCallback(GLFWwindow *window, int width, int height)
{
    glViewport(0, 0, width, height);
}