# OpenGL opengl horizontal field of view

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

Hi, I was wondering if anyone knew how to guarantee the horizontal field of view of a window in OpenGL. I've been using gluPerspective to set up the viewing frustum, and using the vertical field of view I want along with setting the aspect ratio to get the result desired (e.g. for a 80 degree horizontal field of view with a 20 degree vertical field of view, I specify the vertical field of view as 30, with an aspect ratio of 4). However, this seems to breakdown when the horizontal field of view gets close to 180 (> 150 or so). I don't have any direct test for this, except that I render an image with this field of view, then read the depth buffer, convert the depths to points, and then render the points on top of the area viewed from an overhead view. When the desired horizontal field of view gets bigger, the footprint of the field of view doesn't seem to match up. Does anyone know at what point the horizontal field of view won't match up to the values indicated by the vertical field of view and aspect ratio? I hope this e-mail makes sense. Thanks for any help. akgreene

##### Share on other sites
If you'll look at this page (http://pyopengl.sourceforge.net/documentation/manual/gluPerspective.3G.html) and see the matrix generated by gluPerspective, you'll see that the x field of view is specified as a function of fovy and aspect: (cotangent(fovy / 2) / aspect). If you generated your own matrix using cotangent(fovx / 2) in place of that element, you might get what you want.

##### Share on other sites
What isn't matching up? How is it not matching up? Are you sure the thing you are matching it with is correct?

The only thing that I can think of is that you are losing precision or resolution as the horizontal FOV gets closer to 180 degrees.

BTW, the aspect ratio is not the ratio of the angles -- it is the ratio of the width to height. With an aspect ratio of 4:1, if the vertical FOV is 20 degrees, the horizontal FOV is 70.4 degrees, not 80. If the vertical FOV is 30 degrees, the horizontal aspect ratio is 94 degrees. Perhaps this is your results aren't "matching up". This equation shows the relationship between FOV and aspect ratio:
    aspect_ratio = tan( HFOV/2 ) / tan( VFOV/2 )

##### Share on other sites
That seems to have been the trick. Thanks for the help.

1. 1
Rutin
41
2. 2
3. 3
4. 4
5. 5

• 18
• 20
• 14
• 14
• 9
• ### Forum Statistics

• Total Topics
633369
• Total Posts
3011536
• ### Who's Online (See full list)

There are no registered users currently online

×