# How to set focal length in OpenGL^\_^

**URL:** <https://community.khronos.org/t/how-to-set-focal-length-in-opengl/46176>\
**Category:** OpenGL: Advanced Coding\
**Created:** [April 4, 2007, 11:06pm UTC](https://community.khronos.org/t/how-to-set-focal-length-in-opengl/46176 "2007-04-04T23:06:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![hawaii](https://community.khronos.org/letter_avatar_proxy/v4/letter/h/ac8455/32.png) [@hawaii](https://community.khronos.org/u/hawaii)\
**Post date:** [April 4, 2007, 11:06pm UTC](https://community.khronos.org/t/how-to-set-focal-length-in-opengl/46176/1 "2007-04-04T23:06:00Z")

</div>

I was working on an algorithm. Focal length is an crucial parameter in my algorithm.

At first, I think the near\_plane parameter which is used in gluPerspective(fovy, aspect, near\_plane, far\_plane) is related to focal length. But I tried and failed ☹

Could anyone who have ever used this help me please? Thank you 🙂

Best regards,  
Hawaii

---

<div class="post-metadata">

**Author:** ![Mazy](https://community.khronos.org/letter_avatar_proxy/v4/letter/m/fbc32d/32.png) [@Mazy](https://community.khronos.org/u/Mazy)\
**Post date:** [April 5, 2007, 1:08am UTC](https://community.khronos.org/t/how-to-set-focal-length-in-opengl/46176/2 "2007-04-05T01:08:00Z")

</div>

You need to know more than focal length to set the corret FOV(which is what you can use with gluperspective(…) )

To calculate the FOV from a focal length you also need the projected area size ie. “frame size” you are using.

FOV (rectilinear) = 2 \* arctan (frame size/(focal length \* 2))

Here “frame size” refers to the dimension of the frame in the direction of the FOV, so for 35mm (which is 24mm x 36mm), frame size is 36mm for the horizontal FOV, 24mm for the vertical FOV and 43.25mm for the diagonal FOV

---

<div class="post-metadata">

**Author:** ![hawaii](https://community.khronos.org/letter_avatar_proxy/v4/letter/h/ac8455/32.png) [@hawaii](https://community.khronos.org/u/hawaii)\
**Post date:** [April 5, 2007, 2:05am UTC](https://community.khronos.org/t/how-to-set-focal-length-in-opengl/46176/3 "2007-04-05T02:05:00Z")

</div>

Thank you, Mazy 🙂 But I still have two questions to ask.

1, Is focal length equal to the distance from the viewpoint to the projection plane?

2, I can set the value of focal length by setting the value of fov, and fov is calculated through the formula that you posted, is that correctï¼Ÿ

I am looking forward to your reply 🙂

Thanks again 🙂

HuoYi

---

<div class="post-metadata">

**Author:** ![Mazy](https://community.khronos.org/letter_avatar_proxy/v4/letter/m/fbc32d/32.png) [@Mazy](https://community.khronos.org/u/Mazy)\
**Post date:** [April 5, 2007, 2:50am UTC](https://community.khronos.org/t/how-to-set-focal-length-in-opengl/46176/4 "2007-04-05T02:50:00Z")

</div>

Focal length is the number of millimeters from the lens to the focal point, it’s a property of a lens so i don’t think you find it directly equal to any number in OpenGL.

If you know what focal length your imaginary lens should have and what imaginary camera you want to simulate then you just calculate the FOV and use gluperspective. the Far and Near plane has nothing to do with that property, they are only there to clip anything outside those values, and thats not happening in real life.

---

<div class="post-metadata">

**Author:** ![hawaii](https://community.khronos.org/letter_avatar_proxy/v4/letter/h/ac8455/32.png) [@hawaii](https://community.khronos.org/u/hawaii)\
**Post date:** [April 5, 2007, 5:19am UTC](https://community.khronos.org/t/how-to-set-focal-length-in-opengl/46176/5 "2007-04-05T05:19:00Z")

</div>

To Mazy:

Thank you very much for your kindly instructions. But I am sorry because I think I confused focal length with the distance from viewpoint to projection plane. So I want to explain my question again.

I use OpenGL to realize my algorithm. I need to change the distance from the viewpoint to the projection plane. I believed it is same to the concept of focal length at first. But From your explanation, I think they are different.

So do you know how to change the distance from the viewpoint to the projection plane by using OpenGL? Thank you 🙂 I hope you could help me 🙂

I appreciate your kindness very much 🙂

Hawaii
