2.2 Orthogonal projection, observation box, world coordinates

Source: Internet
Author: User

Experiment 2.2 shows that the vertex's coordinate value is not any absolute unit on the screen (the screen unit is pixels).

Glortho (Left,right,bottom,top,near,far) establishes an observation box (viewing box) with 6 parameters to determine the position of six faces.

Recently engaged in OpenGL, originally thought oneself to glortho this function already understood, the result found that oneself did not understand at all.

First, the prototype of the Glortho function is void Glortho (gldouble left,gldouble right,gldouble bottom,gldouble top,gldouble near,GLdouble far). I had always thought that the near and far designations were the z-coordinates of the planar and the distant planes, knowing that it was not the case that the program started writing OpenGL today. First, the function defines the drawing space as follows:

The coordinates of the graph we draw ourselves can only be in this space, or we will not see our own drawing.

But near and far are not the z-coordinates shown in the proximal and distant planes. The coordinates of the lower-left corner of the near-plane rectangle are (left,bottom,-near), the coordinates of the upper-right corner are (right,top,-near), the lower-left corner coordinates of the far-plane rectangle are (Left,bottom,-far), and the upper-right coordinates are (right,top,- FAR). So, the actual near and far plane coordinates are not simply specified by the proximity and far, but by-near and-far.

So what does the near and far plane do for us? One of the most important is in-depth testing. If we want to implement objects close to us that block distant objects, then we should enable the depth test via glenable (Gl_depth_test), which will be compared with the current depth buffer before each object is drawn, and then decide whether to render the current input drawing instructions. First, if we enable depth testing, we typically use Glclear (gl_depth_buffer_bit) before drawing, setting the value of all depth buffers to the maximum value (which is generally the value of the far plane previously mentioned). In the subsequent drawing process, the graph depth value in the current drawing designation, the Z-value, is compared to the value of the corresponding pixel in the depth buffer, and if it is closer to the near plane (rather than simply comparing the numeric size, but teller the position of the near plane), the graphic is drawn, and modifies the value in the depth buffer to the z-value of the specified shape in the current drawing specified, otherwise, the graphic is not drawn and the value in the depth buffer is not changed.

Depth testing is also important when blending. First, if there is a transparent object in the scene that needs to be rendered, then the opaque object is drawn first. Because, when a transparent object is drawn, the color of the object specified by the current drawing instruction is the source color, and the color in the current color buffer is the target color, and the source color is blended with the target color by a certain formula (Formula reference 3). For example, draw a background, draw a transparent object, and then draw a position behind a transparent object (as opposed to a transparent object, away from the near-surface) of the opaque object, you will not get the effect you expect. This is because when you draw a transparent object, the background color is stored in the current color buffer, and the color of the transparent object is blended with the background color. When you draw an opaque object, even if an opaque object is larger than a transparent object, the transparent object cannot block the opaque object, and because of the depth test, the opaque object is not drawn on the area of the transparent object, and the color of the opaque object's position is the mixed color of the opaque object and background. Without creating a mix of transparent objects and opaque objects that you want.

Then, in the case of mixed situations, the general practice is to open the depth test first, and then draw all the opaque objects, because of this time there is a depth test, the order of the drawing is not necessarily in accordance with the object near the near-plane in order to draw. Then use the function Gldepthmask (gl_false) to set the depth buffer to read-only mode (at this time, it is not necessary to turn off depth detection, because whether the boot does not enable depth detection for transparent objects are to be drawn in the order of the first far back), At this point the value of the depth buffer does not change with the depth value of the opaque object drawn later. Next, each transparent object is drawn in the order of the first and last close.

Reference 1:http://blog.csdn.net/shuaihj/article/details/7228882

Reference 2:http://blog.csdn.net/j123kaishichufa/article/details/6603888

Reference 3:http://blog.sina.com.cn/s/blog_6c8369530100m0x8.html

Glortho is the creation of an orthogonal parallel view body. It is generally used for objects that do not cause a change in size because of the distance from the screen. For example, drawings in commonly used projects. Requires a more accurate display. As a result of its confrontation, Glfrustum produces a perspective projection. This is a real-life simulation of how people view objects in the actual situation. For example: Observe two parallel trains, and after a long distance, these two rails will intersect in one place. Also, objects closer to the eye look larger, and distant objects look smaller.

The Glortho (left, right, bottom, top, near, far), which represents the coordinates to the right of the scene body, right represents the right coordinate, and the bottom represents the following, top represents the top. This function is simple to understand, that is, an object is placed there, how do you intercept him. Here, let's just throw away the Glviewport function without looking. First, understand the function of Glortho alone.  Suppose there is a sphere with a radius of 1, the center of the Circle in (0, 0, 0), then we set Glortho (-1.5, 1.5,-1.5, 1.5, 10, 10); it means that the sphere is loaded in a box with a wide height of 3. If set Glortho (0.0, 1.5,-1.5, 1.5,-10, 10); It means using a box with a width of 1.5 and a height of 3 to load the right side of the whole sphere; if you set Glortho (0.0, 1.5, 0.0, 1.5, 10, 10), it means using a wide The upper-right corner of the sphere is loaded into the box with a height of 1.5. The above three cases can be seen in the picture:

2.2 Orthogonal projection, observation box, world coordinates

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.