Switching from perspective orthographic projection in OpenGL

2.2k Views Asked by At

I'm really new to OpenGL and trying to learn from the 'modern' OpenGL tutorials.

I'm using C# and OpenTK.

I'm setting my projectionMatrix with this code:

_projectionMatrix = Matrix4.CreatePerspectiveFieldOfView(MathHelper.PiOver3, GetAspectRatio(), 0.1f, 100f);

After I set it, I upload it to the shaders, use for transformations, etc. Everything is working well this way, as the image below shows:

enter image description here

Now if I set my projection matrix this way, the result is very bad as the next image shows:

_projectionMatrix = Matrix4.CreateOrthographic(GLControl.ClientSize.Width, GLControl.ClientSize.Height, 0.1f, 100f);

enter image description here

Not only the new view is very strange, but if I move forward the scene, the objects starts to clipping, even having znear close to zero.

How can I set the orthographic projection correctly so I can have a view close to what I have in perspective?

1

There are 1 best solutions below

1
On BEST ANSWER

It seems like you're having trouble understanding orthographic projections.

There are several reasons why your scene doesn't look right in an orthographic view:

  • The perspective projection gives the appropriate depth to the floor so it can be seen; objects look bigger when they're closer to you. But the orthographic projection doesn't change their size according to their depth. Moreover, the reason the floor "disappears" in the orthographic projection is that the floor is "infinitely thin" and oriented horizontally.
  • Your orthographic projection resizes the screen so that one pixel in window space corresponds to 1 unit in object space. Since the rings are (it seems) about 12 units in size, they will look rather small on the screen. One solution may be to use a smaller size in CreateOrthographic. But this won't solve everything; for instance, the floor will still remain "invisible".

Note also:

  • If you use an orthographic projection, you can even use negative values for zNear, but probably not 0. This isn't the case for a perspective projection.
  • The orthographic projection can form the basis for a 3D-like projection called the isometric projection.