The current version of OpenGL is 3.3, which is based on the renderable pipeline to achieve model generation, rendering, image output and other work.
The Render Pipeline is a series of processing of three dimensional vertices into two dimensional discrete pixels. And the user can configure freely in specific shading phases (such as vertex shading and fragment shading phases, which is the biggest difference from fixed pipeline). The brief flow of the renderable pipeline is shown below.
Second, detailed process
The figure above is basically correct, but it’s not very intuitive. How does a three-dimensional vertex transform into a pixel?I’m going to break it down into two big steps, two dimensional vertices, two dimensional vertices discretization.
1. Transformation of three-dimensional coordinates into two-dimensional coordinates
(1) Model vertex construction
Model vertices are built relative to the model’s own coordinates, namely object coordinates. Only the shape of the model can be expressed, and its position and attitude cannot be obtained, so world coordinates must be introduced.
(2) Convert to world coordinates
The world coordinates represent a larger coordinate domain, and each vertex of the model can be represented by the world coordinates. From the object coordinates to the world coordinates, you have to multiply by a world matrix, and you get the model of the relative world coordinates.
(3) World coordinate transformation camera coordinates
The world coordinate transformation of camera coordinates, from object coordinates to world coordinates, is multiplied by an observation matrix, which gives the model relative to the camera coordinates.
(4) Camera coordinate transformation screen coordinate 1
Camera coordinates transform screen coordinates. Any three – dimensional mode is displayed in two – dimensional form (screen). So a three-dimensional model is usually converted to a two-dimensional model. The first step is to build the cone with the camera as the origin.
(5) Camera coordinate transformation screen coordinate 2
Next, the 3D coordinates of the model are transformed to 2D coordinates, which are multiplied by the perspective matrix. Finally, a 2D model is projected onto the near plane of the cone.
2, 2D vertex pixelation
The vertices obtained by perspective projection are linear and cannot be displayed on the screen. They need to be pixelated, as shown in the following figure: