OpenGL viewport distortion

I am still new to OpenGL. I am trying to draw a perfect square on a 1280 by 720 screen using shaders.

I am using the main OpenGL profile, version 3.3. I was stuck with this when I tried to draw a square at 1280 by 720

enter image description here

After some time of searching, I realized that the size is distorted by the size in the viewport, after changing the size of the viewport to 720 by 720, I got this.

This is in a 720 by 720 viewport

In legacy OpenGL, they have a solution to fix this, but now it is deprecated in the Core profile.

Problem: how can I draw a perfect square in 1280 x 720 screens using only the main OpenGL 3.3 profile?

0
source share
2

. , , , OpenGL . , , , :

uniform mat4 ProjMat;
in vec4 InPosition;
...
    gl_Position = ProjMat * InPosition;

++ glUniformMatrix4fv().

, . , . , .

, - , (). w h :

if (w > h) {
    glViewport(0, (h - w) / 2, w, w);
} else {
    glViewport((w - h) / 2, 0, h, h);
}

.

+1

(2.0/width, 2.0/height). , .

, .

0

All Articles