Perspective Projection with an 'orthographic' view

I’ve been dealing with OpenGL for a while now, but have stuck with orthographic projection since mine is really a 2d app. So now I find that I never really ‘got’ the matrix system, just stuck with simple transforms. Even when I try to set perspective projection, then transform back to the correct view size, I seem to undo the perspective. I’m going to add perspective back in so that a quad looks right when rotated, but need to keep the ‘perfect’ orthographic result when it’s flat.

But now I look at what I need to do in a vertex shader, it starts to look a little clearer. Basically every vertex just gets multiplied by a 4d matrix, right?

So, here’s what I need to work out. What matrix will keep all the items on one plane - lets say z=vpZ, untouched and apply perspective to other values. The best example would be a 1920 x 1080 viewport (and 1920x1080 view), then I’ll draw a 1920 x 1080 at vpZ, centered on the x and y axes. I need the texels to exactly match the screen pixels.

How would I work out the matrix I need? Is that a projection matrix, then I use the ModelView matrix as normal?



Hi Bruce,

If you have w, h, and zp that will allow you to draw exact pixels with x in [-w/2, w/2], y in [-h/2, h/2] at z = -zp in eye space, you should use

gluPerspective( to_degrees( 2 * arctan( h / ( 2 * zp) ) ), w / h, zp / 2, 3 * zp / 2 );

You could use different zNear and zFar values, but zp needs to be in that range.

Or something like that…

Thanks -

Thanks, I’ll try that.