Mutual conversion between glfrustum () and gluperspective () in OpenGL
In OpenGL, the resize () function is triggered when the window size changes. A new width and height will be input here. In the resize () function, we will set the projection matrix, you can use the basic OpenGL functions glfrustum () and gluperspective. There are few links between the two functions on the Internet, so you can study them yourself.
OpenGL function glfrustum is a function used to create a flat header and create a projection matrix. The gluperspective () function of Glu encapsulates the glfrustum () Basic OpenGL function. The parameters provided by the two are also inconsistent. How does the gluperspective () function encapsulate the glfrustum () function? The Declaration of the two functions is as follows:
glFrustum(GLdouble left,GLdouble right,GLdouble bottom,GLdouble top,GLdouble zNear,GLdouble zFar);gluPerspective(GLdouble fovy,GLdouble aspect,GLdouble zNear,GLdouble zFar);
To understand the relationship between the two, we have to study their principles. The schematic diagram of the two functions is as follows:
After understanding these relationships, you can list the conversion relationships between the two.
Void myperspective (gldouble FOV, gldouble aspectratio, gldouble znear, gldouble zfar) {// you need to add the Glu to use the Glu library function. h header file // gluperspective (FOV, aspectratio, znear, zfar); // use OpenGL functions, but add math. h header file gldouble rfov = FOV * 3.14159265/180.0; glfrustum (-znear * Tan (rfov/2.0) * aspectratio, znear * Tan (rfov/2.0) * aspectratio, -znear * Tan (rfov/2.0), znear * Tan (rfov/2.0), znear, zfar );}
If you cannot use the Glu library for some reason, use the substitution method and glfrustum () function.