# OpenGL Horizontal FOV?

This topic is 4864 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

How do I get the horizontal FOV from OpenGL?

##### Share on other sites
Extract the left and right frustum planes from the projection matrix, and compute the angle between both using the dotproduct of their normals.

##### Share on other sites
Of course, the easiest way is to have it in the first place. If the projection matrix is from calling gluPerspective, you passed in the horizontal FOV. it's from calling glFrustum, you can easily calculate the horizontal FOV from the left, right, and near parameters.

##### Share on other sites
To add to the above, here's some additional info. If you created the frustum using gluPerspective(), you must already have the vertical fov since that's one of the arguments. Here are a couple of utility functions that convert back and forth between horizontal and vertical fov's:

float xfov_to_yfov(float xfov, float aspect) {    xfov = Math::DegToRad(xfov);    float yfov = 2.0f * Math::ATan(Math::Tan(xfov * 0.5f) / aspect);    return Math::RadToDeg(yfov);}float yfov_to_xfov(float yfov, float aspect) {    yfov = Math::DegToRad(yfov);    float xfov = 2.0f * Math::ATan(Math::Tan(yfov * 0.5f) * aspect);    return Math::RadToDeg(xfov);}

If you created the frustum through glFrustum() or some other means, than as has been suggested you'll have to figure out the fov yourself from the function arguments or frustum planes.

##### Share on other sites
Great! thanks alot to all of you.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 14
• 12
• 29
• 11
• 44
• ### Forum Statistics

• Total Topics
634856
• Total Posts
3019659
×