Mutual conversion between glfrustum () and gluperspective () in OpenGL

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.