openglclippingorthographic

Othographic projection causing geometry to get clipped by the far plane


Let's say I have a rectangle that I want to render oriented 45 degrees about the x-axis to the camera. So it looks like this:

enter image description here

(clipped at the bottom only because it's the edge of the window).

As I shift this rectangle along it's local y-direction though (i.e. increase y on it's vertices before we rotate it about the x-axis) then it eventually gets clipped by the far plane:

enter image description here

How do I prevent this? It seems unnatural that the rectangle should be cut off at all when moved away from the viewport but still within actual view.

I do definitely want to render my rectangles orthographically.

I am quite new to OpenGL so I'm thinking I'm missing something here.


Solution

  • The trick it turns out is just to squish the z position of the vertices in the vertex shader. This way more vertices can fit inside the frustrum. This does distort the mesh but in orthographic projection this actually doesn't make a visible difference (at least in my situation).

    I.e. inside the vertex shader do this:

    gl_Position.z *= 0.5; // or whatever scale you want