width of windows and vbo data vertexes

hello,
I use this chunk of code for setup a windows for opengl 3.3:


HWND CreateAppWindow(const WNDCLASSEX &wcl, const char *pszTitle)
    {
        // Create a window that is centered on the desktop. It's exactly 1/4 the
        // size of the desktop. Don't allow it to be resized.

        DWORD wndExStyle = WS_EX_OVERLAPPEDWINDOW;
        DWORD wndStyle = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU |
                         WS_MINIMIZEBOX | WS_CLIPCHILDREN | WS_CLIPSIBLINGS;

        HWND hWnd = CreateWindowEx
            (wndExStyle, wcl.lpszClassName, "title",
                    wndStyle, 0, 0, 0, 0, 0, 0, wcl.hInstance, 0);

        if (hWnd)
        {
            int screenWidth = GetSystemMetrics(SM_CXSCREEN);
            int screenHeight = GetSystemMetrics(SM_CYSCREEN);
            int halfScreenWidth = screenWidth / 2;
            int halfScreenHeight = screenHeight / 2;
            int left = (screenWidth - halfScreenWidth) / 2;
            int top = (screenHeight - halfScreenHeight) / 2;
            RECT rc = {0};

            SetRect(&rc, left, top, left + halfScreenWidth, top + halfScreenHeight);
            AdjustWindowRectEx(&rc, wndStyle, FALSE, wndExStyle);
            MoveWindow(hWnd, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, TRUE);

            GetClientRect(hWnd, &rc);
            m_windowWidth = rc.right - rc.left;
            m_windowHeight = rc.bottom - rc.top;
        }

        return hWnd;
    };

The problem is that i can’t understand how the vbo vertexes are related to the window.
For example i use these points:
-1.0, -1.0, 0.5;
-1.0 , 1.0, 0.5;
1.0, 1.0, 0.5;

and i use this two shaders:
vshader:
i set the uniform mat4 MVP to identity


#version 330
in vec3 VertexPosition;
uniform mat4 MVP;
void main()
{
    gl_Position = MVP * vec4( VertexPosition, 1.0 );
    
}

and this fragment shader(the uniform vec4 color is set corrected by my project:


#version 330

out vec4 outputColor;
uniform vec4 color;
void main()
{   
    outputColor = color;
}

I think that the vbo data is from -1 to 1, the problem is that the triangle is not correct, it must be the half of the screen but it isn’t, is more smaller.
How i can create a triangle that is half of the entire screen ? and how are related the vbo vertexes to the width and height of the screen?
my goal is be able to set the entire coordinate for example 800 if the width of the screen is 800 ecc…
is possible?
my viewport recreated always in the render loop is
glViewport(0.0, 0.0, 800, 600);

thanks.

I find this OpenGL Transformation one of the easiest explainations

i see your article and i try to use a orthographics projection.
i use glm for that
the vbo points are related to the viewport, is correct?

If so

1)i can create a window of 400 x 400

2)set this vbo :


-1,-1,0
-1, 1, 0
1,1,0

3)set the ortho matrix with glm(m_MP = glm::ortho(-1, 1, -1, 1); to


{1, 0, 0, 0}
{0, 1, 0, 0}
{0, 0, -1, 0}
{-0, -0, 0, 1}

4)all works fine.

but i wish use pixel coords:

1)ok,

2)set this vbo


0, 0, 0
0,400,0
400,400,0

3)the ortho matrix sended to the shader as a mvp(now i change the name)m_MP = glm::ortho(0, 400, 0, 400) is :



{0.0049999999, 0, 0, 0}
{0, 0.0049999999, 0, 0}
{0, 0, -1, 0}
{-1, -1, 0, 1}

but,i see nothing

this is all that i change , from the first to the second i change only the ortho projection and the vbo points from -1 1 to 0 400 ecc…

thanks again for your help, and sorry if i 'm a newbe

and the mview matrix is to use? i suppose that is identity .

i sue opengl 3.3.
thanks and by.

I am not sure what is wrong - I tried your code and it worked fine


 Shader* shader = EnableShader(SYSTEM_SHADER_DEFAULT));
  glm::mat4 s = glm::ortho(0.0f,400.0f,0.0f,400.0f);
  shader->SetMatrix4x4Parameterv("u_mvp",glm::value_ptr(s));

  C3D_Batch_UserShader batch(3);
  batch.Begin(GL_TRIANGLES,3);
    batch.Vertex3f(0,0,0);
    batch.Vertex3f(0,400,0);
    batch.Vertex3f(400,400,0);
  batch.End();


vertex shader


#version 410 core
layout(location = VERTEX_BINDINGS_POSITION) in  vec3  Position;

uniform mat4 u_mvp;

void main()
{
  gl_Position = u_mvp * vec4(Position,1);
}

frag shader


#version 410 core
layout(location = 0, index = 0) out vec4 fFragColour;


void main()
{
    fFragColour = vec4(1,0,0,1);
}