How does OpenGL keep its graphics stretched when the window is changed?

Source: Internet
Author: User

Note the following two concepts: the view and the visual body. When the aspect ratio of the view is the same as the aspect ratio of the visual body, the window size is changed and the image is not deformed;

A visual object is a set of spaces where an image is located. It is a collection of spaces.

A single visual object, such as a sphere, should be the smallest external cube of the sphere if it needs to be fully displayed. To show only the upper half, the upper hemisphere is taken, the visual object is the smallest external cube in the upper hemisphere. For the hemisphere, the upper hemisphere is a visual object, so only the upper hemisphere has the display permission, and the lower hemisphere does not. Therefore, even if the sphere is located farther away, only the upper hemisphere can be seen.

If the visual object is only in the upper hemisphere, the canvas mapped to the upper hemisphere is filled with cameras by default. When you move the camera down, the camera screen displays the horizontal line of the upper hemisphere section, and the black background color is below the horizontal line. Even in theory, the camera is facing the lower hemisphere, but because the visual object is only the upper hemisphere, the lower hemisphere does not have the display permission and will not be displayed.

For OpenGL, the visual object means that the space can be displayed. All objects in the space can be displayed and all objects outside the space cannot be seen. If the camera wants to see objects in the space, the camera itself must be in the space of the visual object. If the camera is outside the visual body space, even if the visual body is in front of the camera, the camera still cannot see

 

For example:
Control the size of the View: glviewprot (400,200,); the aspect ratio is 2
The parameters for controlling the visual body are: gluperspective (fovy, 2, near, far );

Add the following code:

 1 void changeSize(GLsizei w, GLsizei h) 2 { 3     if (h == 0) 4         h = 1; 5     glViewport(0, 0, w, h); 6     glMatrixMode(GL_PROJECTION); 7     glLoadIdentity(); 8  9     if (w <= h)10     {11         glOrtho(0.0f, 300.0f, 0.0f, 300.0f * h / w, 1.0f, -1.0f);12     }13     else14     {15         glOrtho(0.0f, 300.0f * w / h, 0.0f, 300.0f, 1.0f, -1.0f);16     }17 18     glMatrixMode(GL_MODELVIEW);19     glLoadIdentity();20 }

Note: You need to use the pixel coordinate system when drawing the image, with the origin in the lower left corner. For example: glrectf (100366f, 100366f, 200366f, 200366f); instead of glrectf (-0.5f,-0.5f, 0.5f, 0.5f );

How does OpenGL keep its graphics stretched when the window is changed?

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.