Horizontal/Vertical angle conversion

I am having difficulties converting from horizontal to vertical view angles. I have to convert a program to OpenGL that passes its field of view as a horizontal angle but OpenGL requires a vertical angle. Is there any reliable way to convert between those 2 that takes the current aspect ratio into account? I’ve got something that works for 4:3 but it is more or less random messing around with the values and doesn’t help with other aspect ratios.

A little trigonometry solves this:

fovy = 2 * atan((h/w) * tan(fovx / 2))


fovy = 2 * atan(tan(fovx / 2) / aspect)

Here fovx and fovy are the opening angles in x and y respectively, and w and h are the width and height.

Note that this is only correct for gluPerspective-style (ie non-oblique frustums).