Search code examples
c#openglopentk

How to fix proportions of output


I have my OpenGL graphic where I'd like to fix proportions. What I actually have now.

While my form has normal proportions (like 4:3) everything looks nice. But when I re-size form to approx (20:2) image becomes outstretched (this effect I'd like to avoid).


Normal proportions

normal proportions

Outstretched proportions

outstretched proportions

I use shaders approach. My matrices set-ups looks like:

    projectionMatrix = Matrix4.CreateOrthographic(Width, Height, 10000f, -10000f);
    viewMatrix = Matrix4.CreateTranslation(0.0f, 0.0f, 0.0f);
    modelMatrix = Matrix4.Scale(1.0f);

When render:

        viewMatrix = Matrix4.CreateRotationY((float)xrot) *
                     Matrix4.CreateRotationX((float)yrot) *
                     Matrix4.Scale((float)scale);

        program.SetValue(projectionMatrix);
        program.SetValue(viewMatrix);
        program.SetValue(modelMatrix);

Solution

  • You must recreate and resubmit to OpenGL the projection matrix when the window's aspect ratio changes to reflect that.