OpenGL normalized device coordinates

Normalized Device Coordinates (NDC)

Before we start drawing graphics, we need to feed OpenGL some vertex data. OpenGL is a 3D graphics library, so in OpenGL all the coordinates we specify are 3D coordinates (x, y and z). OpenGL doesn't simply transform all 3D coordinates into 2D pixels on the screen; OpenGL only deals with 3D coordinates if they are in the range -1.0 to 1.0 on the 3 axes (x, y, and z). All coordinates within this range are called Normalized Device Coordinates, and coordinates within this range are finally displayed on the screen (coordinates outside this range will not be displayed).

Once your vertex coordinates have been processed in the vertex shader, they should be normalized device coordinates , which is a small space with x, y and z values ​​between -1.0 and 1.0. Any coordinates that fall outside the bounds will be discarded/clipped and not displayed on your screen. Below you can see the triangle we defined in normalized device coordinates (ignoring the z-axis):

Unlike the usual screen coordinates, the positive direction of the y-axis is upward, and the (0, 0) coordinate is the center of the image, not the upper left corner. Ultimately you want all (transformed) coordinates to be in this coordinate space, otherwise they won't be visible.

By using the data provided by the glViewport function, after the viewport transformation (Viewport Transform), the normalized device coordinates will be transformed into screen-space coordinates (Screen-space Coordinates). The resulting screen space coordinates are transformed into fragments and fed into the fragment shader.

Guess you like

Origin blog.csdn.net/u012861978/article/details/130983576