How to Implement OpenGL

Source: Internet
Author: User

View Original

Http://www.ibaiyang.org/2012/12/27/a-opengl-like-implementatio/

 

People who have learned OpenGL know that the design of OpenGL state machine is really impressive. Each State will continuously affect the rendering of subsequent objects until the state is changed.

OpenGL maintains two sets of matrices, the pattern view matrix, and the projection matrix. These two sets of matrices complete all the geometric changes from 3d to 2D, including rotation, scaling, translation, and projection. At the same time, OpenGL maintains two stacks, one storage mode view matrix and the other storage projection matrix.

Never underestimate the design of this stack. Let's take an example.

Draw_object (1) rotate (1) Translate (1) push_matrix () draw_object (2) rotate (2) Translate (2) pop_matrix () draw_object (3)

Among them, rotate (2) and translate (2) do not affect the draw_object (3) function, because the previous push_matrix will press the current into the stack. When draw_object (2), pop_matrix () the previous status is restored, so when draw_object (3), it is restored to the rotate (1), translate (1) status.

I took the time to use Python and pyqt to basically implement the 3D OpenGL function and simulate the two stacks.
CodePut it in my GitHub.
Https://github.com/baiyang/valleygl

The following shows the running effect of the Code:

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.