# Perspective projection in Open GL

I am trying to convert a 3d point into a 2d point using a perspective projection. I'm new to OpenGL and may not have fully understood how this works. How exactly do I calculate the near and far values?

The vertex values I want to consider are between 1, 1, 1 and 16, 16, 16. So if I consider a output texture of size 16 x 16. Will my near and far be 0 and 16 respectively?

Does this transformation take care of scaling my vertex values between 0 and 1 as well?

## 1 Answer

You don't usually calculate these, you set them to a value, and you tweak them depending on the outcome. There are some limitations too:

The near plane needs to be bigger than 0, but if it's too small, then you'll have some issues later. OpenGL has a higher precision closer to the camera, and with a near plane of 0.01 units, the difference between the actual distance and the distance based on the depth buffer'll be around 100 units at 1000 units, which results in z-fighting. If the far plane is too high, then the same thing can happen.

You should probably use 0.1 for the near plane distance and 100 or 50 for the far plane distance. There's virtually no reason to go below these.

• Thanks! And the vertex I pass to the perspective matrix would be the real world vertices right ( (1, 1), (2, 2) etc ) or do they have to be adjusted to fit between 0 and 1? – Kirit Thadaka May 12 '17 at 16:28
• @KiritThadaka The perspective matrix does that for you, so you don't have to provide the data like that. If the answer was helpful, don't forget to accept it – Bálint May 12 '17 at 17:20