OpenGl basics 2. opengl

Source: Internet
Author: User

OpenGl basics 2. opengl

Basic graphic rendering process

1. create GLSurfaceView 2. initialize Renderer 3. onSurfaceCreated (), onSurfaceChanged (), onDrawFrame () Three Methods 4. coloring tool (vertex coloring tool, chip coloring tool) 5. vertex color texture 6. draw

Projection

OpenGL only provides two projection methods:

One is normal Projection, and the other is Orthographic Projection: There is no near-large effect of normal Projection, also known as parallel Projection. The projected visual object is a parallel pipe of a rectangle, that is, a cube ,. The biggest feature of normal projection is that the size of the projected object remains unchanged no matter how far the object is from the camera. This projection is usually used in the drawing of building blueprints and computer-aided design. These industries require that the size and angle of the projected objects remain unchanged, so that the proportion of the objects during construction or manufacturing is correct. In this mode, you do not need to set the camera location, direction, and viewpoint location, that is, you do not need the gluLookAt function. OpenGL has two normal projection functions. A function is void glOrtho (GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near, GLdouble far). It creates a parallel visual object. In fact, this function is used to create a normal projection matrix and multiply it by the current matrix. The near-crop plane is a rectangle, the three-dimensional coordinate of the point in the lower left corner of the rectangle is (left, bottom,-near), and the point in the upper right corner is (right, top,-near ); the far crop plane is also a rectangle. the coordinate of the point space in the lower left corner is (left, bottom,-far), and the point in the upper right corner is (right, top,-far ). All near and far values are both positive and negative. If there are no other transformations, the direction of the projection is parallel to the Z axis, and the viewpoint is oriented to the Z negative axis. This means that far and near are both negative values before the object's viewpoint, and far and near are both positive values after the object's viewpoint. Another function is void gluOrtho2D (GLdouble left, GLdouble right, GLdouble bottom, GLdouble top). It is a special normal projection function used to project two-dimensional images to two-dimensional screens. The default values of near and far are-1.0 and 1.0, respectively. The zcoordinates of all two-dimensional objects are 0.0. Therefore, the cropping area is a rectangle with the (left, bottom) and (right, top) points in the lower left corner. 2. Perspective Projection: Most 3D games use near-large, small-sized results. Perspective Projection conforms to people's psychological habits, that is, objects close to the viewpoint are large and objects far from the viewpoint are small, as far as the pole, it becomes a point of extinction. Its visual body is similar to an edges removed from the top and bottom, that is, a pyramid. This projection is usually used for animation, visual simulation, and many other aspects with authenticity reflection. There are also two OpenGL perspective projection functions, the glFrustum () function (). In this case, you need to use gluLookAt to set the camera position, camera direction (generally set to (0, 1, 0), and viewpoint position. This function is prototype: void glFrustum (GLdouble left, GLdouble Right, GLdouble bottom, GLdouble top, GLdouble near, GLdouble far); it creates a perspective visual body. The operation is to create a pivot projection matrix and multiply it by the current matrix. The parameters of this function only define the three-dimensional space coordinates of the lower-left and upper-right vertices of the near-cropping plane, namely (left, bottom,-near) and (right, top,-near ); the final far parameter is the Z negative value of the far-cropping plane. The coordinate between the point space in the lower-left corner and the upper-right corner is automatically generated by the function based on the perspective projection principle. Near and far indicate the distance from the viewpoint. They are always positive values. Another function is void gluPerspective (GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar). It also creates a symmetric perspective visual body, but its parameters are defined in the previous differences ,. The operation is to create a symmetric Perspective Projection Matrix and multiply it by the current matrix. The fovy parameter defines the angle of the field of view on the X-Z plane in the range of [0.0, 180.0]; The aspect parameter is the ratio of the projection plane width to height; the zNear and Far parameters are the distance from the cropping surface to the eyes. They are always positive values.

The normal projection is as follows:

Differences between Coordinate Transformation and plotting functions GLSL language triangles

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.