opengl vertex coordinate transformation

After defining an object, first do the MVP matrix transformation, and pass the final calculated matrix resultMatrix to the vertex shader. The vertex shader multiplies the resultMatrix and the coordinates of the current vertex to obtain the gl_Position to be output by the vertex shader.

The gl_Position output by the vertex shader contains a w value, and OpenGL will do space clipping according to this w. x, y, and z all need to be between -w and w, and if it is greater or less than it will be clipped.

Then opengl will do perspective division, the so-called perspective division, that is, the three values ​​of x, y, z are divided by w, and then x, y, z are all in the range of [-1, 1], which is the normalization Normalized coordinates. Perspective division is the key to showing the 3D effect on the 2D screen.

 

Finally, the normalized coordinates are converted to screen coordinates, which requires viewport transformation.

GLES20.glViewport(0, 0, width, height); //Used to specify the position of the upper left corner of the screen and the length and width of the screen

GLES20.glDepthRangef(zNear, zFar);//The range of depth, this function can also not be set, because there is a default value between [0,1].

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325458987&siteId=291194637